我正在使用 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/