Progress Telerik JustMock

Recursive Mocking

Nasa, Visa, Microsoft Fox, Samsung, IBM World Bank Group, Volvo
  • Recursive Mocking Overview

    Recursive mocking is a productivity feature that allows you to mock a chained call to a member. This saves you the effort to create new objects, associating them to members, and executing additional logic for the "chain" to be fully prepared for access.

    [TestMethod]
    public void ShouldAssertNestedPropertyGet()
    {
        var expected = 10;
     
        // ARRANGE
        // Creating a mocked instance of the "IFoo" interface.
        var foo = Mock.Create<IFoo>();
     
        // Arranging: When foo.Bar.Value is called, it should return expected value.
        //              This will automatically create mock of foo.Bar
        //              and a NullReferenceException will be avoided.
        Mock.Arrange(() => foo.Bar.Value).Returns(expected);
     
        // ACT
        var actual = foo.Bar.Value;
     
        // ASSERT
        Assert.AreEqual(expected, actual);
    }

    Recursive mocking documentation
Background-NextSteps

Next Steps

See Plans & Pricing

Purchase individual products or any of the bundles

Download Free Trial

With dedicated technical support.