我正在尝试使用 Rhinomocks 3.5 和新的 lambda 表示法来模拟一些测试。我读过 这个,但还有很多问题。有没有完整的例子,特别是对于 MVC 类型的架构?
例如,模拟这个的最佳方法是什么。
public void OnAuthenticateUnitAccount()
{
if(AuthenticateUnitAccount != null)
{
int accountID = int.Parse(_view.GetAccountID());
int securityCode = int.Parse(_view.GetSecurityCode());
AuthenticateUnitAccount(accountID, securityCode);
}
}
有一个视图界面和一个演示者界面。它在控制器上调用一个事件。
我想出的是这个。
[TestMethod()]
public void OnAuthenticateUnitAccountTest()
{
IAuthenticationView view = MockRepository.GenerateStub<IAuthenticationView>();
IAuthenticationPresenter target = MockRepository.GenerateMock<IAuthenticationPresenter>();
target.Raise(x => x.AuthenticateUnitAccount += null, view.GetPlayerID(), view.GetSecurityCode());
target.VerifyAllExpectations();
}
它通过了,但我不知道它是否正确。
是的,我们正在开发后进行测试……需要快速完成。