Skip to content

Instantly share code, notes, and snippets.

@gustavopsantos
Created February 11, 2023 13:29
Show Gist options
  • Save gustavopsantos/5364e2331e93c49e40bfd03d7ac104cf to your computer and use it in GitHub Desktop.
Save gustavopsantos/5364e2331e93c49e40bfd03d7ac104cf to your computer and use it in GitHub Desktop.
CallbackAssertion for FluentAssertions
public class CallbackAssertion
{
private int _calls;
private readonly Action _call;
public CallbackAssertion()
{
_call = () => _calls++;
}
public static implicit operator Action(CallbackAssertion callbackAssertion)
{
return callbackAssertion._call;
}
public void ShouldBeCalledOnce()
{
_calls.Should().Be(1);
}
public void ShouldNotBeCalled()
{
_calls.Should().Be(0);
}
public void ShouldBeCalled(int times)
{
_calls.Should().Be(times);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment