Skip to content

Instantly share code, notes, and snippets.

@scottheckel
Created June 6, 2017 21:14
Show Gist options
  • Save scottheckel/60d2c9dce3eaeac37f37a61b09711729 to your computer and use it in GitHub Desktop.
Save scottheckel/60d2c9dce3eaeac37f37a61b09711729 to your computer and use it in GitHub Desktop.
Microsoft Fakes Stub Verify Method Called
public static class StubBaseExtensions
{
/// <summary>
/// Verify if a method was called on a stub
/// </summary>
/// <remarks>Derived from code found on http://www.peterprovost.org/blog/2012/11/29/visual-studio-2012-fakes-part-3/ </remarks>
/// <param name="stub">Stub</param>
/// <param name="methodName">Method Name</param>
/// <returns>True if <paramref name="methodName"/> was called</returns>
public static bool VerifyMethodCalled(this StubBase stub, string methodName)
{
return ((StubObserver)stub.InstanceObserver).GetCalls().Any(call => call.StubbedMethod.Name == methodName);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment