diff --git a/src/NServiceBus.IntegrationTesting.Tests/Approver.cs b/src/NServiceBus.IntegrationTesting.Tests/Approver.cs new file mode 100644 index 0000000..e4d579a --- /dev/null +++ b/src/NServiceBus.IntegrationTesting.Tests/Approver.cs @@ -0,0 +1,29 @@ +using System.Runtime.CompilerServices; +using NUnit.Framework; + +namespace NServiceBus.IntegrationTesting.Tests; + +static class Approver +{ + public static void Verify(string value, [CallerFilePath] string callerFilePath = "", [CallerMemberName] string callerMemberName = "") + { + var directory = Path.GetDirectoryName(callerFilePath)!; + var baseName = $"{Path.GetFileNameWithoutExtension(callerFilePath)}.{callerMemberName}"; + var approvedFile = Path.Combine(directory, $"{baseName}.approved.txt"); + var receivedFile = Path.Combine(directory, $"{baseName}.received.txt"); + + var received = Normalize(value); + var approved = File.Exists(approvedFile) ? Normalize(File.ReadAllText(approvedFile)) : null; + + if (received == approved) + { + File.Delete(receivedFile); + return; + } + + File.WriteAllText(receivedFile, received); + Assert.Fail($"Received value does not match '{approvedFile}'. If the change is expected, replace the approved file with '{receivedFile}'."); + } + + static string Normalize(string value) => value.Replace("\r\n", "\n").TrimEnd(); +} diff --git a/src/NServiceBus.IntegrationTesting.Tests/NServiceBus.IntegrationTesting.Tests.csproj b/src/NServiceBus.IntegrationTesting.Tests/NServiceBus.IntegrationTesting.Tests.csproj index 18a184f..ff30027 100644 --- a/src/NServiceBus.IntegrationTesting.Tests/NServiceBus.IntegrationTesting.Tests.csproj +++ b/src/NServiceBus.IntegrationTesting.Tests/NServiceBus.IntegrationTesting.Tests.csproj @@ -15,7 +15,6 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - diff --git a/src/NServiceBus.IntegrationTesting.Tests/PublicApiTests.MongoDb_PublicApi_matches_approved_snapshot.verified.txt b/src/NServiceBus.IntegrationTesting.Tests/PublicApiTests.MongoDb_PublicApi_matches_approved_snapshot.approved.txt similarity index 100% rename from src/NServiceBus.IntegrationTesting.Tests/PublicApiTests.MongoDb_PublicApi_matches_approved_snapshot.verified.txt rename to src/NServiceBus.IntegrationTesting.Tests/PublicApiTests.MongoDb_PublicApi_matches_approved_snapshot.approved.txt diff --git a/src/NServiceBus.IntegrationTesting.Tests/PublicApiTests.MySql_PublicApi_matches_approved_snapshot.verified.txt b/src/NServiceBus.IntegrationTesting.Tests/PublicApiTests.MySql_PublicApi_matches_approved_snapshot.approved.txt similarity index 100% rename from src/NServiceBus.IntegrationTesting.Tests/PublicApiTests.MySql_PublicApi_matches_approved_snapshot.verified.txt rename to src/NServiceBus.IntegrationTesting.Tests/PublicApiTests.MySql_PublicApi_matches_approved_snapshot.approved.txt diff --git a/src/NServiceBus.IntegrationTesting.Tests/PublicApiTests.PostgreSql_PublicApi_matches_approved_snapshot.verified.txt b/src/NServiceBus.IntegrationTesting.Tests/PublicApiTests.PostgreSql_PublicApi_matches_approved_snapshot.approved.txt similarity index 100% rename from src/NServiceBus.IntegrationTesting.Tests/PublicApiTests.PostgreSql_PublicApi_matches_approved_snapshot.verified.txt rename to src/NServiceBus.IntegrationTesting.Tests/PublicApiTests.PostgreSql_PublicApi_matches_approved_snapshot.approved.txt diff --git a/src/NServiceBus.IntegrationTesting.Tests/PublicApiTests.PublicApi_matches_approved_snapshot.verified.txt b/src/NServiceBus.IntegrationTesting.Tests/PublicApiTests.PublicApi_matches_approved_snapshot.approved.txt similarity index 100% rename from src/NServiceBus.IntegrationTesting.Tests/PublicApiTests.PublicApi_matches_approved_snapshot.verified.txt rename to src/NServiceBus.IntegrationTesting.Tests/PublicApiTests.PublicApi_matches_approved_snapshot.approved.txt diff --git a/src/NServiceBus.IntegrationTesting.Tests/PublicApiTests.RabbitMQ_PublicApi_matches_approved_snapshot.verified.txt b/src/NServiceBus.IntegrationTesting.Tests/PublicApiTests.RabbitMQ_PublicApi_matches_approved_snapshot.approved.txt similarity index 100% rename from src/NServiceBus.IntegrationTesting.Tests/PublicApiTests.RabbitMQ_PublicApi_matches_approved_snapshot.verified.txt rename to src/NServiceBus.IntegrationTesting.Tests/PublicApiTests.RabbitMQ_PublicApi_matches_approved_snapshot.approved.txt diff --git a/src/NServiceBus.IntegrationTesting.Tests/PublicApiTests.RavenDb_PublicApi_matches_approved_snapshot.verified.txt b/src/NServiceBus.IntegrationTesting.Tests/PublicApiTests.RavenDb_PublicApi_matches_approved_snapshot.approved.txt similarity index 100% rename from src/NServiceBus.IntegrationTesting.Tests/PublicApiTests.RavenDb_PublicApi_matches_approved_snapshot.verified.txt rename to src/NServiceBus.IntegrationTesting.Tests/PublicApiTests.RavenDb_PublicApi_matches_approved_snapshot.approved.txt diff --git a/src/NServiceBus.IntegrationTesting.Tests/PublicApiTests.SqlServer_PublicApi_matches_approved_snapshot.verified.txt b/src/NServiceBus.IntegrationTesting.Tests/PublicApiTests.SqlServer_PublicApi_matches_approved_snapshot.approved.txt similarity index 100% rename from src/NServiceBus.IntegrationTesting.Tests/PublicApiTests.SqlServer_PublicApi_matches_approved_snapshot.verified.txt rename to src/NServiceBus.IntegrationTesting.Tests/PublicApiTests.SqlServer_PublicApi_matches_approved_snapshot.approved.txt diff --git a/src/NServiceBus.IntegrationTesting.Tests/PublicApiTests.cs b/src/NServiceBus.IntegrationTesting.Tests/PublicApiTests.cs index eca727f..bfe9962 100644 --- a/src/NServiceBus.IntegrationTesting.Tests/PublicApiTests.cs +++ b/src/NServiceBus.IntegrationTesting.Tests/PublicApiTests.cs @@ -1,5 +1,5 @@ +using NUnit.Framework; using PublicApiGenerator; -using VerifyNUnit; namespace NServiceBus.IntegrationTesting.Tests; @@ -18,51 +18,51 @@ public class PublicApiTests }; [Test] - public Task PublicApi_matches_approved_snapshot() + public void PublicApi_matches_approved_snapshot() { var publicApi = typeof(TestEnvironment).Assembly.GeneratePublicApi(Options); - return Verifier.Verify(publicApi); + Approver.Verify(publicApi); } [Test] - public Task RabbitMQ_PublicApi_matches_approved_snapshot() + public void RabbitMQ_PublicApi_matches_approved_snapshot() { var publicApi = typeof(RabbitMqContainerOptions).Assembly.GeneratePublicApi(Options); - return Verifier.Verify(publicApi); + Approver.Verify(publicApi); } [Test] - public Task PostgreSql_PublicApi_matches_approved_snapshot() + public void PostgreSql_PublicApi_matches_approved_snapshot() { var publicApi = typeof(PostgreSqlContainerOptions).Assembly.GeneratePublicApi(Options); - return Verifier.Verify(publicApi); + Approver.Verify(publicApi); } [Test] - public Task MySql_PublicApi_matches_approved_snapshot() + public void MySql_PublicApi_matches_approved_snapshot() { var publicApi = typeof(MySqlContainerOptions).Assembly.GeneratePublicApi(Options); - return Verifier.Verify(publicApi); + Approver.Verify(publicApi); } [Test] - public Task MongoDb_PublicApi_matches_approved_snapshot() + public void MongoDb_PublicApi_matches_approved_snapshot() { var publicApi = typeof(MongoDbContainerOptions).Assembly.GeneratePublicApi(Options); - return Verifier.Verify(publicApi); + Approver.Verify(publicApi); } [Test] - public Task SqlServer_PublicApi_matches_approved_snapshot() + public void SqlServer_PublicApi_matches_approved_snapshot() { var publicApi = typeof(SqlServerContainerOptions).Assembly.GeneratePublicApi(Options); - return Verifier.Verify(publicApi); + Approver.Verify(publicApi); } [Test] - public Task RavenDb_PublicApi_matches_approved_snapshot() + public void RavenDb_PublicApi_matches_approved_snapshot() { var publicApi = typeof(RavenDbContainerOptions).Assembly.GeneratePublicApi(Options); - return Verifier.Verify(publicApi); + Approver.Verify(publicApi); } }