我有一個設置屬性犀牛製品斷言的屬性設置調用了正確的對象類型
public void SetNetworkCredential(string userName, string password, string domain)
{
_reportExecutionService.Credentials = new NetworkCredential(userName, password, domain);
}
我如何驗證證書被稱爲具有有效的NetworkCredential的方法?
我想這TestMethod的,但沒有成功,因爲的NetworkCredential對象是不同的引用
[TestMethod]
public void TestTest()
{
const string userName = "userName";
const string password = "password";
const string domain = "domain";
var mock = MockRepository.GenerateMock<IReportExecutionService>();
var rptService= new ReportService(mock);
rptService.SetNetworkCredential(userName, password, domain);
mock.AssertWasCalled(x => x.Credentials = new System.Net.NetworkCredential(userName, password, domain));
}
有沒有辦法來驗證的setter被稱爲與類型的NetworkCredential的對象,並用正確的參數?
優秀的答案,所以這個代碼實際工作它測試,如果制定者與給定值稱爲: mock.AssertWasCalled(X => x.PropertyName = VALUE_WE_ARE_CHECKING); – Roboblob 2010-02-18 09:06:50