2013-10-18 1 views
3

내가, 여기에 내가 내 테스트에서 조롱하고 싶은 클래스입니다했다 그것의 일부 인터페이스입니다 :RhinoMocks은 일반적인 방법에서 InvalidOperationException을 던지고

interface IInventory 
{ 
    Instrument[] GetAllInstrumentsAffectedByFixSide(int fixSideNumber); 

    bool IsRegistered<T>(string name, int? fixSideNumber) where T : InventoryObject; 
} 

내 기록은 다음과 같습니다

using (mockRepository.Record()) 
{ 
    inventory.GetAllInstrumentsAffectedByFixSide(0); 
    LastCall.Return(new Instrument[0]); 

    inventory.Expect(x => x.IsRegistered<TestInstrument>("ActivatorInstrument", null)).IgnoreArguments().Return(true) 
} 

는하지만 내 코드 테스트 대상이를 쓸 때 :

TestHandler.Inventory.IsRegistered<TestInstrument>("ActivatorInstrument", null) 

그것은 InvalidOperationException이 발생합니다. 그것은이 예외를 발생 장소는 재미있다 - 그것은 모양의이 MethodInfo.GetGenericMethodDefinition()

원천입니다 :

public override MethodInfo GetGenericMethodDefinition() 
{ 
    if (!IsGenericMethod) 
     throw new InvalidOperationException(); 
    Contract.EndContractBlock(); 

    return RuntimeType.GetMethodBase(m_declaringType, RuntimeMethodHandle.StripMethodInstantiation(this)) as MethodInfo; 
} 

그래서이 방법은 실제로 일반적인되지 방법에 호출됩니다. breakpoint를 안에 넣었을 때이 methodInfo가 무엇인지 확인했을 때 실제로는 IsRegistered<> 메서드가 아니라는 것을 알았지 만 GetAllInstrumentsAffectedByFixSide입니다.

Rhino가 IsRegistered<>의 모의 전화에서 GetAllInstrumentsAffectedByFixSide 메서드에 대해 GetGenericMethodDefinition을 호출해야하는 이유는 무엇입니까? 이전에 GetGenericMethodDefinition 콜이 발생했습니다. 그것은 단지이 두 가지 방법을 혼란스럽게하는 것처럼 보입니다.

스택 트레이스 :

at System.Reflection.RuntimeMethodInfo.GetGenericMethodDefinition() 
at Rhino.Mocks.MethodRecorders.UnorderedMethodRecorder.MethodsEquals(MethodInfo method, ProxyMethodExpectationTriplet triplet) 
at Rhino.Mocks.MethodRecorders.UnorderedMethodRecorder.GetAllExpectationsForProxyAndMethod(Object proxy, MethodInfo method) 
at Rhino.Mocks.MethodRecorders.UnorderedMethodRecorder.CalcExpectedAndActual.Calculate(Object proxy, MethodInfo method, Object[] args) 
at Rhino.Mocks.MethodRecorders.UnorderedMethodRecorder.CalcExpectedAndActual..ctor(UnorderedMethodRecorder parent, Object proxy, MethodInfo method, Object[] args) 
at Rhino.Mocks.MethodRecorders.UnorderedMethodRecorder.UnexpectedMethodCall(IInvocation invocation, Object proxy, MethodInfo method, Object[] args) 
at Rhino.Mocks.MethodRecorders.UnorderedMethodRecorder.DoGetRecordedExpectation(IInvocation invocation, Object proxy, MethodInfo method, Object[] args) 
at Rhino.Mocks.MethodRecorders.MethodRecorderBase.GetRecordedExpectation(IInvocation invocation, Object proxy, MethodInfo method, Object[] args) 
at Rhino.Mocks.Impl.ReplayMockState.DoMethodCall(IInvocation invocation, MethodInfo method, Object[] args) 
at Rhino.Mocks.Impl.ReplayMockState.MethodCall(IInvocation invocation, MethodInfo method, Object[] args) 
at Rhino.Mocks.MockRepository.MethodCall(IInvocation invocation, Object proxy, MethodInfo method, Object[] args) 
at Rhino.Mocks.Impl.RhinoInterceptor.Intercept(IInvocation invocation) 
at Castle.DynamicProxy.AbstractInvocation.Proceed() 
at IInventoryProxy4a132be1cb07441cafba3f828d3ced66.IsRegistered[T](String name, Nullable`1 fixSideNumber) 
at TestHandlerLibrary.DummyFixSideHandler.DoInitialization() in \RTX.Test.TestGear.DummyTestHandlerLibrary\DummyFixSideHandler.cs:line 87 

UPD 내가했던 문제의 실수 : 나는 실제로 설치 기대로 :

inventory.Expect(x => x.IsRegistered<TestInstrument>("ActivatorInstrument", null)).IgnoreArguments().Return(true); 

나는 변경이 .Expect없이 직접 설치, 그리고 LastCall과 함께 - 실제로 작동합니다. 이견있는 사람? 문제를 반영하기 위해 위 코드를 변경했습니다.

+0

남아는 구조의 모든으로 버전 3.6.0에서 업데이트하는 데 문제가 될 것을 생각하지 않는다 사용 하시겠습니까? 나는 역사를 회고하려고 노력하고있다. 그러나 나는 * 이것이 코뿔소 조롱으로 알려진 버그라고 생각한다. 이 문제에 대한 독립적이고 완전한 코드 예제를 작성하여 직접 재현 할 수 있습니까? – vcsjones

+0

3.6.0 시도 할 수는 있지만 작동하지 않을 것입니다. 많은 단위 테스트가 있고 일반적인 방법이 많이 있습니다. 어떤 이유에 의해서만 예외가 발생합니다. 나는 아직 어떤 차이도 발견하지 못했다. – Archeg

+0

@vcsjones 나는 그 게시물에 대한 업데이트를 만들었다. – Archeg

답변

0

이 문제는 버전 3.6.1

으로 수정되었습니다 나는 코뿔소 모의 객체의 어떤 버전을하다

관련 문제