Function stubbed out with Structuremap Automocking not returning value

346 Views Asked by At

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:

    [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

There are 1 best solutions below

0
On

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