Telerik® JustMock™ by Progress

Sealed mocking is one of the advanced features supported in Telerik JustMock. It allows you to fake sealed classes and calls to their methods/properties, set expectations and verify results using the AAA principle. Faking sealed classes and calls to their methods/properties doesn't affect the way you write your tests, i.e. the same syntax is used for mocking non sealed classes.

Note

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.

Important

To use sealed mocking you first need to go to elevated mode by enabling Telerik JustMock from the menu. How to Enable/Disable Telerik JustMock?

In the further examples we will use the following sample classes and interface to test:

Assert Final Method Call on a Sealed Class

Set up a call to a final method on a sealed class and assert its return value.

Here we setup that a call to the final foo.Echo method with any int argument should return 10.

Create Mock for Sealed Class with Internal Constructor

Even the sealed class has only an internal constructor we can still create a mock, call its methods and verify the results.

Here we setup that a call to the final foo.Echo method with any int argument should return 10. After we ensure that the object is actually created, we assert for the return value of the foo.Echo method.

Create Mock for Sealed Class with Interface

When a mock is created by using Mock.Create all dependencies are also implemented. In the example below we mock the Foo class, which implements the IFoo interface.

Furthermore, if you are interested in IFoo interface implementation you can use the as operator and call the interface members as shown below.

In both examples a local variable is set to true once the Execute method is called.

See Also