diff --git a/src/WireMock.Net.Minimal/Serialization/PactMapper.cs b/src/WireMock.Net.Minimal/Serialization/PactMapper.cs index 05b35a71..c500840d 100644 --- a/src/WireMock.Net.Minimal/Serialization/PactMapper.cs +++ b/src/WireMock.Net.Minimal/Serialization/PactMapper.cs @@ -42,8 +42,7 @@ internal static class PactMapper 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 f4eebe84..20aaea0b 100644 --- a/test/WireMock.Net.Tests/AdminApi/WireMockAdminApiTests.cs +++ b/test/WireMock.Net.Tests/AdminApi/WireMockAdminApiTests.cs @@ -24,7 +24,6 @@ using WireMock.Client.Extensions; 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 partial class WireMockAdminApiTests 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 00000000..393129ce --- /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 00000000..94c8ac2a --- /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 d0d4b30e..08ef55db 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 @@ using Xunit; 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 class PactTests 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 class PactTests // 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 61a617f8..8593974c 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 5dc41267..0ccee601 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 00000000..2af12b59 --- /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