Quiero afirmar que un método se llama exactamente una vez. Estoy usando RhinoMocks 3.5.Afirmando que un método se llama exactamente una vez
Aquí es lo que pensé que funcionaría:
[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);
}
Quiero que esta prueba falle si la segunda invocación de GetMeMyThing()
llamadas source.GetSomethingThatTakesALotOfResources()
.
+1 para usar 'using (mocks.Record()) {..} Aumenta mucho la legibilidad. –
-1 Esto no funciona. No lanzará una excepción si se llama a GetSomethingThatTakesALotOfResources más de una vez. – Ergwun
Estoy bastante seguro de que esto estaba funcionando en el momento en que escribí esto hace 2 años. Actualizaré la publicación para incluir la nueva forma de hacerlo. –