You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.0 KiB
43 lines
1.0 KiB
using System.Diagnostics;
|
|
using FluentAssertions.Execution;
|
|
using NSubstitute.Core.Arguments;
|
|
|
|
namespace TestLibrary.NSubstitute;
|
|
|
|
// Interface changes in IArgumentMatcher make nullability difficult
|
|
// to deal with. So we just ignore that here for now.
|
|
#nullable disable
|
|
|
|
public static class Verify
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
}
|