0
我有一个方法CreateAccount(...),我想单元测试。基本上它创建一个帐户实体并将其保存到数据库,然后返回新创建的帐户。我在嘲笑仓库并期待Insert(...)调用。但是Insert方法需要一个Account对象。正确单元测试服务/库交互
此测试通过,但它似乎不正确,因为CreateAccount创建一个帐户,并且我为Mock'ed期望的呼叫(两个单独的帐户实例)创建一个帐户。测试这种方法的正确方法是什么?或者是我使用这种方法创建帐户不正确?
[Fact]
public void can_create_account()
{
const string email = "[email protected]";
const string password = "password";
var accounts = MockRepository.GenerateMock<IAccountRepository>();
accounts.Expect(x => x.Insert(new Account()));
var service = new AccountService(accounts);
var account = service.CreateAccount(email, password, string.Empty, string.Empty, string.Empty);
accounts.VerifyAllExpectations();
Assert.Equal(account.EmailAddress, email);
}
这里是的createAccount方法:
public Account CreateAccount(string email, string password, string firstname, string lastname, string phone)
{
var account = new Account
{
EmailAddress = email,
Password = password,
FirstName = firstname,
LastName = lastname,
Phone = phone
};
accounts.Insert(account);
return account;
}
对不起,我应该发布我正在测试的实际方法,杜。我更新了OP。 – mxmissile 2009-07-03 17:30:02