Oh, I see, thank you.  I need Activator.Create instance in order to
swap real repository (class that talks to SharePoint) to the mock
during unit testing. I am testing presenter class that doesn't see the
difference because it is  where Activator.CreateInstance for the given
interface is called and real or mock type is being instantiated.

I can accomplish this by creating manual (static) class mock but don't
want to go to this route..



On Feb 12, 8:21 am, Patrick Steele <[email protected]> wrote:
> 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 Steelehttp://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.

Reply via email to