tdd - Asserting that a method is called exactly one time -
i want assert method called 1 time. i'm using rhinomocks 3.5.
here's thought work:
[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); // first call expect client use source client.getmemything(key); // second call result should cached // , source not used client.getmemything(key); }
i want test fail if second invocation of getmemything()
calls source.getsomethingthattakesalotofresources()
.
here's how i'd verify method called once.
[test] public void just_once() { // arrange var = mockrepository.generatemock<isomedatasource>(); a.expect(x => x.getsomethingthattakesalotofresources()).return(new something()).repeat.once(); a.stub(x => x.getsomethingthattakesalotofresources()).throw(new invalidoperationexception("gotcha")); // act // first invocation should call getsomethingthattakesalotofresources a.getmemything(); // second invocation should return cached result a.getmemything(); // assert a.verifyallexpectations(); }
Comments
Post a Comment