Rhino Mocks: Expect a method call after property set

40 views Asked by At

I have a class to test that associates with an interface:

interface IMyFactory
{
    int MyProperty {get; set;}
    int Create(int x);
}

class ClassToTest
{
    public IMyFactory Factory {get; set;}

    public int Calculate(int x, int y)
    {
        this.MyFactory.MyProperty = x;
        this.MyFactory.Calculate(y);
    }
}

I know how to verify that method ClassToTest.Calculate(x, y) will set MyProperty to x.
I also know how to verify that IFactory.Calculateis called with value y.

But how do I assert that calculate is called after MyProperty has been set?

I tried this:

MockRepository mockRepository = new MockRepository();
IMyFactory mockedFactory = mockRepository.StrictMock<IMyFactory>();

int x = 4;
int y = 5;
MyClass testObject = new ClassToTest
{
    Factory = mockedFactory,
};

using (mockRepository.Record())
{
     // expect that Factory.MyProperty is set once to a value of x:
     mockedFactory.Expect( (x) => x.MyProperty)
                  .SetPropertyWithArgument(x)
                  .Repeat.Once();

     // expect that Factory.Calculate is called once with a value of y
     mockedFactory.Expect( (x) => x.Calculate(Arg<int>.Is.Equal(y))
                  .Repeat.Once();
}
using (mockRepository.Playback())
{
    testObject.Calculate(x, y);
}

But how do I verify that MyProperty is set to x before Calculate(y) is called?

0

There are 0 answers