Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple calls to a Rhino mocked method return different results

Tags:

rhino-mocks

If I want to mock a class that returns a string that is used to determine whether while loop should continue (imagine read while string != null), how can I set the expectation. I have tried the following:

    provider.Reader.Expect(r => r.ReadLine()).Return("1,10,20");
    provider.Reader.Expect(r => r.ReadLine()).Return(null);

but when it is called twice in the same method, it returns the first string on both occasions, whereas I want it to return the second value (null) if called a second time.

like image 757
Colin Desmond Avatar asked Sep 23 '09 19:09

Colin Desmond


1 Answers

I think you can just stick the repeat on the end of the syntax you're currently using.

provider.Reader.Expect(r => r.ReadLine()).Return("1,10,20").Repeat.Once();
provider.Reader.Expect(r => r.ReadLine()).Return(null).Repeat.Once();

or

 provider.Reader.Expect(r => r.ReadLine()).Return("1,10,20").Repeat.Once();
    provider.Reader.Expect(r => r.ReadLine()).Return(null);

if you have any calls beyond 2nd call that you want to use second expectation.

like image 155
Binz Avatar answered Nov 26 '22 14:11

Binz