我创建一个DynamicMultiMock如下设置与返回值的预期:犀牛制品DynamicMultiMock - 额外接口
this.serviceClient = this.mocks.DynamicMultiMock<ISlippyPlateProcedureService>(typeof(ICommunicationObject));
然后设置以下期待:
Expect.Call(((ICommunicationObject)this.serviceClient).State).Return(CommunicationState.Faulted);
当我执行测试,犀牛Mocks报告如下:
重播预期:ICommunicationObject.get_State();
动态模拟:意外的方法调用忽略:ICommunicationObject.get_State();
我是否正确地设定了这个期望值还是有另一种方法?
编辑,包括完整的测试代码:
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();
感谢
安德烈
你可以粘贴整个测试吗?乍一看,这条线看起来是正确的... – Grzenio 2010-03-11 16:41:45