JCh*_*ian 26 .net c# rhino-mocks
我有一个私有集属性的类,我想用犀牛模拟存根.但是,当我尝试这样做时,它给了我一个编译时错误,说我无法设置只读属性.我是新手使用Rhino Mocks所以我必须在这里遗漏一些东西......
public Interface IFoo
{
int Quantity { get; }
}
[TestMethod]
public void SomeTest()
{
IFoo foo = MockRepository.GenerateStub<IFoo>();
foo.Quantity = 5;
//Asserts and such
}
Run Code Online (Sandbox Code Playgroud)
Pet*_*ete 34
使用:
foo.Stub (f => f.Quantity).Return (5);
Run Code Online (Sandbox Code Playgroud)
请参阅http://ayende.com/Wiki/Rhino+Mocks+3.5.ashx#UsingExpecttosetupproperties
您还可以使用:
foo.Expect(f => f.Quantity).Return (5);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9772 次 |
| 最近记录: |