模仿对象

时间:2010-12-08 16:28:09

标签: .net mocking

我如何在.net中的nhibernate中的相同repository.SaveOrUpdate(Object)上设置期望。

1 个答案:

答案 0 :(得分:0)

如果您使用Moq框架,则可以执行类似于...

Mock<IDataAccessObject> mockDataAccess = new Mock<IDataAccessObject>();

// Setting up the mock to return expected values as part of the tests
mockDataAccess.Setup(dal => dal.SaveOrUpdate(Object)).Returns(expectedReturnValue);

// Calling the receiver business layer passing in the mocked DataAccess
using (BusinessLayerObject bl = new BusinessLayerObject(mockDataAccess.Object))
{
    result = bl.SaveOrUpdate(Object);
}