How to use MoqAutoMocker that comes with StructureMap 2.5.3?

I am trying to use the MoqAutoMocker class that comes with StructureMap and I cannot find examples of how to use it. All I need is an example on the StructureMap website that uses RhinoMocks .

What I'm trying to do is get a link to one of my dependencies with automatic bullying / injection using the Get method. According to this link above, I would have to do something like this

    // This retrieves the mock object for IMockedService
    autoMocker.Get<IMockedService>().AssertWasCalled(s => s.Go());

Notice how you can use AssertWasCalled, which distorts that the Get function returns a reference to the RhinoMocks Mock object? The same bit of code does not work for me when I use MoqAutoMocker.

I have a SignInController class that depends on the ISecurityService in the constructor. Using MoqAutoMocker, like RhinoAutoMocker, is used in this example, I think I should do this ...

var autoMocker = new MoqAutoMocker<SignInController>();
autoMocker.Get<ISecurityService>().Setup(ss => ss.ValidateLogin
(It.IsAny<string>(), It.IsAny<string>())).Returns(true); 

But the problem is that I never get access to the installation method. In this case, calling autoMocker.Get seems to return an ISecurityService instance, not a Mock <ISecurityService>

Has anyone successfully used MoqAutoMocker in this way? Am I just doing it wrong?

+5
source share
2 answers

I recently ran into simillar problem. It seems like the solution is to do something like this:

var autoMocker = new MoqAutoMocker<SignInController>();
var mock = autoMocker.Get<ISecurityService>();
Mock.Get(mock).Setup(ss => ss.ValidateLogin
(It.IsAny<string>(), It.IsAny<string>())).Returns(true);

: StructureMaps MoqAutoMocker.

+10

autoMocker.Get<ISecurityService>()
ISecurityService, .
Mock.Get(mock)
Moq.Mock, .

+1

All Articles