Here goes an example of what I have:
public class ClassToBeTestedTest
{
private Mock<IAService> aService;
private Mock<IAnotherService> anotherService;
private ClassToBeTested testedClass;
[SetUp]
public void setup()
{
aService = new Mock<IAService>();
anotherService = new Mock<IAnotherService>();
testedClass = new ClassToBeTested(aService.Object, anotherService.Object);
}
[Test]
public void ShouldCallAServiceMethodBeforeAnotherService()
{
testedClass.Run();
aService.Verify(x=>x.AMethod(), Times.Once());
anotherService.Verify(x=>x.AnotherMethod(), Times.Once());
}
}
In this sample I just check if they were called, no mather the sequence…
Im considering to setup a callback in those methods that add some kind of sequence control in the test class…
edit: I’m using the moq lib: http://code.google.com/p/moq/
Rhino Mocks supports orders in the mocking, see http://www.ayende.com/Wiki/Rhino+Mocks+Ordered+and+Unordered.ashx
Or Moq Sequences perhaps, http://dpwhelan.com/blog/software-development/moq-sequences/
See here for a similar question on this, How to test method call order with Moq