Using RhinoMocks, how do you mock or stub a concrete class without an empty constructor?

Posted by Mark Rogers on Stack Overflow See other posts from Stack Overflow or by Mark Rogers
Published on 2009-08-17T23:50:34Z Indexed on 2010/06/10 23:02 UTC
Read the original article Hit count: 283

Filed under:
|
|
|

Mocking a concrete class with Rhino Mocks seems to work pretty easy when you have an empty constructor on a class:

public class MyClass{
     public MyClass() {}
}

But if I add a constructor that takes parameters and remove the one that doesn't take parameters:

public class MyClass{
     public MyClass(MyOtherClass instance) {}
}

I tend to get an exception:

System.MissingMethodException : Can't find a constructor with matching arguments

I've tried putting in nulls in my call to Mock or Stub, but it doesn't work.

Can I create mocks or stubs of concrete classes with Rhino Mocks, or must I always supply (implicitly or explicitly) a parameter-less constructor?

© Stack Overflow or respective owner

Related posts about c#

Related posts about TDD