Verifying Static Methods

To verify that a static method was called, use the same API as fake objects. You can verify calls only on the types that were activated with Isolate.WhenCalled().

When to Use

When you want to check a case when a specific static method is called.

Syntax

C#

Isolate.Verify.<Verification_Statement>(() => <static_method>);

VB

Isolate.Verify.<Verification_Statement>(Function() <static_method>)

Samples

The following sample shows how to verify whether a static method was called.

C#

[TestMethod, Isolated]
public void VerifyStaticMethodWasCalled()
{
  Isolate.Fake.StaticMethods<Dependency>(Members.ReturnRecursiveFakes); // Must Fake At Least One Static Method
  var result = new ClassUnderTest().Calculate(1, 2);
  Isolate.Verify.WasCalledWithAnyArguments(() => Dependency.CheckSecurity(null, null));
}

VB

<TestMethod(), Isolated()>
Public Sub VerifyStaticMethodWasCalled()     
  Isolate.Fake.StaticMethods(Of Dependency)(Members.ReturnRecursiveFakes)
  Dim result = New ClassUnderTest().Calculate(1, 2)
  Isolate.Verify.WasCalledWithAnyArguments(Sub() Dependency.CheckSecurity(Nothing, Nothing))
End Sub