Telerik® JustMock™ by Progress

JustCode provides support for Telerik JustMock by automatically generating mocks and arrangements. This makes the writing of JustMock unit tests much easier.

Getting Started

The only thing you need, in order to use this functionality, is the Telerik.JustMock.dll referenced in the current project. Then, creating or arranging a mock through JustCode will automatically include the required usings (Telerik.JustMock; and Telerik.JustMock.Helpers; if fluent syntax is used).

Both, the Create Mock and the Arrange Mock commands are placed inside the Visual Aid menu of JustCode.

Create Mocks

To use the Create Mock command, you need to have a similar to the following declaration:

Just Code Integration Create MockVAMenu

Executing the command will result in a creation of a mock with default behavior:

Just Code Integration Create Mock Result

Arrange Mocks

You can use the Arrange Mock command on declarations, such as:

  • Foo myMock = Mock.Create<Foo>();
  • var myMock = Mock.Create<Foo>();
  • Foo myMock; - here the mock is not even created. Its creation will be automatically generated by JustCode.
  • Foo myMock = new Foo(); or var myMock = new Foo(); - for this initialization, JustCode will automatically apply partial mocking for the arranged methods.

Just Code Integration Arrange MockVAMenu

Clicking on the Arrange Mock command will prompt a window, containing all mockable members of the instance. You will notice JustCode shows non public methods and properties as well.

You can also choose between standard arrangements or fluent syntax.

The next image describes the functionalities inside the Arrange Mock configuration window:

Just Code Integration Arrange Mock Select Members Interface With Options

Let's assume we have the following Foo class:

Just Code Integration SUT

When you click the Finish button, the following code will be automatically generated for it:

Just Code Integration Arrange Mock Result

Expected Arrangement's Behavior

The template for the Arrange Mock command is as follows:

Arranging functions or property getters:

  • Value type functions/properties are arranged to return the default value for their type:

    Examples:

    Mock.Arrange(() => myMock.IntProperty).Returns(0);
    Mock.Arrange(() => myMock.IntFunction()).Returns(0);
  • For string functions/properties the expected return value is String.Empty or "":

    Examples:

    Mock.Arrange(() => myMock.StringProperty).Returns("");
    Mock.Arrange(() => myMock.StringFunction()).Returns("");
  • Reference type functions/properties will return a new mock of their type:

    Examples:

    Bar expectedRefProperty = Mock.Create<Bar>();
    Mock.Arrange(() => myMock.RefProperty).Returns(expectedRefProperty);
    Bar expectedRefFunction = Mock.Create<Bar>();
    Mock.Arrange(() => myMock.RefFunction()).Returns(expectedRefFunction);

Arranging void methods:

By default, void methods will be arranged to .DoNothing().
Examples:
Mock.Arrange(() => myMock.VoidMethod()).DoNothing();

Arranging property setters:

At this stage, JustMock allows arranging for property setters only if they are public. The JustCode's Arrange Mock command will generate the following for them:
  • Value type properties are set the default value for their type:

    Examples:

    Mock.ArrangeSet(() => myMock.IntProp = 0);
  • For string properties the expected set value is String.Empty or "":

    Examples:

    Mock.Arrange(() => myMock.Category = "");
  • Reference type properties will be set to the default of their type:

    Examples:

    Mock.Arrange(() => myMock.RefProperty = default(Bar));

Matching arguments

For the expected method/function arguments JustCode uses the matchers, inside JustMock:
Examples:
Mock.Arrange(() => myMock.DoSomething(Arg.AnyBool, Arg.AnyString, Arg.IsAny<Bar>())).DoNothing();

See Also