From ecb8e620ed4f3511ccd4cb9a7fd45cc34ca38072 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Mon, 8 Jul 2024 21:41:05 +0200 Subject: [PATCH] Add unit tests for AdminApiMappingBuilder (#1133) --- ...pingBuilder_BuildAndPostAsync.verified.txt | 32 +++++++++ .../Builders/AdminApiMappingBuilderTests.cs | 67 +++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 test/WireMock.Net.Tests/Client/Builders/AdminApiMappingBuilderTests.GetMappingBuilder_BuildAndPostAsync.verified.txt create mode 100644 test/WireMock.Net.Tests/Client/Builders/AdminApiMappingBuilderTests.cs diff --git a/test/WireMock.Net.Tests/Client/Builders/AdminApiMappingBuilderTests.GetMappingBuilder_BuildAndPostAsync.verified.txt b/test/WireMock.Net.Tests/Client/Builders/AdminApiMappingBuilderTests.GetMappingBuilder_BuildAndPostAsync.verified.txt new file mode 100644 index 00000000..0fd8bce2 --- /dev/null +++ b/test/WireMock.Net.Tests/Client/Builders/AdminApiMappingBuilderTests.GetMappingBuilder_BuildAndPostAsync.verified.txt @@ -0,0 +1,32 @@ +{ + Guid: 53241df5-582c-458a-a67b-6de3d1d0508e, + UpdatedAt: DateTime_1, + Title: This is my title 1, + Request: { + Path: { + Matchers: [ + { + Name: WildcardMatcher, + Pattern: /bla1, + IgnoreCase: false + } + ] + }, + Methods: [ + POST + ], + Body: { + Matcher: { + Name: JsonPartialMatcher, + Pattern: { + test: abc + }, + IgnoreCase: false, + Regex: false + } + } + }, + Response: { + Body: The Response + } +} \ No newline at end of file diff --git a/test/WireMock.Net.Tests/Client/Builders/AdminApiMappingBuilderTests.cs b/test/WireMock.Net.Tests/Client/Builders/AdminApiMappingBuilderTests.cs new file mode 100644 index 00000000..5679f662 --- /dev/null +++ b/test/WireMock.Net.Tests/Client/Builders/AdminApiMappingBuilderTests.cs @@ -0,0 +1,67 @@ +#if !(NET452 || NET461 || NETCOREAPP3_1) +using System; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +using System.Threading.Tasks; +using FluentAssertions; +using VerifyTests; +using VerifyXunit; +using WireMock.Client; +using WireMock.Client.Extensions; +using WireMock.Net.Tests.VerifyExtensions; +using WireMock.Server; +using Xunit; + +namespace WireMock.Net.Tests.Client.Builders; + +[ExcludeFromCodeCoverage] +[UsesVerify] +public class AdminApiMappingBuilderTests +{ + private static readonly VerifySettings VerifySettings = new(); + static AdminApiMappingBuilderTests() + { + VerifyNewtonsoftJson.Enable(VerifySettings); + } + + [Fact] + public async Task GetMappingBuilder_BuildAndPostAsync() + { + using var server = WireMockServer.StartWithAdminInterface(); + + var api = RestEase.RestClient.For(server.Url!); + + var guid = Guid.Parse("53241df5-582c-458a-a67b-6de3d1d0508e"); + var mappingBuilder = api.GetMappingBuilder(); + mappingBuilder.Given(m => m + .WithTitle("This is my title 1") + .WithGuid(guid) + .WithRequest(req => req + .UsingPost() + .WithPath("/bla1") + .WithBody(body => body + .WithMatcher(matcher => matcher + .WithName("JsonPartialMatcher") + .WithPattern(new { test = "abc" }) + ) + ) + ) + .WithResponse(rsp => rsp + .WithBody("The Response") + ) + ); + + // Act + var status = await mappingBuilder.BuildAndPostAsync().ConfigureAwait(false); + + // Assert + status.Status.Should().Be("Mapping added"); + + var getMappingResult = await api.GetMappingAsync(guid).ConfigureAwait(false); + + await Verifier.Verify(getMappingResult, VerifySettings).DontScrubGuids(); + + server.Stop(); + } +} +#endif \ No newline at end of file