Progress Telerik JustMock

Mock Delegates

  • JustMock enables you to use mock delegates in your favorite .NET language.
  • This feature is a part of the fastest, most flexible and complete mocking tool for crafting unit tests.
  • Our award-winning support team is dedicated to assisting you with any questions and issues you may have during your application development.
Mock everything
Nasa, Visa, Microsoft Fox, Samsung, IBM World Bank Group, Volvo
  • Mocking Delegates Overview

    JustMock allows you to use the framework's full capabilities for mocking delegates in your favorite .NET language, whether it is C# or VB. For example, you can arrange a delegate behavior with predefined expectations and assert against its invocation.
  • Return a Predefined Value

    When you isolate your test case from a call to a delegate, a common requirement is that the delegate returns a predefined value.

    public class Foo
    {
        public Func<int, int> FuncDelegate { get; set; }
      
        public int GetInteger(int toThisInt)
        {
            return FuncDelegate(toThisInt);
        }
    }
     
    ...
     
    [TestMethod]
    public void ShouldArrangeReturnExpectation()
    {
        // ARRANGE
        // Creating a mock instance of the Func<int, int> delegate.
        var delegateMock = Mock.Create<Func<int, int>>();
         
        // Arranging:   When the mock is called with 10 as an integer argument,
        //              it should return 20.
        Mock.Arrange(() => delegateMock(10)).Returns(20);
     
        // ACT
        var foo = new Foo();
        // Assigning the mock to the dependent property.
        foo.FuncDelegate = delegateMock;
        var actual = foo.GetInteger(10);
         
        // ASSERT
        Assert.AreEqual(20, actual);
    }

    Mock delegates documentation
Background-NextSteps

Next Steps

See Plans & Pricing

Purchase individual products or any of the bundles

Download Free Trial

With dedicated technical support.