功能已截断,结构图自动锁定不返回值

时间:2009-05-19 05:28:02

标签: c# structuremap-automocking

使用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);
    }

我做错了什么?

1 个答案:

答案 0 :(得分:0)

我将返回值添加到被测试类的接口,而不是正在被注入的接口。