Telerik® JustMock™ by Progress

The CallOriginal method marks a mocked method/property call that should execute the original method/property implementation. This topic goes through a number of scenarios where the CallOriginal method is usefull.

Assert CallOriginal

For this example, we will use the following class:

Now, we will set up that a call to a method should call the original implementation for one argument and fake for another argument.

With the first arrange we set up that the original method implementation should be called when the method is called with argument "x", while with the second arrange we use the Returns behavior to specify that once the method is called with argument "y" it should return "z". Then we act and finally assert the execution.

CallOriginal with void calls

CallOriginal can be used also with methods returning void. Consider the following class:

Let's arrange its Info method to be called with its original implementation and verify the call.

The call of the Info method throws an exception. To verify this behavior we use the ExpectedException attribute provided from Microsoft.VisualStudio.TestTools.UnitTesting namespace (found in Microsoft.VisualStudio.QualityTools.UnitTestFramework assembly).

See Also

Other Resources