I am new to mocking. I need to mock method (it doesn't have return value). I cannot find any examples of how to mock a method. I need to mock ITempDa.Import
method.
var stub = MockRepository.GenerateStub<ITempDA>();
stub.Stub(x => x.Import(param1)). ???
public void MockedImport() {
// some processing here
}
ITempDa.Import
should be mocked and instead some internal method "MockedImport
" should be called.
As @JamesLucas said you don't need to use
Return()
method(you should use this method only when your method is notvoid
).In this case you should use the
Do()
method:or if
MockedImport
ths same arguments asImport
:You should use
WhenCalled
method when the method under test called your fake and you want to intercept the execution(execute something + change return value/change arguments/do additional steps and etc...). Another reason to useDo
instead ofWhenCalled
is, your code become more readable.Usually I do not recommend to use
IgnoreArguments
method. The reason is quite simple, you test the method behaviour. When something violate the method behaviour then the test should fail.IgnoreArguments
easily hide things. However, if the calling parameters aren't important do: