Call Original
The CallOriginal
method marks a mocked method/property call that should execute the original method/property implementation.
CallOriginal with Void Calls
You can use CallOriginal
on methods and properties. This also includes methods that doesn't return a value. Consider the following class:
Sample setup
Let's arrange its Info
method to be called with its original implementation and verify the call.
Example 1: Calling the original implementation
The call of the Info
method throws an exception. To verify this behavior, we use the ExpectedException attribute provided from the Microsoft.VisualStudio.TestTools.UnitTesting namespace (found in Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll).
CallOriginal Depending on Parameter Value
This section shows how you can set up that a call to a method should call the original implementation for one argument and fake for another argument.
For this example, we will use the following sample class:
Sample setup
Example 2 shows how to implement the different behavior of the mocked object depending on the parameter value the method is invoked with.