Can I test method call order with AAA syntax in Rhino-Mocks 3.6?

后端 未结 5 1545
南笙
南笙 2020-12-19 01:19

Is it possible to test for the following example if the Method1 called 1st, then Method2 called after and then Method3 by using the AAA syntax, in Rhino-mocks 3.6 ?

5条回答
  •  感动是毒
    2020-12-19 01:40

    The mocks.Ordered() syntax specified by @craastad is the right way to do it, but I couldn't get it to work in RhinoMocks 3.5 - instead I had to tweak it to work without the instance of MockRepository that @craastad's solution used to call Ordered() on:

    var fooMock = MockRepository.GenerateMock();
    using (fooMock.GetMockRepository().Ordered())
    {
        fooMock.Expect(x => x.Method1());
        fooMock.Expect(x => x.Method2());
    }
    
    var bar = new Bar(fooMock);
    bar.DoWork();
    
    fooMock.VerifyAllExpectations();
    

    If you do it this way, it also appears to be unnecessary to call fooMock.Replay() either.

提交回复
热议问题