Verifying Local Functions
When to Use
When you want to check a case when a specific local function is called.
To verify that a local function was called, use Isolate.Verify.NonPublic() with one of the following verification statements:
Statement |
Description |
LocalWasCalled |
Passes the verification if during the test execution, the call was made at least once. |
LocalWasNotCalled |
Passes the verification if the call was never made. |
Syntax
Main Method Type |
API |
Instance |
instance Isolate.Verify.NonPublic.LocalWasCalled(<instance>, "PrivateMethodname", "LocalFunctionName"); |
Static |
Isolate.Verify.NonPublic.LocalWasCalled(typeof(Dependency), "PrivateMethodname", "LocalFunctionName");. |
C# Instance: Isolate.Verify.NonPublic.LocalWasCalled(<instance>, "PrivateMethodname", "LocalFunctionName"); Static: Isolate.Verify.NonPublic.LocalWasCalled(typeof(Dependency), "PrivateMethodname", "LocalFunctionName");
Local functions which doesn't contain fields considered as static.
Public main methods are also supported with the Isolate.NonPublic API. This allows you to change the visibility of your methods without having to change the tests.
Samples
Sample 1: Verifying the Local Function without fields Was Called
The following sample shows how to verify that the static local function was called.
C# [TestMethod, Isolated] public void VerifyLocalFunctionWithoutField_WasCalled() { var fake = Isolate.Fake.Instance<ClassWithLocal>(Members.CallOriginal); Isolate.NonPublic.WhenCalledLocal(fake, "UseVoidLocal", "VoidLocal").CallOriginal(); fake.UseVoidLocal(); Isolate.Verify.NonPublic.LocalWasCalled(typeof(ClassWithLocal), "UseVoidLocal", "VoidLocal"); }
Sample 2: Verifying the Local Function was called.
The following sample shows how to verify the local function was called.
C# [TestMethod, Isolated] public void VerifyLocalFunctionWasCalled() { var fake = Isolate.Fake.Instance<ClassWithLocal>(Members.CallOriginal); Isolate.NonPublic.WhenCalledLocal(fake, "UseIntLocal", "GetLocal").CallOriginal(); var result = fake.UseIntLocal(); Isolate.Verify.NonPublic.LocalWasCalled(fake, "UseIntLocal", "GetLocal"); }