繁体   English   中英

如何告诉RhinoMocks返回作为参数传递的同一对象

[英]How do I tell RhinoMocks to return the same object passed as parameter

我正在使用RhinoMock进行单元测试,我想知道如何设置它,因此特定方法总是返回它作为参数接收的相同对象。

这是我想要模拟的界面:

public interface IItemRepository
{
    Item Craete(Item item);
}

我想以这样的方式设置RhinoMocks:每次调用Create方法时,模拟的存根将返回作为参数传递的同一对象。

这是我的测试初始化​​方法:

[TestInitialize]
public void CrateServiceWithMockRepository()
{
    var stubRepository = MockRepository.GenerateStub<IItemRepository>();

    // ... how to set-up the stubRepository as described above ...

    // Create the target service for this unit test
    this.targetService = new ServiceXYZ(stubRepository);
}

您可以使用Do并在调用方法时传递委托来执行:

stubRepository.Stub(r => r.Create(null)).IgnoreArguments()
    .Do(new Func<Item, Item>(item => item));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM