It is just on overload:
public void Register<T>(Type concreteType)
{
Register(typeof(T), concreteType);
}
This code ties an interface to a concreate type that implements this
interface and works fine for the regular classes. When concrete Rhino
mock is instantiated, it fails because mock does not have default
constructor...
On Feb 11, 3:46 pm, bill richards <[email protected]>
wrote:
> It looks to me like there is something missing here ...
>
> The implementation you have shown for Register is different to that
> which is being called in your test
>
> your implementation : Register(Type contractType, Type concreteType)
> being called in test : Register<T>(T type)
>
> so I'm not sure about this. Secondly, you are passing your interface
> in to Register as the concrete type, I think this is why you are
> getting the exception,
>
> IProfileRepository mockProfileRepository =
> mocks.StrictMock<IProfileRepository>();
>
> mockProfileRepository.GetType() will (I believe) return
> typeof(IProfileRepository)
>
> I've been wrong before ;o)
>
> On Feb 11, 8:34 pm, Stan B <[email protected]> wrote:
>
>
>
> > Why doesn't a mock or stub have default constructor?
>
> > I create a mock:
>
> > IProfileRepository mockProfileRepository =
> > mocks.StrictMock<IProfileRepository>();
>
> > and then swap in my service locator class:
>
> > serviceLocator.Register<IProfileRepository>(mockProfileRepository.GetType());
>
> > Register does this:
>
> > public void Register(Type contractType, Type concreteType)
> > {
> > lock ( lockObject )
> > {
> > if ( instance.typeMappings.ContainsKey(contractType) )
> > {
> > instance.typeMappings.Remove(contractType);
> > }
> > instance.typeMappings.Add(contractType, concreteType);
> > }
> > }
>
> > and it blows up with "No parameterless constructor defined for this
> > object"
>
> > I can't figure out why....- 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.