Rhinomocks DynamicMock question

Posted by epitka on Stack Overflow See other posts from Stack Overflow or by epitka
Published on 2010-06-18T13:06:38Z Indexed on 2010/06/18 13:53 UTC
Read the original article Hit count: 283

Filed under:

My dynamic mock behaves as Parial mock, meaning it executes the actual code when called. Here are the ways I tried it

var mockProposal = _mockRepository.DynamicMock<BidProposal>();
  SetupResult.For(mockProposal.CreateMarketingPlan(null, null, null)).IgnoreArguments().Repeat.Once().Return(
                copyPlan);

            //Expect.Call(mockProposal.CreateMarketingPlan(null, null, null)).IgnoreArguments().Repeat.Once().Return(
            //   copyPlan);

           // mockProposal.Expect(x => x.CreateMarketingPlan(null, null, null)).IgnoreArguments().Return(copyPlan).Repeat.Once();

Instead of just returning what I expect it runs the code in the method CreateMarketingPlan

Here is the error:

System.NullReferenceException: Object reference not set to an instance of an object.

at Policy.Entities.MarketingPlan.SetMarketingPlanName(MarketingPlanDescription description) in MarketingPlan.cs: line 76
at Policy.Entities.MarketingPlan.set_MarketingPlanDescription(MarketingPlanDescription value) in MarketingPlan.cs: line 91
at Policy.Entities.MarketingPlan.Create(PPOBenefits ppoBenefits, MarketingPlanDescription marketingPlanDescription, MarketingPlanType marketingPlanType) in MarketingPlan.cs: line 23
at Policy.Entities.BidProposal.CreateMarketingPlan(PPOBenefits ppoBenefits, MarketingPlanDescription marketingPlanDescription, MarketingPlanType marketingPlanType) in BidProposal.cs: line 449
at Tests.Policy.Services.MarketingPlanCopyServiceTests.can_copy_MarketingPlan_with_all_options() in MarketingPlanCopyServiceTests.cs: line 32 

Update: I figured out what it was. Method was not "virtual" so it could not be mocked because non-virtual methods cannot be proxied.

© Stack Overflow or respective owner

Related posts about rhino-mocks