From 39e218e325f288886ea9e9298808e3877eed17e1 Mon Sep 17 00:00:00 2001 From: Jonas Nyrup Date: Mon, 9 Nov 2026 16:17:33 +0100 Subject: [PATCH] Replace Verify with plain DiffPlex This PR replaces the use of Verify.XunitV3 and Verify.DiffPlex with just DiffPlex. --- CONTRIBUTING.md | 2 +- Tests/Approval.Tests/ApiApproval.cs | 58 ++++++++++++++----- Tests/Approval.Tests/Approval.Tests.csproj | 3 +- .../FluentAssertions.Json/net47.verified.txt | 3 +- .../netstandard2.0.verified.txt | 3 +- 5 files changed, 51 insertions(+), 18 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b8a14f8c..68a405f7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,5 +5,5 @@ No open-source project is going to be successful without contributions. After we * The [Pull Request](https://help.github.com/articles/using-pull-requests) is targeted at the `master` branch. * The code complies with the [Coding Guidelines for C#](https://csharpcodingguidelines.com/). * The changes are covered by a new or existing set of unit tests which follow the Arrange-Act-Assert syntax such as is used [in this example](https://github.com/fluentassertions/fluentassertions/blob/daaf35b9b59b622c96d0c034e8972a020b2bee55/Tests/FluentAssertions.Shared.Specs/BasicEquivalencySpecs.cs#L33). -* If the contribution changes the public API, the changes needs to be included by running [`AcceptApiChanges.ps1`](https://github.com/fluentassertions/fluentassertions.json/tree/master/AcceptApiChanges.ps1)/[`AcceptApiChanges.sh`](https://github.com/fluentassertions/fluentassertions/tree/master/AcceptApiChanges.sh) or using Rider's [Verify Support](https://plugins.jetbrains.com/plugin/17240-verify-support) plug-in. +* If the contribution changes the public API, the changes needs to be included by running [`AcceptApiChanges.ps1`](https://github.com/fluentassertions/fluentassertions.json/tree/master/AcceptApiChanges.ps1)/[`AcceptApiChanges.sh`](https://github.com/fluentassertions/fluentassertions/tree/master/AcceptApiChanges.sh). * If the contribution affects the documentation, please update the [**readme.md**](https://github.com/fluentassertions/fluentassertions.json/tree/master/readme.md). diff --git a/Tests/Approval.Tests/ApiApproval.cs b/Tests/Approval.Tests/ApiApproval.cs index c5563905..f23ba348 100644 --- a/Tests/Approval.Tests/ApiApproval.cs +++ b/Tests/Approval.Tests/ApiApproval.cs @@ -2,36 +2,31 @@ using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; -using System.Threading.Tasks; +using System.Text; using System.Xml.Linq; using System.Xml.XPath; +using DiffPlex.DiffBuilder; +using DiffPlex.DiffBuilder.Model; using PublicApiGenerator; -using VerifyTests; -using VerifyTests.DiffPlex; -using VerifyXunit; using Xunit; namespace Approval.Tests; public class ApiApproval { - static ApiApproval() => VerifyDiffPlex.Initialize(OutputType.Minimal); - [Theory] [ClassData(typeof(TargetFrameworksTheoryData))] - public Task ApproveApi(string framework) + public void ApproveApi(string framework) { var configuration = typeof(ApiApproval).Assembly.GetCustomAttribute()!.Configuration; var assemblyFile = CombinedPaths("Src", "FluentAssertions.Json", "bin", configuration, framework, "FluentAssertions.Json.dll"); var assembly = Assembly.LoadFile(assemblyFile); var publicApi = assembly.GeneratePublicApi(options: null); + var expected = GetExpected(publicApi, framework); + + var diff = InlineDiffBuilder.Diff(expected, publicApi); - return Verifier - .Verify(publicApi) - .ScrubLinesContaining("FrameworkDisplayName") - .UseDirectory(Path.Combine("ApprovedApi", "FluentAssertions.Json")) - .UseFileName(framework) - .DisableDiff(); + Assert.False(diff.HasDifferences, StringifyDiff(diff)); } private class TargetFrameworksTheoryData : TheoryData @@ -50,4 +45,41 @@ private static string GetSolutionDirectory([CallerFilePath] string path = "") => private static string CombinedPaths(params string[] paths) => Path.GetFullPath(Path.Combine(paths.Prepend(GetSolutionDirectory()).ToArray())); + + private string GetExpected(string publicApi, string targetFramework, [CallerFilePath] string path = "") + { + var projectPath = Path.Combine(Path.GetDirectoryName(path)!, "ApprovedApi", "FluentAssertions.Json"); + var receivedPath = Path.Combine(projectPath, $"{targetFramework}.received.txt"); + var verifiedPath = Path.Combine(projectPath, $"{targetFramework}.verified.txt"); + + File.WriteAllText(receivedPath, publicApi); + return File.Exists(verifiedPath) ? File.ReadAllText(verifiedPath) : string.Empty; + } + + private static string StringifyDiff(DiffPaneModel diff) + { + var builder = new StringBuilder(); + if (diff.HasDifferences) + { + foreach (var line in diff.Lines) + { + switch (line.Type) + { + case ChangeType.Inserted: + builder.Append("+ "); + break; + case ChangeType.Deleted: + builder.Append("- "); + break; + default: + // omit unchanged files + continue; + } + + builder.AppendLine(line.Text); + } + } + + return builder.ToString(); + } } diff --git a/Tests/Approval.Tests/Approval.Tests.csproj b/Tests/Approval.Tests/Approval.Tests.csproj index d9b9ac45..90c14229 100644 --- a/Tests/Approval.Tests/Approval.Tests.csproj +++ b/Tests/Approval.Tests/Approval.Tests.csproj @@ -5,6 +5,7 @@ + @@ -13,8 +14,6 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - - diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions.Json/net47.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions.Json/net47.verified.txt index 0e2bec32..525549c3 100644 --- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions.Json/net47.verified.txt +++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions.Json/net47.verified.txt @@ -1,4 +1,5 @@ -[assembly: System.Reflection.AssemblyMetadata("RepositoryUrl", "https://github.com/fluentassertions/fluentassertions.json.git")] +[assembly: System.Reflection.AssemblyMetadata("RepositoryUrl", "https://github.com/fluentassertions/fluentassertions.json.git")] +[assembly: System.Runtime.Versioning.TargetFramework(".NETFramework,Version=v4.7", FrameworkDisplayName=".NET Framework 4.7")] namespace FluentAssertions.Json { public interface IJsonAssertionOptions diff --git a/Tests/Approval.Tests/ApprovedApi/FluentAssertions.Json/netstandard2.0.verified.txt b/Tests/Approval.Tests/ApprovedApi/FluentAssertions.Json/netstandard2.0.verified.txt index 0e2bec32..73d25231 100644 --- a/Tests/Approval.Tests/ApprovedApi/FluentAssertions.Json/netstandard2.0.verified.txt +++ b/Tests/Approval.Tests/ApprovedApi/FluentAssertions.Json/netstandard2.0.verified.txt @@ -1,4 +1,5 @@ -[assembly: System.Reflection.AssemblyMetadata("RepositoryUrl", "https://github.com/fluentassertions/fluentassertions.json.git")] +[assembly: System.Reflection.AssemblyMetadata("RepositoryUrl", "https://github.com/fluentassertions/fluentassertions.json.git")] +[assembly: System.Runtime.Versioning.TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName=".NET Standard 2.0")] namespace FluentAssertions.Json { public interface IJsonAssertionOptions