简体   繁体   中英

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://codeverge.com/asp.net.free-for-all/mocking-httpcontext-object/36423

Kindly help me here, thanks.

没关系,我已将我想存根的属性更改为可覆盖,并直接设置值来解决此问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM