2

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();
4

1 回答 1

0

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.

于 2009-02-25T11:47:54.777 回答