What on earth are you talking about?!?! Upon what are you calling register if it's not an IoC container? And why would you EVER want to instantiate a repository within a view?
On Feb 12, 3:04 pm, Stan B <[email protected]> wrote: > I guess this is the only way around it... The code came from > SharePoint guidance library. There are no IoC container there, the > repostitories are instantiated in the prsenters, although they > probably should have been in the views.. > > On Feb 12, 9:14 am, Patrick Steele <[email protected]> wrote: > > > > > I would change the implementation so that the Presenter gets an > > IProfileRepository in the constructor. During unit testing, just feed > > it your mock. In production, use an IoC container to inject it. > > > --- > > Patrick Steelehttp://weblogs.asp.net/psteele > > > On Fri, Feb 12, 2010 at 8:55 AM, Stan B <[email protected]> wrote: > > > 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 > > > athttp://groups.google.com/group/rhinomocks?hl=en.-Hide quoted text - > > > - Show quoted text - -- 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.
