Difference in techniques for setting a stubbed method's return value with Rhino Mocks
        Posted  
        
            by CRice
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by CRice
        
        
        
        Published on 2010-05-26T09:00:33Z
        Indexed on 
            2010/05/26
            23:21 UTC
        
        
        Read the original article
        Hit count: 317
        
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.
© Stack Overflow or respective owner