当我的存根的属性(双精度)被设置(为任何值)时,我的存根应该抛出一个异常。如何使用 Rhino Mocks 3.5 完成此任务?
我试过这个:
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;
但在这种情况下,我不是在谈论设置和获取一个简单的值,它应该抛出。