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.
36 lines
926 B
36 lines
926 B
4 years ago
|
using System.Diagnostics;
|
||
|
using FluentAssertions.Execution;
|
||
|
using NSubstitute.Core.Arguments;
|
||
|
|
||
2 years ago
|
namespace Recyclarr.TestLibrary.NSubstitute;
|
||
3 years ago
|
|
||
3 years ago
|
// Interface changes in IArgumentMatcher make nullability difficult
|
||
|
// to deal with. So we just ignore that here for now.
|
||
|
#nullable disable
|
||
|
|
||
3 years ago
|
public static class Verify
|
||
4 years ago
|
{
|
||
3 years ago
|
public static T That<T>(Action<T> action)
|
||
4 years ago
|
{
|
||
3 years ago
|
return ArgumentMatcher.Enqueue(new AssertionMatcher<T>(action));
|
||
|
}
|
||
|
|
||
1 year ago
|
private sealed class AssertionMatcher<T>(Action<T> assertion) : IArgumentMatcher<T>
|
||
3 years ago
|
{
|
||
|
public bool IsSatisfiedBy(T argument)
|
||
4 years ago
|
{
|
||
3 years ago
|
using var scope = new AssertionScope();
|
||
1 year ago
|
assertion(argument);
|
||
4 years ago
|
|
||
3 years ago
|
var failures = scope.Discard().ToList();
|
||
|
if (failures.Count == 0)
|
||
4 years ago
|
{
|
||
3 years ago
|
return true;
|
||
4 years ago
|
}
|
||
|
|
||
3 years ago
|
failures.ForEach(x => Trace.WriteLine(x));
|
||
|
return false;
|
||
4 years ago
|
}
|
||
|
}
|
||
|
}
|