c# - RhinoMocks mock method without return -


i new mocking. need mock method (it doesn't have return value). cannot find examples of how mock method. need mock itempda.import method.

 var stub = mockrepository.generatestub<itempda>();  stub.stub(x => x.import(param1)). ???    public void mockedimport() {     // processing here  } 

itempda.import should mocked , instead internal method "mockedimport" should called.

as @jameslucas said don't need use return() method(you should use method when method not void).

in case should use do() method:

var stub = mockrepository.generatestub<itempda>(); stub.stub(x => x.import(arg<object>.is.anything))                 .do(new action<object>(o => mockedimport())); 

or if mockedimport ths same arguments import:

stub.stub(x => x.import(arg<object>.is.anything))                 .do(new action<object>(mockedimport); 

you should use whencalled method when method under test called fake , want intercept execution(execute + change return value/change arguments/do additional steps , etc...). reason use do instead of whencalled is, code become more readable.

usually not recommend use ignorearguments method. reason quite simple, test method behaviour. when violate method behaviour test should fail. ignorearguments hide things. however, if calling parameters aren't important do:

stub.stub(x => x.import(null))                 .ignorearguments()                 .do(new action<object>(o => mockedimport())); 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -