Difference in techniques for setting a stubbed method's return value with Rhino Mocks
- by CRice
What is the main difference between these following two ways to give a method some fake implementation?
I was using the second way fine in one test but in another test the behaviour can not be achieved unless I go with the first way.
These are set up via:
IMembershipService service = test.Stub<IMembershipService>();
so (the first),
using (test.Record()) //test is MockRepository instance
{
service.GetUser("dummyName");
LastCall.Return(new LoginUser());
}
vs (the second).
service.Stub(r => r.GetUser("dummyName")).Return(new LoginUser());
Edit
The problem is that the second technique returns null in the test, when I expect it to return a new LoginUser. The first technique behaves as expected by returning a new LoginUser. All other test code used in both cases is identical.