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

时间:2023-01-23 18:16:02

Using Josh Flanagans StructureMap Automocking overview, I'm trying my hand at it but can get the following code to return the Category object I've assigned:

使用Josh Flanagans StructureMap自动锁定概述,我正在尝试使用它,但可以获取以下代码以返回我指定的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);
    }

What am I doing wrong?

我究竟做错了什么?

1 个解决方案

#1


I was adding the return value to the Interface of the class under test, not the Interface that was being Injected.

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

#1


I was adding the return value to the Interface of the class under test, not the Interface that was being Injected.

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