2012-09-07 2 views
1

속성 (double 값)이 설정된 경우 내 스텁에서 예외를 throw해야합니다 (값에 관계 없음). Rhino Mocks 3.5를 사용하여 어떻게이 작업을 수행 할 수 있습니까?Rhino Mocks에서 속성을 설정할 때 예외를 throw하는 방법

 var myMock = MockRepository.GenerateStub<MyInterface>(); 
     myMock.Stub(x => x.MyProperty).Throw(new Exception()); 

그러나 그것은 나에게 제공합니다 :

나는이 시도

System.InvalidOperationException : You are trying to set an expectation on a property that was defined to use PropertyBehavior. 
Instead of writing code such as this: mockObject.Stub(x => x.SomeProperty).Return(42); 
You can use the property directly to achieve the same result: mockObject.SomeProperty = 42; 

을하지만,이 경우에 나는 그것을 던져해야 설정하고 간단한 값을 얻기에 대해서 이야기하고 있지 않다.

답변

3

당신은,이 버전은 GenerateStub에 문제가 MockRepository.GenerateMock,

var myMock = MockRepository.GenerateMock<MyInterface>(); 
myMock.Stub(x => x.MyProperty).Throw(new Exception()); 
+1

감사를 교체해야합니다! GenerateMock에 대해 알아야 할 것이 있습니까? 아니면 모든 GenerateStub를 GenerateMock으로 대체 할 수 있습니까? – Emile

+1

에밀, 당신의 필요에 따라 적응해 드리겠습니다.이 경우에는 –