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# - 抛出 NullReferenceException 但对象通过了 null 检查,这怎么可能?

c# - 从文本文件中提取数组

wpf - WPF 的平滑视频过渡

c# - 如何更改 WPF TextBlock 中的 TextDecoration 颜色?

visual-studio - Visual Studio 测试工具与第三方工具的比较

angular - Karma 使用内置管道的自定义管道测试 Angular X (5) 组件

c# - 有没有办法方便地将字典转换为字符串?

c# - 在文件系统级别同步写入文件

c# - WPF 窗口边框与功能区控件表现得很奇怪

c# - 如何测试 RoutedUICommand?