How do I make fun of an object using a constructor using Rhino Mocks?
For example, how will this object be mocked ...
public class Foo : IFoo { private IBar bar; public Foo (IBar bar) { this.bar = bar } public DoSomeThingAwesome() { //awesomeness happens here } }
You are not mocking Foo - you are mocking IFoo . To test Foo , you mock IBar and pass the layout to the constructor.
Foo
IFoo
IBar
You should try to avoid relying on IFoo by explicitly creating Foo instances: they need to either be given a factory if IFoo somehow, or explicitly pass the IFoo tag.
var myIFoo = MockRepository.GenerateStub<IFoo>();
you can check the awesomeness that happened through
myIFoo.AssertWasCalled(f => f.DoSomethingAwesome());
It has been a while since I used Rhino, but I believe that you can do:
mockRespository.StrictMock<Foo>( ibarVariable )
However, this will not work if all Foo members are not virtual.