我創建一個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