tags:

views:

375

answers:

1

When I use Repeat.Any() it doesn't show any error though I don't call GetMood() Method ,but if i don't use n doesn't call GetMood then it shows Excpetion of type ExpectationViolationException.Can somebody tell me what is the use of repeat.any().

MockRepository mocks = new MockRepository();

IAnimal animal = mocks.DynamicMock<IAnimal>();

using (mocks.Record())  
{                 
    //Expect.Call(animal.GetMood()).Return("punit");   
    Expect.Call(animal.GetMood()).Return("Punit").Repeat.Any();
}

//animal.GetMood();

mocks.ReplayAll();   
mocks.VerifyAll();
A: 

Repeat.Any specifies that GetMood() can be called 0 or more times and that it should return "Punit" if it is called.

The line

Expect.Call(animal.GetMood()).Return("punit");

implies that GetMood must be called exactly once. This is the same as Repat.Once.

You may also use AtLeastOnce, Times, Twice, and Never.

Jakob Christensen
thnx for reply actually if u see my questions which states that if i use repeat.any and odn't call the method it deosn't show any expectation,but if i don't use repeat.any it throws exception.is repeat.any autmatically calls the method.
Repeat.Any means that you don't care how many times your method is being called so it will not throw an exception even if your method is not called at all.
Jakob Christensen