Rhino Mocks and ordered test with unordered calls

Posted by Shaddix on Stack Overflow See other posts from Stack Overflow or by Shaddix
Published on 2010-04-25T06:12:32Z Indexed on 2010/04/25 6:13 UTC
Read the original article Hit count: 304

Filed under:
|

I'm using Rhino.Mocks for testing the system. I'm going to check the order of calling .LoadConfig and .Backup methods. I need .LoadConfig to be the first. Currently the code is like this:

var module1 = mocks.Stub<IBackupModule>();
var module2 = mocks.Stub<IBackupModule>();

module1.Expect(x => x.Name).Return("test");
module2.Expect(x => x.Name).Return("test2");

using (mocks.Ordered())
{
  module1.Expect(x => x.LoadConfig(null));
  module2.Expect(x => x.LoadConfig(null));

  module1.Expect(x => x.Backup());
  module2.Expect(x => x.Backup());
}
mocks.ReplayAll();

The problem is, that there's also a call to .Name property, and i'm not interesting when it'll be called: before .LoadConfig or after the .Backup - it just doesn't matter.

And when I run this I'm getting Exception: Unordered method call! The expected call is: 'Ordered: { IConfigLoader.LoadConfig(null); }' but was: 'IIdentification.get_Name();'

Is there a way to deal with this? Thanks

© Stack Overflow or respective owner

Related posts about rhino-mocks

Related posts about unit-testing