New to Telerik JustMockStart a free 30-day trial

Mocking Inside WinRT

Updated on Jan 29, 2026

You can use Telerik® JustMock in Windows Runtime to perform elevated or non-elevated testing.

Having an Unit Test Library (Windows Store apps) project, you need to refer the Telerik.JustMock assembly(ies). Then you will be able to mock everything as in standard .NET project.

Non-Elevated Examples

The next examples can be applied with both JustMock Lite and JustMock commercial (Commercial vs Free Version. For them, we will use the following system under test:

C#
public interface IFoo
{
    void DoSomething();

    string ReturnMyString(string arg);
}

Mocking Void Method from an Interface

To mock an interface under Windows Runtime, we use Mock.Create<T>():

C#
[TestMethod]
public void DoSomething_MustBeCalled()
{
    // Arrange
    var myMock = Mock.Create<IFoo>();

    Mock.Arrange(() => myMock.DoSomething()).DoNothing().MustBeCalled();

    // Act
    myMock.DoSomething();

    // Assert
    Mock.Assert(myMock);
}

In the above test, we create a mocked instance of the IFoo interface. Then, we arrange that, DoSomething() must be called during the test execution and it should do nothing. After acting on the system under test, we assert the expected behavior.

Mocking Functions from an Interface

Here we perform a mocking of an interface string method:

C#
[TestMethod]
public void ReturnMyString_ShouldReturnExpectedAndMustBeCalled()
{
    // Arrange
    var myMock = Mock.Create<IFoo>();

    Mock.Arrange(() => myMock.ReturnMyString(Arg.AnyString)).Returns("Test").MustBeCalled();

    // Act
    var actual = myMock.ReturnMyString("Telerik");

    // Assert
    Assert.AreEqual("Test", actual);
}

Again, we create a mocked instance of the IFoo interface. Then, we arrange that ReturnMyString() must be called during the test execution and it should return "Test". Note that we ignore the arguments by expecting any string to be passed. After acting on the system under test, we assert that the actual and the expected return value are the same.

Elevated Examples

This feature is available only in the commercial version of Telerik JustMock. Refer to this topic to learn more about the differences between both the commercial and free versions of Telerik JustMock.

For the examples, we will use the following system under test:

C#
static class FooStatic
{
    public static string StatProp { get; set; }

    public static void DoSomething()
    {
        throw new NotImplementedException();
    }
}

Important

You first need to go to elevated mode by enabling JustMock from the menu. Learn how to do that in the How to Enable/Disable Telerik JustMock topic.

Mocking Static Property

To mock a static property inside Windows Runtime you can refer to the following:

C#
[TestMethod]
public void StatProp_ShouldReturnExpectedAndMustBeCalled()
{
    // Arrange
    Mock.Arrange(() => FooStatic.StatProp).Returns("Test").MustBeCalled();

    // Act
    var actual = FooStatic.StatProp;

    // Assert
    Assert.AreEqual("Test", actual);
}

We directly arrange that, StatProp must be called during the test execution and it should return "Test". Then, the only thing needed is to act on the system under test and assert the results.

Mocking Static Method

To mock a static method you use similar syntax as when mocking properties. However, as we are mocking a void method we arrange it to do nothing this time:

C#
[TestMethod]
public void DoSomething_ShouldDoNothingAndMustBeCalled()
{
    // Arrange
    Mock.Arrange(() => FooStatic.DoSomething()).DoNothing().MustBeCalled();

    // Act
    FooStatic.DoSomething();

    // Assert
    Mock.Assert(() => FooStatic.DoSomething());
}

Further, you can also specify expected method arguments, as described in the Matchers article.