views:

192

answers:

1

Hello,

I am creating a DynamicMultiMock as follows:

this.serviceClient = this.mocks.DynamicMultiMock<ISlippyPlateProcedureService>(typeof(ICommunicationObject));

Then setting the following expectation:

Expect.Call(((ICommunicationObject)this.serviceClient).State).Return(CommunicationState.Faulted);

When I execute the test, Rhino Mocks reports this:
Replayed expectation: ICommunicationObject.get_State();
Dynamic Mock: Unexpected method call ignored: ICommunicationObject.get_State();

Am I correctly setting this expectation or is there another way?

Editing to include the complete test code:

        Expect.Call(this.syncContextContainer.SynchronizationContext).Return(new SlippyPlateProcedureSynchronizationContextMock());
        Expect.Call(this.clientFactory.CreateServiceClient(null)).IgnoreArguments().Return(this.serviceClient);
        Expect.Call(((ICommunicationObject)this.serviceClient).State).Return(CommunicationState.Faulted);
        Expect.Call(() => this.serviceClient.IsAlive());
        this.mocks.ReplayAll();
        SlippyPlateProcedureClient client = new SlippyPlateProcedureClient(
            this.syncContextContainer, this.clientFactory, this.container);
        PrivateObject privateObject = new PrivateObject(client);
        SlippyPlateProcedureClient_Accessor target = new SlippyPlateProcedureClient_Accessor(privateObject);

        target.CheckServerConnectivity();

        this.mocks.VerifyAll();

Thanks

Andrey

A: 

Its really hard to tell what is going wrong without seeing your production code. The following test passes:

public interface IA
    {
        int A(int a);
    }

    public interface IB
    {
        int B(int b);
    }

    [Test]
    public void Multimocks()
    {
        MockRepository mocks = new MockRepository();
        IA mymock = mocks.DynamicMultiMock<IA>(typeof (IB));
        Expect.Call(mymock.A(1)).Return(2);
        Expect.Call(((IB)mymock).B(3)).Return(4);
        mocks.ReplayAll();

        Assert.AreEqual(2, mymock.A(1));
        Assert.AreEqual(4, ((IB)mymock).B(3));
    }

which means that the multimocks work correctly. Are you sure you are not calling State more than once? Try changing your mocks to StrictMocks (you will get an exception when calls are not expected), so:

this.serviceClient = this.mocks.StrictMultiMock<ISlippyPlateProcedureService>(typeof(ICommunicationObject));

and let the property be read multiple times:

Expect.Call(((ICommunicationObject)this.serviceClient).State).Return(CommunicationState.Faulted).Repeat.Any();

let me know what is your progress.

Grzenio
Hi, I was away doing some other work and returned to this issue today. You're right, multimocks works, and State was being called more than once. Thanks!
Andrey