Created
February 11, 2023 13:29
-
-
Save gustavopsantos/5364e2331e93c49e40bfd03d7ac104cf to your computer and use it in GitHub Desktop.
CallbackAssertion for FluentAssertions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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