Concrete mocking is one of the advanced features supported in Telerik JustMock. Up to this point we have been talking mostly
about mocking interfaces. This feature allows you to mock the creation of an object.
To some extent this is available in the free edition and there are more things you can do in the commercial edition of the product.
In this topic we will go through some examples demonstrating these differences.
Telerik JustMock also gives you the ability to explicitly specify whether a constructor should be mocked or not.
Refer to this topic to learn more about mocking internal types via proxy.
In the further examples we will use the following sample class:
Note that we have declared a concrete class FooVirtual which does not implement any interfaces.
Mocking concrete classes with virtual methods
What we need to do is to make sure that all class members are virtual. As you will see in the later examples
there is a way to overcome this restriction. Here is the example code:
When using Mock.Create to create your mocked instance of a specific class you can specify whether or not the
constructor should be mocked. You can choose from the Constructor enumeration:
By default the constructor is not mocked.
Note that in the Arrange part of this example we use the
This example shows how Telerik JustMock allows us to add behaviour checking - it will call the original
GetList() method, verififing that the method call is made only once.
Concrete classes advanced mocking
This feature allows you to mock concrete objects without having to change anything in their interface.
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.
Here is the example class we are going to use:
Note that here we are going to mock an instance of the Foo class in the same way as we did for
FooVirtual while Foo does not need to have all its members declared as