2014-12-03 202 views
-1

我有一個單元測試,它登錄到數據庫並檢查用戶名和密碼,但我需要現在使用mock重新創建這些測試。C#模擬測試

我一直在網上尋找,但找不到像我想實現的任何東西。以下是原始測試

[TestMethod()] 
public void LoginTest() 
{ 
    this.errorText = string.Empty; 
    this.user = MasterDataManager.GetInstance().Login("JohnSmith", "123", out errorText); 
    Assert.AreEqual(string.Empty, errorText); 
} 

從我在網上找到,它通過但我真的不知道爲什麼,說實話,我已經寫了測試。我在這裏用犀牛嘲笑,但我願意接受任何幫助或解決方案,讓我跟你去

[TestMethod()] 
public void LoginTestMock() 
{ 
    var repo = MockRepository.GenerateMock<IAbstractConnector>(); 
    repo.Login("JohnSmith", "123", out errorText); 
    repo.VerifyAllExpectations(); 
} 
+0

您認爲「VerifyAllExpectations」會檢查什麼?你認爲在這種情況下「通過單元測試」實際上意味着什麼? – 2014-12-03 15:13:24

+0

你想測試什麼? – thumbmunkeys 2014-12-03 15:13:31

+0

我想模擬一個測試,返回一個空字符串 – 2014-12-03 15:15:12

回答