On Fri, Feb 12, 2010 at 7:52 AM, Stan B <[email protected]> wrote:
> Here is the problem in a nutshell, only two lines of code:
>
> IProfileRepository mock = mocks.StrictMock<IProfileRepository>();
>
> Activator.CreateInstance(mock.GetType()); // this fails with "No
> parameterless constructor defined for this
> object"
>
>
> Why doesn't mock have default constructor?
Because you're not supposed to "create" direct instances of mocks.
Rhino Mocks creates the mock object for you and handles all of
internal plumbing to keep track of expectations and stubbing.
Your first line of code (IProfileRepository mock =
mocks.StrictMock<IProfileRepository>()) tells Rhino Mocks to generate
(dynamically) an object that implements the IProfileRepository
interface. So what you're given back ("mock") is an object that was
dynamically created from Rhino Mocks, but it implements your interface
and can therefore be used in place of your real ProfileRepository.
What are you trying to accomplish with the Activator.CreateInstance?
---
Patrick Steele
http://weblogs.asp.net/psteele
--
You received this message because you are subscribed to the Google Groups
"Rhino.Mocks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rhinomocks?hl=en.