好日,Moq的驗證表達
我具有執行註冊表查找以確定在那裏的應用程序被安裝(在64位機器上)的類。
我試圖驗證,在這裏寫單元測試是我所:
[Test, Explicit]
public void Validate64Bit()
{
wsMock.Setup(x => x.IsInstalled).Returns(true);
wsMock.Setup(x => x.Path).Returns(@"C:\Program Files (x86)\DIRP\");
IWorkstationLocator workstationLocator = new WorkstationLocator();
string workstationInstallationPath = workstationLocator.Path;
Assert.That(workstationInstallationPath != string.Empty, "The install path should exist.");
wsMock.Verify(x => x.Path == workstationInstallationPath,
"64-bit Workstation Install Path should match: " + @"C:\Program Files (x86)\DIRP\");
}
但我發現了一個錯誤:
System.ArgumentException:表達式是不是方法調用: x => x.Path == .workstationInstallationPath
所以我的問題是:我想測試如果x.Path == wrokstationInstallationPath。
我該如何在.Verify()方法中執行此操作?
或者我最好使用斷言?
TIA,
COSON