Created
March 3, 2020 08:24
-
-
Save Krusen/b9d957aa2d396fac327f6d1b70e053aa to your computer and use it in GitHub Desktop.
Updated version for NSubstitute 4.x of https://www.neovolve.com/2014/10/07/bridging-between-nsubstitute-and-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 static class Verify | |
{ | |
/// <summary> | |
/// Verifies that the fluent assertions in the <paramref name="action" /> are correct. | |
/// </summary> | |
/// <param name="action">An action with one or more fluent assertions</param> | |
public static T That<T>(Action<T> action) | |
{ | |
return ArgumentMatcher.Enqueue(new AssertionMatcher<T>(action)); | |
} | |
private class AssertionMatcher<T> : IArgumentMatcher<T> | |
{ | |
private readonly Action<T> _assertion; | |
public AssertionMatcher(Action<T> assertion) | |
{ | |
_assertion = assertion; | |
} | |
public bool IsSatisfiedBy(T argument) | |
{ | |
using (var scope = new AssertionScope()) | |
{ | |
_assertion(argument); | |
var failures = scope.Discard().ToList(); | |
if (failures.Count == 0) | |
{ | |
return true; | |
} | |
failures.ForEach(x => Trace.WriteLine(x)); | |
return false; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment