views:

29

answers:

1

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

+1  A: 

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?

Patrick Steele
.Name isn't called many times, but when it'll be called is a subject to change. It can be called before all .LoadConfigs or before each .LoadConfig.. But the fact, that firstly all LoadConfigs should be run, and only then all .Backups won't change, so I want to test that.And thanks for the link, it's not solving the problem, but at least I will put all .Backups and all .LoadConfigs in another unordered block :)
Shaddix
Okay, if you don't care about calls to the Name property, try using .Stub instead of .Expect. Then your code above should work (without the need to nest).
Patrick Steele