Prism.DialogService的单元测试

问题描述 投票:-1回答:1

我使用带有Nert.Core 3.xxx的Prism.Wpf,我希望tp使用XUnit作为测试框架。有什么想法如何测试对话框?在我的应用程序中,我使用以下代码片段。

public DelegateCommand CustomerSelectionCommand =>_customerSelectionCommand ?? (_customerSelectionCommand =新的DelegateCommand(async()=>{var parameters = new DialogParameters{{“ Title”,“ Kunden Auswahldialog”}};UnsubscribeEvents();var dialogService = _container.Resolve();

           dialogService.ShowDialog("CustomerSelectionDialog", parameters, CloseCustomerSelectionCallback);
       }));

谢谢彼得

wpf prism
1个回答
0
投票

var dialogService = _container.Resolve()

这很糟糕。因此,假设您在构造函数中设置了_dialogService,然后在测试中注入了Mock<IDialogService>或手动编码的变体(如果您愿意),并在视图模型对象下调用了CustomerSelectionCommand,测试。然后,检查模拟程序是否预期的ShowDialog调用已到达。

或者,设置您的模型以调用传递的回调并在命令后仅检查视图模型的状态。

无论如何,您要做的[[not想要做的就是根据问题标题”编写针对DialogService的测试,完全是因为您不需要这样做。这不是您的代码,并且库为其类提供了自己的单元测试集。

© www.soinside.com 2019 - 2024. All rights reserved.