From 020cc1542079bd0f8dd1f02561989279a2677cec Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Fri, 18 Jul 2025 08:41:04 +0200 Subject: [PATCH 1/2] Correctly map the Pact Interaction Description property (#1331) * Correctly map the Pact Interaction Description property * Update src/WireMock.Net.Minimal/Serialization/PactMapper.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * post --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../Serialization/PactMapper.cs | 3 +- .../AdminApi/WireMockAdminApiTests.cs | 3 +- ..._And_Response_WithBodyAsJson.verified.json | 32 ++++++++++++++++++ ...Post_Request_WithDescription.verified.json | 20 +++++++++++ test/WireMock.Net.Tests/Pact/PactTests.cs | 33 +++++++++++++++++-- .../Pact/files/pact-get.json | 2 +- .../Pact/files/pact-multiple.json | 4 +-- .../Pact/files/pact-post.json | 20 +++++++++++ 8 files changed, 107 insertions(+), 10 deletions(-) create mode 100644 test/WireMock.Net.Tests/Pact/PactTests.SavePact_Get_Request_And_Response_WithBodyAsJson.verified.json create mode 100644 test/WireMock.Net.Tests/Pact/PactTests.SavePact_Post_Request_WithDescription.verified.json create mode 100644 test/WireMock.Net.Tests/Pact/files/pact-post.json diff --git a/src/WireMock.Net.Minimal/Serialization/PactMapper.cs b/src/WireMock.Net.Minimal/Serialization/PactMapper.cs index 05b35a71d..c500840d5 100644 --- a/src/WireMock.Net.Minimal/Serialization/PactMapper.cs +++ b/src/WireMock.Net.Minimal/Serialization/PactMapper.cs @@ -42,8 +42,7 @@ public static (string FileName, byte[] Bytes) ToPact(WireMockServer server, stri var interaction = new Interaction { - Description = mapping.Description, - ProviderState = mapping.Title, + Description = !string.IsNullOrWhiteSpace(mapping.Description) ? mapping.Description : mapping.Title ?? string.Empty, Request = MapRequest(mapping.Request, path), Response = MapResponse(mapping.Response) }; diff --git a/test/WireMock.Net.Tests/AdminApi/WireMockAdminApiTests.cs b/test/WireMock.Net.Tests/AdminApi/WireMockAdminApiTests.cs index f4eebe842..20aaea0b2 100644 --- a/test/WireMock.Net.Tests/AdminApi/WireMockAdminApiTests.cs +++ b/test/WireMock.Net.Tests/AdminApi/WireMockAdminApiTests.cs @@ -24,7 +24,6 @@ using WireMock.Handlers; using WireMock.Logging; using WireMock.Matchers; -using WireMock.Models; using WireMock.Net.Tests.VerifyExtensions; using WireMock.RequestBuilders; using WireMock.ResponseBuilders; @@ -185,7 +184,7 @@ public async Task IWireMockAdminApi_PutMappingAsync() server.Stop(); } - + [Fact] public async Task IWireMockAdminApi_FindRequestsAsync() diff --git a/test/WireMock.Net.Tests/Pact/PactTests.SavePact_Get_Request_And_Response_WithBodyAsJson.verified.json b/test/WireMock.Net.Tests/Pact/PactTests.SavePact_Get_Request_And_Response_WithBodyAsJson.verified.json new file mode 100644 index 000000000..393129ced --- /dev/null +++ b/test/WireMock.Net.Tests/Pact/PactTests.SavePact_Get_Request_And_Response_WithBodyAsJson.verified.json @@ -0,0 +1,32 @@ +{ + "consumer": { + "name": "Something API Consumer Get" + }, + "interactions": [ + { + "description": "A GET request to retrieve the something", + "request": { + "headers": { + "Accept": "application/json" + }, + "method": "GET", + "path": "/tester", + "query": "q1=test&q2=ok" + }, + "response": { + "body": { + "id": "tester", + "firstName": "Totally", + "lastName": "Awesome" + }, + "headers": { + "Content-Type": "application/json; charset=utf-8" + }, + "status": 200 + } + } + ], + "provider": { + "name": "Something API" + } +} \ No newline at end of file diff --git a/test/WireMock.Net.Tests/Pact/PactTests.SavePact_Post_Request_WithDescription.verified.json b/test/WireMock.Net.Tests/Pact/PactTests.SavePact_Post_Request_WithDescription.verified.json new file mode 100644 index 000000000..94c8ac2a9 --- /dev/null +++ b/test/WireMock.Net.Tests/Pact/PactTests.SavePact_Post_Request_WithDescription.verified.json @@ -0,0 +1,20 @@ +{ + "consumer": { + "name": "Default Consumer" + }, + "interactions": [ + { + "description": "A POST request to change something", + "request": { + "method": "POST", + "path": "/tester" + }, + "response": { + "status": 200 + } + } + ], + "provider": { + "name": "Default Provider" + } +} \ No newline at end of file diff --git a/test/WireMock.Net.Tests/Pact/PactTests.cs b/test/WireMock.Net.Tests/Pact/PactTests.cs index d0d4b30e5..08ef55dbe 100644 --- a/test/WireMock.Net.Tests/Pact/PactTests.cs +++ b/test/WireMock.Net.Tests/Pact/PactTests.cs @@ -1,11 +1,14 @@ +#if !(NET452 || NET461 || NETCOREAPP3_1) // Copyright © WireMock.Net using System.IO; using System.Net; using System.Text; +using System.Threading.Tasks; using FluentAssertions; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using VerifyXunit; using WireMock.Matchers; using WireMock.RequestBuilders; using WireMock.ResponseBuilders; @@ -14,10 +17,11 @@ namespace WireMock.Net.Tests.Pact; +[UsesVerify] public class PactTests { [Fact] - public void SavePact_Get_Request_And_Response_WithBodyAsJson() + public async Task SavePact_Get_Request_And_Response_WithBodyAsJson() { var server = WireMockServer.Start(); server @@ -46,12 +50,34 @@ public void SavePact_Get_Request_And_Response_WithBodyAsJson() var folder = Path.Combine("../../../", "Pact", "files"); var file = "pact-get.json"; + var path = Path.Combine(folder, file); // Act server.SavePact(folder, file); // Assert - File.ReadAllBytes(Path.Combine(folder, file)).Length.Should().BeGreaterThan(1); + await Verifier.VerifyFile(path); + } + + [Fact] + public async Task SavePact_Post_Request_WithDescription() + { + var server = WireMockServer.Start(); + server + .Given(Request.Create().UsingPost().WithPath("/tester")) + .WithTitle("POST something") + .WithDescription("A POST request to change something") + .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK)); + + var folder = Path.Combine("../../../", "Pact", "files"); + var file = "pact-post.json"; + var path = Path.Combine(folder, file); + + // Act + server.SavePact(folder, file); + + // Assert + await Verifier.VerifyFile(path); } [Fact] @@ -219,4 +245,5 @@ public void SavePact_Multiple_Requests() // Assert File.ReadAllBytes(Path.Combine(folder, file)).Length.Should().BeGreaterThan(1); } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/test/WireMock.Net.Tests/Pact/files/pact-get.json b/test/WireMock.Net.Tests/Pact/files/pact-get.json index 61a617f85..8593974c8 100644 --- a/test/WireMock.Net.Tests/Pact/files/pact-get.json +++ b/test/WireMock.Net.Tests/Pact/files/pact-get.json @@ -4,7 +4,7 @@ }, "interactions": [ { - "providerState": "A GET request to retrieve the something", + "description": "A GET request to retrieve the something", "request": { "headers": { "Accept": "application/json" diff --git a/test/WireMock.Net.Tests/Pact/files/pact-multiple.json b/test/WireMock.Net.Tests/Pact/files/pact-multiple.json index 5dc412674..0ccee6018 100644 --- a/test/WireMock.Net.Tests/Pact/files/pact-multiple.json +++ b/test/WireMock.Net.Tests/Pact/files/pact-multiple.json @@ -4,7 +4,7 @@ }, "interactions": [ { - "providerState": "A GET request to retrieve the something", + "description": "A GET request to retrieve the something", "request": { "headers": { "Accept": "application/json" @@ -26,7 +26,7 @@ } }, { - "providerState": "A Post request to add the something", + "description": "A Post request to add the something", "request": { "headers": { "Accept": "application/json" diff --git a/test/WireMock.Net.Tests/Pact/files/pact-post.json b/test/WireMock.Net.Tests/Pact/files/pact-post.json new file mode 100644 index 000000000..2af12b596 --- /dev/null +++ b/test/WireMock.Net.Tests/Pact/files/pact-post.json @@ -0,0 +1,20 @@ +{ + "consumer": { + "name": "Default Consumer" + }, + "interactions": [ + { + "description": "A POST request to change something", + "request": { + "method": "POST", + "path": "/tester" + }, + "response": { + "status": 200 + } + } + ], + "provider": { + "name": "Default Provider" + } +} \ No newline at end of file From fcc95ff06f2d83343b3d7f542a014b44da0a8249 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Fri, 18 Jul 2025 08:45:42 +0200 Subject: [PATCH 2/2] 1.8.15 --- CHANGELOG.md | 4 ++++ Directory.Build.props | 2 +- Generate-ReleaseNotes.cmd | 2 +- PackageReleaseNotes.txt | 9 +++------ 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b879f5832..52fa3ca6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 1.8.15 (18 July 2025) +- [#1331](https://github.com/wiremock/WireMock.Net/pull/1331) - Correctly map the Pact Interaction Description property [bug] contributed by [StefH](https://github.com/StefH) +- [#1330](https://github.com/wiremock/WireMock.Net/issues/1330) - Generated Pact-compatible consumer contract does not contain description [bug] + # 1.8.14 (13 July 2025) - [#1325](https://github.com/wiremock/WireMock.Net/pull/1325) - Add method CreateHttpClientFactory [feature] contributed by [StefH](https://github.com/StefH) - [#1326](https://github.com/wiremock/WireMock.Net/pull/1326) - Implement IMimeMessageData [feature] contributed by [StefH](https://github.com/StefH) diff --git a/Directory.Build.props b/Directory.Build.props index 16230321a..26507f262 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -4,7 +4,7 @@ - 1.8.14 + 1.8.15 WireMock.Net-Logo.png https://github.com/wiremock/WireMock.Net Apache-2.0 diff --git a/Generate-ReleaseNotes.cmd b/Generate-ReleaseNotes.cmd index 0220a3600..d17b7dbdd 100644 --- a/Generate-ReleaseNotes.cmd +++ b/Generate-ReleaseNotes.cmd @@ -1,6 +1,6 @@ rem https://github.com/StefH/GitHubReleaseNotes -SET version=1.8.14 +SET version=1.8.15 GitHubReleaseNotes --output CHANGELOG.md --skip-empty-releases --exclude-labels wontfix test question invalid doc duplicate example environment --version %version% --token %GH_TOKEN% diff --git a/PackageReleaseNotes.txt b/PackageReleaseNotes.txt index a2aa946dd..8ca638c79 100644 --- a/PackageReleaseNotes.txt +++ b/PackageReleaseNotes.txt @@ -1,8 +1,5 @@ -# 1.8.14 (13 July 2025) -- #1325 Add method CreateHttpClientFactory [feature] -- #1326 Implement IMimeMessageData [feature] -- #1329 Fix HandlebarsContext.ParseAndEvaluate [bug] -- #556 Support OData [wontfix] -- #1327 Response Body Does Not Evaluate Multiple Handlebars Templates [bug] +# 1.8.15 (18 July 2025) +- #1331 Correctly map the Pact Interaction Description property [bug] +- #1330 Generated Pact-compatible consumer contract does not contain description [bug] The full release notes can be found here: https://github.com/wiremock/WireMock.Net/blob/master/CHANGELOG.md \ No newline at end of file