using System.Diagnostics; using FluentAssertions.Execution; using NSubstitute.Core.Arguments; namespace Recyclarr.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(Action action) { return ArgumentMatcher.Enqueue(new AssertionMatcher(action)); } private sealed class AssertionMatcher(Action assertion) : IArgumentMatcher { 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; } } }