Question

When I run the following test:

    [TestMethod]
    public void MyTest()
    {
        var wizardCatalog = MockRepository.GenerateStub<IWizardCatalog>();

        var firstQuestion = MockRepository.GenerateStub<IWizardQuestion>();
        wizardCatalog.Stub(i => i.GetFirstQuestion()).Return(firstQuestion);

        var choices = new List<IWizardChoice>();
        firstQuestion.Stub(i => i.Choices).Return(choices);
    }

I get this exception:

You are trying to set an expectation on a property that was defined to use PropertyBehavior. Instead of writing code such as this: mockObject.Stub(x => x.SomeProperty).Return(42); You can use the property directly to achieve the same result: mockObject.SomeProperty = 42;

Everything I read tells me that this stub operation is valid:

        var choices = new List<IWizardChoice>();
        firstQuestion.Stub(i => i.Choices).Return(choices);

What is going on?

Was it helpful?

Solution

PropertyBehaviour is on by default on stubs, but not on mocks. So you can either continue using a stub and change to the syntax suggested in the exception, or create a mock with GenerateMock<IWizardQuestion>() and use your existing .Stub(...).Return(...) syntax.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top