background

Telerik JustMock

Mock Named Arguments

  • JustMock enables you to easily mock method calls with named arguments even if those methods are static.
  • Part of the fastest, most flexible and complete mocking tool for crafting unit tests.
  • Our award-winning support team is available to assist you with any issues.
Mock everything
  • Mocking Methods with Named Arguments Overview

    Named arguments enable you to specify an argument for a parameter by matching the argument with its name rather than with its position in the parameter list.

    JustMock allows you to easily mock method calls with named arguments even if those methods are static.

    internal class Foo
    {
      public static void StaticAction(int param1 = 0, int param2 = 0, int param3 = 0)
      {
        throw new NotImplementedException();
      }
    }
     
    ...
     
    [TestMethod]
    public void TestStaticMethodAcceptingNamedParameters()
    {
      // Arrange
      Mock.SetupStatic<Foo>();
      Mock.Arrange<Foo>(() => Foo.StaticAction(param2: 2, param1: 3)).OccursOnce();
     
      // Act
      Foo.StaticAction(3, 2);
     
      // Assert
      Mock.Assert<Foo>();
    }

    JustMock documentation
Next Steps