我想断言一个方法只被调用一次。我使用RhinoMocks 3.5。
@H_502_8@这里是我认为会工作:
[Test] public void just_once() { var key = "id_of_something"; var source = MockRepository.GenerateStub<ISomeDataSource>(); source.Expect(x => x.GetSomethingThatTakesALotOfResources(key)) .Return(new Something()) .Repeat.Once(); var client = new Client(soure); // the first call I expect the client to use the source client.GetMeMyThing(key); // the second call the result should be cached // and source is not used client.GetMeMyThing(key); }
如果第二次调用GetMeMyThing()调用source.GetSomethingThatTakesALotOfResources(),我想这个测试失败。