c# - WPF Prism 中的单元测试确认

标签 c# wpf unit-testing prism confirmation

我正在使用 Prism 的确认类来要求用户进行确认。当我进行单元测试时,确认的返回值始终为 false。也许我可以公开 InteractionRequest 的 setter 。我的代码现在看起来像这样,我的单元测试应该验证是否调用了 this.copyService.Execute。

public InteractionRequest<Confirmation> CopyProjectConfirmationRequest { get; private set; }

    bool confirmationResult = false;
    DialogConfirmation dialogConfirmation = new DialogConfirmation
                                              {
                                                Title = "Copy and Convert Project",
                                                Content = string.Format("This Project was created with Version {0} to be used with currentVersion({1}) it must be converted should it copyed and converted Project", projectVersion, toolVersion),
                                                ConfirmButtonText = "Copy & Convert",
                                                DeclineButtonText = "Cancel"
                                              };

    this.CopyProjectConfirmationRequest .Raise(dialogConfirmation, cb => { confirmationResult = cb.Confirmed; });

    if (confirmationResult)
    {
      this.copyService.Execute(this.Model);
    }

最佳答案

解决方案非常简单。只需将其添加到单元测试中

  sut.CopyProjectConfirmationRequest.Raised += (s, e) =>
  {
    Confirmation context = e.Context as Confirmation;
    context.Confirmed = true;
    e.Callback();
  };

关于c# - WPF Prism 中的单元测试确认,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22689473/

相关文章:

c# - 如何将自定义消息退出对话框添加到 Wix 安装程序

c# - C# 应用程序的首选菜单

unit-testing - 为内存中的 UnboundID LDAP 服务器创建自定义架构/添加到现有架构

unit-testing - 阻止 BizTalk 项目调用完全重建?

asp.net-mvc - 对 POST 的 MVC 路由进行单元测试

c# - 面板双缓冲

c# - Moq中的设置方法,调用不明确

wpf - 好莱坞原理+DI+WPF+Unity怎么做

c# - 通用 View 模型编辑支持

.net - 媒体元素不显示