我正在使用Prism的Confirmation類來詢問用戶是否確認。當我單元測試確認的返回值總是錯誤的。也許我可以讓InteractionRequest的setter公開。我的代碼現在看起來像這樣,我的單元測試應該驗證this.copyService.Execute被調用。WPF Prism中的單元測試確認
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);
}
我已經這樣做了,因爲在我的測試中confirmationResult始終爲false,所以失敗。 – Kingpin
保存'CopyProjectConfirmationRequest'?即把它放在一個也可以嘲弄的不同類中? – Boklucius