使用Josh Flanagans StructureMap Automocking overview,我正在尝试它但是可以获得以下代码来返回我指定的Category对象:
[Test]
public void Service_Should_Return_Category_From_ID()
{
// Arrange
var categoryToTest = new Category()
{
ID = 1,
Name = "Department 1",
Description = "Department 1 description"
};
var mocks = new RhinoAutoMocker<CatalogueService>();
mocks.Get<ICatalogueService>().Stub(c => c.GetCategory(1)).Return(categoryToTest);
// Act
var categoryResult = mocks.ClassUnderTest.GetCategory(1);
// Assert
Assert.IsNotNull(categoryResult);
Assert.AreEqual(categoryToTest.ID, categoryResult.ID);
}
我做错了什么?
答案 0 :(得分:0)
我将返回值添加到被测试类的接口,而不是正在被注入的接口。