Sure. var context = MockRepository.GenerateStub<ICommunicationContext>(); var principal = MockRepository.GenerateStub<IPrincipal>(); var identity = MockRepository.GenerateStub<IIdentity>();
identity.Stub(i => i.Name).Return(testUserName); principal.Stub(p => p.Identity).Return(identity); context.Stub(c => c.User).Return(principal); --- Patrick Steele http://weblogs.asp.net/psteele On Wed, Mar 9, 2011 at 11:08 PM, Rob <[email protected]> wrote: > I am working with OpenRasta and testing authentication. > > // Need to use this style of setting up mock it seems. Stubs dont work > without setter. > var mocks = new MockRepository(); > var mockContext = mocks.StrictMock<ICommunicationContext>(); > var mockPrincipal = mocks.StrictMock<IPrincipal>(); > var mockIdentity = mocks.StrictMock<IIdentity>(); > using (mocks.Record()) > { > Expect.Call(mockIdentity.Name).Return(testUserName).Repeat.Any(); > > Expect.Call(mockPrincipal.Identity).Return(mockIdentity).Repeat.Any(); > Expect.Call(mockContext.User).Return(mockPrincipal).Repeat.Any(); > } > > This is allowing me to return my testUserName from the Context > dependent injection. > > This I figured out with help of > http://stackoverflow.com/questions/162534/mock-iidentity-and-iprincipal/1093800#1093800 > > Is a more AAA form of doing this ? > > Is it possible to use a Stub not a mock - because I do not need to > verify the expectations at all. I did notice some comments about how > it was necessary to use Mocks not Stubs in Rhino mocks for get only > properties but was wanting to confirm this. > > > > -- > You received this message because you are subscribed to the Google Groups > "Rhino.Mocks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/rhinomocks?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Rhino.Mocks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rhinomocks?hl=en.
