mardi 7 juillet 2015

Rhino Mock Expect.Call() actually calls the method not only create an expectation

I want to test if a method has been called in the test.

My problem is that when I want to create the expectations it is not working as I thought. The next line actually runs the method, not only create an expectation:

Expect.Call(() => mockedService.MethodThatIExpectToRun(params));

There is another way:

mockedService.Expect((s=> s.MethodThatIExpectToRun(params)));

But this also actually runs the method, not only creates an expectation to be fulfilled by the test.

And this line that asserts if the method was not called also actually calls the method, not only checks whether it was called.

mockedService.AssertWasCalled(s=> s.MethodThatIExpectToRun((params)));

additional info: MethodThatIExpectToRun returns void

For prgmtc's comment:

IService mockedService = MockRepository.GeneratePartialMock<Service>(mockedRepository_1, ..., mockedRepository_n);

Aucun commentaire:

Enregistrer un commentaire