Rhino mock calling the function that is mocked
Trying to mock a function with RhinoMock.
var repository = new Rhino.Mocks.MockRepository();
var classMock = repository.DynamicMock<Customer>();
Expect.Call(classMock.getCustomerAge("john")).Return(12);
The problem is that in the Expect.Call line it actually calls the function that it's supposed to mock. Am I doing something wrong? Isn't the purpose of mocking that you don't have to run the actual function?
public class AgeProvider
{
private static Service _Service;
private static string _User;
public AgeProvider()
{
}
public AgeProvider(ISession session, string authenticatedUser)
{
_Service = new Service(session);
_user = authenticatedUser;
}
public int getCustomerAge(string userToSearch)
{
var user = _Service.FindUser(_user, userToSearch);
return user.age;
}
}
Simplified the clas开发者_运维百科s, where the function is that I'm trying to mock.
is the method virtual? I think you also need to use a partial mock if you are mocking a class rather than an interface.
It's probably because you're using the older record/replay semantics. Instead, use the new AAA (Arrange/Act/Assert) style:
classMock.Stub(r => r.getCustomerAge("john")).Return(12);
精彩评论