I'm playing around with Rhino Mocks and am trying to set some dummy results on my mocked objects so when they are called in my factory methods I don't have to worry about the data.
But I've hit a snag, the methods I want to have the dummy results for are causing exceptions because they aren't virtual.
I've got code like this:
using(mock.Record()){
SetupResult.For(service.SomeMethod()).Return("hello world");
}
Does the SomeMethod
method have to be a virtual to be have a mocked result?
Also, what's the difference between SetupResult.For
and Expect.Call
?
Rhino Mocks uses DynamicProxy2 to do it's magic, so you will not be able to set up expectations/results on non-virtual methods.
As for the difference between
SetupResult.For
, andExpect.Call
if you want your test to fail validation if a method is not called, useExpect.Call
. If you just want to provide a result from your mock object, and you don't want to fail verification if it is not called, useSetupResult.For
So the following will fail:
And this test will not:
Does that make sense?