Ale*_*lex 4 c# unit-testing rhino-mocks
我试图模拟一个接口.我想设置"MockThisProperty"的属性没有setter.我无法更改接口源.我得到的错误是
上一个方法'IThirdPartyInterface.get_MockThisProperty();' 需要返回值或抛出异常.
我尝试过DynamicMock,Strictmock,部分模拟等.
当我尝试SetupResult.For(thirdParty.MockThisProperty = mockedValue)将无法编译,因为没有setter.
使用mstest的最新Rhino模拟
不知所措,这是代码......
var stuff = _Mockery.Stub<Hashtable>();
matchItem.Add(key, "Test");
var thirdParty = _Mockery.Stub<IThirdPartyInterface>();
SetupResult.For(thirdParty.MockThisProperty).Return(stuff);
_Mockery.BackToRecordAll();
//more code
_Mockery.ReplayAll();
Assert.IsTrue(MethodToTest(thirdParty));
_Mockery.VerifyAll();
Run Code Online (Sandbox Code Playgroud)
这对我有用:
var thirdParty = Rhino.Mocks.MockRepository.GenerateStub<IThirdPartyInterface>();
thirdParty.Stub(x => x.MockThisProperty).Return("bar");
string mockPropertyValue = thirdParty.MockThisProperty; //returns "bar"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1985 次 |
| 最近记录: |