Shaddix
Shaddix

Reputation: 6109

Rhino Mocks and ordered test with unordered calls

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

Upvotes: 3

Views: 741

Answers (1)

PatrickSteele
PatrickSteele

Reputation: 14697

According to this old CodeProject article, you can "nest" your Order() and Unordered() calls. Maybe that will get you what you're looking for.

Is the "Name" property called so many times that you don't want to set it up as part of your ordered test?

Upvotes: 1

Related Questions