Multiple calls to a Rhino mocked method return different results

后端 未结 2 563
说谎
说谎 2021-02-18 15:40

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.

2条回答
  •  抹茶落季
    2021-02-18 16:10

    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.

提交回复
热议问题