Reputation: 53323
How can I enforce a stub object in RhinoMocks to return void for a void method on it?
Take this example:
public interface ICar
{
string Model {get;set;}
void Horn();
}
ICar stubCar= MockRepository.GenerateStub<ICar>();
stubCar.Expect(c=>c.Horn()).Return( //now what so that
// it returns nothing as the meth. returns void ?
Upvotes: 6
Views: 5499
Reputation: 57907
The Return()
method is invalid for a void method call. Rather you want something like this:
ICar stubCar= MockRepository.GenerateStrictMock<ICar>();
stubCar.Expect(c=>c.Horn());
stubCar.DoSomethingThatIsSupposedToCallHorn();
stubCar.VerifyAllExpectations();
which will tell you whether or not Horn()
was called.
That's how you test that void methods are called when unit testing. You do the following:
Expect()
)Upvotes: 6
Reputation: 1503924
The method can't return a value - it's a void method. The CLR won't let it try to return a value. You don't need to test for this.
You only need the Expect
call.
Upvotes: 9