2014-12-03 200 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

回答