mercredi 1 avril 2015

Mocking session state with Rhino mocks

i am trying to perform a test operation on complex methods which handles some complex objects. In that it uses SessionManager class which is a customer class with properties and handles the Session Context stuff.


I have the below code where i am trying to mock the sessionstate and override the value returned for PromotionDTO property returned from SessionManager class.



SessionManager sessionStub = MockRepository.GenerateStub<SessionManager>( MockObjectFactory.GetMockHttpSessionState());


var dto = new PromotionParamsDTO(store.DefaultAdCode, membershiptypefromResult.membershipType.Id, offerCodes, true);


sessionStub.Stub(x => x.PromotionDTO).Return(dto);


I am facing the below error at the last line where i am trying to stub the value


Invalid call, the last call has been used or no call has been made (make sure that you are calling a virtual (C#) / Overridable (VB) met



at Rhino.Mocks.LastCall.GetOptions[T]()
at Rhino.Mocks.RhinoMocksExtensions.Expect[T,R](T mock, Function`2 action)
at Rhino.Mocks.RhinoMocksExtensions.Stub[T,R](T mock, Function`2 action)
at Bluefield.Test.MembershipPromo.MembershipInfoServicesTest.CheckAndRunPromoForMembershipTypeTest()


I am using MockObjectFactory implementation from here http://ift.tt/1Gfym7z


Kindly help me here, thanks.


Aucun commentaire:

Enregistrer un commentaire