Mocking named instance

54 views
Skip to first unread message

Raif

unread,
Jul 27, 2010, 12:53:52 PM7/27/10
to structuremap-users
Hi, I did a search on here form this subject and got nothing, but I
never trust the search on google groups so if there's another thread
just point me there.
I am using automocker with rhinomocks and I have a registry which sets
up some named instances for an interface. In my controller method I'm
calling
ObjectFactory.Container.GetInstance<IParentPropertyMapService>(input.MapType);
this works great but I can't seem to mock it for my tests. I've
written the tests and just given them the attribute ignore cuz I can't
get this to work. should I create the mock then inject it into the
automocker?
Any suggestions?
thanks,
R

Jeremy Miller

unread,
Jul 27, 2010, 3:39:43 PM7/27/10
to structuremap-users
Raif,

You can get at the automocker's container itself like so to inject
other mocks (named and otherwise):

var mocker = new RhinoAutoMocker<MyClass>();
mocker.Container.Configure(x =>
x.For<IParentPropertyMapService>().Add( your mock
object ).Named( input.MapType );

Raif

unread,
Jul 28, 2010, 3:27:47 PM7/28/10
to structuremap-users
Ah, I see.
Thanks
R

Raif

unread,
Aug 11, 2010, 6:39:07 PM8/11/10
to structuremap-users
Hmmm, just got back to this and seem to still be having trouble.
here's what I've tried
S2CPropertyMapService _service = new
S2CPropertyMapService(MockFor<IRepository>(),
MockFor<ISinglePropertyMapService>(), MockFor<ISaveEntityService>());
// i've also tried just mocking the concrete
S2CPropertyMapService and the interface ( IParentPropertyMapService )
to no avail
Services.Container.Configure(x =>
x.For<IParentPropertyMapService>().Add(_service).Named("SourceToChild"));
_map = new PropertyMap { GUID = Guid.NewGuid() };
_service.Expect(x =>
x.AddOrUpdateMapProperty(null)).IgnoreArguments().Return(new
PropertyMapContinuation { Success = true, Map = _map });

when I get to the point of setting my expectations it fails
I've also tried retrieving my object from the container then setting
the expectations on that as well. same result. Am I doing something
wrong?
R

On Jul 28, 2:27 pm, Raif <reha...@gmail.com> wrote:
> Ah, I see.
> Thanks
> R
>
> On Jul 27, 2:39 pm, Jeremy Miller <jeremydmil...@yahoo.com> wrote:
>
> >Raif,
>
> > You can get at the automocker's container itself like so to inject
> > other mocks (named and otherwise):
>
> > var mocker = new RhinoAutoMocker<MyClass>();
> > mocker.Container.Configure(x =>
> > x.For<IParentPropertyMapService>().Add(  your mock
> > object ).Named(  input.MapType  );
>
Reply all
Reply to author
Forward
0 new messages