Hello all,
(C#, Rhino Mocks, MbUnit).
I have a class called AccountManager that has a RegisterUser() method. This method returns void but does throw an exception for any errors. AccountManager calls into an IDataRepository calling its AddUser() method to do a database insert.
I'm mocking the IDataRepository using a Rhino Mock and throwing and exception for a given set of arguments simulating the exception being raised in the repository.
[Test]
public void RegisterKnownUser()
{
MockRepository mocks = new MockRepository();
IDataRepository dataRepository = mocks.StrictMock<IDataRepository>();
using (mocks.Record())
{
Expect.Call(() => dataRepository.AddUser("abc", "abc", "[email protected]", "a", "bc")).Throw(
new InvalidOperationException());
}
using (mocks.Playback())
{
AccountManager manager = new AccountManager(dataRepository);
Assert.Throws(typeof (InvalidOperationException), () => manager.RegisterUser("abc", "abc", "[email protected]", "a", "bc"));
}
}
This test works fine.
My question is what to do about the situation where the args supplied to RegisterUser are correct and valid. The real IDataRepository would not return anything nor would it thrown any exceptions. So in short AccountManager's state would not have changed. Does this mean I don't need to test AccountManager.RegisterUser when it would result in nothing I can observe directly in the class and method under test. Testing against state in the mock smells a bit to me. I think as long as I test IDataRepository.AddUser seperately then I shouldn't need to test AccountManager.RegisterUser for inputs that would result in nothing observable in the class.
Thanks in advance.