Progress Telerik JustMock

Mock Generics

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

    Generics introduce the concept of type parameters to .NET. Type parameters make it possible to design classes and methods that defer the specification of one or more types until the class or method is declared and instantiated by client code.
    Generics are a pillar of modern software design, often used as method parameters and as such represent a dependency to that method.
  • Mocking Generic Class

    JustMock makes it easy to mock a generic class as easy as mocking a non-generic one. The construction is the same.

    var foo = Mock.Create<FooGeneric<int>>();
  • Mocking Generic Method in Non-Generic Class

    Mocking of generic methods with JustMock is as easy as mocking a non-generic method.

    public void ShouldMockGenericMethodInNonGenericClass()
        var foo = Mock.Create<Foo>();
        Mock.Arrange(() => foo.Get<int, int>(1)).Returns(10);
        // Act
        var actual = foo.Get<int, int>(1);
        Assert.AreEqual(10, actual);

    Mock of generics documentation 

Next Steps

See Plans & Pricing

Purchase individual products or any of the bundles

Download Free Trial

With dedicated technical support.