tags:

views:

59

answers:

0
var dependency1 = MockRepository.GenerateMock<IDependency1>();
var dependency2 = MockRepository.GenerateMock<IDependency2>();
var dependency3 = MockRepository.GenerateMock<IDependency3>();

using(dependency2.GetMockRepository().Ordered())
{
    using (dependency1.GetMockRepository().Ordered())
    {
        using (dependency3.GetMockRepository().Ordered())
        {
            dependency1.Expect(d => d.Foo()).Repeat.Once();
            dependency1.Expect(d => d.Bar()).Repeat.Once();

            //loop1
            dependency2.Expect(d => d.Foo()).Repeat.Once();
            dependency2.Expect(d => d.Bar()).Repeat.Once();

            //loop2
            dependency2.Expect(d => d.Foo()).Repeat.Once();
            dependency2.Expect(d => d.Bar()).Repeat.Once();

            dependency3.Expect(d => d.Foo()).Repeat.Once();
        }
    }
}


var algorithm = new MyAlgorithm(dependency1, dependency2, dependency3);
algorithm.Execute();

dependency1.VerifyAllExpectations();
dependency2.VerifyAllExpectations();
dependency3.VerifyAllExpectations();

I have the above code, and my algorithm contains a loop on dependencies, the loop might go on many times (I can get the actual loop count), but how should I write expectation. I cant keep writing expectations multiple times, nor can I say Repeat.Times(count) as ordering is important in my algorithm.