Skip to content

Commit 020cc15

Browse files
StefHCopilot
andauthored
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 <[email protected]> * post --------- Co-authored-by: Copilot <[email protected]>
1 parent aeb1572 commit 020cc15

File tree

8 files changed

+107
-10
lines changed

8 files changed

+107
-10
lines changed

src/WireMock.Net.Minimal/Serialization/PactMapper.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ public static (string FileName, byte[] Bytes) ToPact(WireMockServer server, stri
4242

4343
var interaction = new Interaction
4444
{
45-
Description = mapping.Description,
46-
ProviderState = mapping.Title,
45+
Description = !string.IsNullOrWhiteSpace(mapping.Description) ? mapping.Description : mapping.Title ?? string.Empty,
4746
Request = MapRequest(mapping.Request, path),
4847
Response = MapResponse(mapping.Response)
4948
};

test/WireMock.Net.Tests/AdminApi/WireMockAdminApiTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
using WireMock.Handlers;
2525
using WireMock.Logging;
2626
using WireMock.Matchers;
27-
using WireMock.Models;
2827
using WireMock.Net.Tests.VerifyExtensions;
2928
using WireMock.RequestBuilders;
3029
using WireMock.ResponseBuilders;
@@ -185,7 +184,7 @@ public async Task IWireMockAdminApi_PutMappingAsync()
185184
server.Stop();
186185
}
187186

188-
187+
189188

190189
[Fact]
191190
public async Task IWireMockAdminApi_FindRequestsAsync()
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"consumer": {
3+
"name": "Something API Consumer Get"
4+
},
5+
"interactions": [
6+
{
7+
"description": "A GET request to retrieve the something",
8+
"request": {
9+
"headers": {
10+
"Accept": "application/json"
11+
},
12+
"method": "GET",
13+
"path": "/tester",
14+
"query": "q1=test&q2=ok"
15+
},
16+
"response": {
17+
"body": {
18+
"id": "tester",
19+
"firstName": "Totally",
20+
"lastName": "Awesome"
21+
},
22+
"headers": {
23+
"Content-Type": "application/json; charset=utf-8"
24+
},
25+
"status": 200
26+
}
27+
}
28+
],
29+
"provider": {
30+
"name": "Something API"
31+
}
32+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"consumer": {
3+
"name": "Default Consumer"
4+
},
5+
"interactions": [
6+
{
7+
"description": "A POST request to change something",
8+
"request": {
9+
"method": "POST",
10+
"path": "/tester"
11+
},
12+
"response": {
13+
"status": 200
14+
}
15+
}
16+
],
17+
"provider": {
18+
"name": "Default Provider"
19+
}
20+
}

test/WireMock.Net.Tests/Pact/PactTests.cs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
#if !(NET452 || NET461 || NETCOREAPP3_1)
12
// Copyright © WireMock.Net
23

34
using System.IO;
45
using System.Net;
56
using System.Text;
7+
using System.Threading.Tasks;
68
using FluentAssertions;
79
using Newtonsoft.Json;
810
using Newtonsoft.Json.Linq;
11+
using VerifyXunit;
912
using WireMock.Matchers;
1013
using WireMock.RequestBuilders;
1114
using WireMock.ResponseBuilders;
@@ -14,10 +17,11 @@
1417

1518
namespace WireMock.Net.Tests.Pact;
1619

20+
[UsesVerify]
1721
public class PactTests
1822
{
1923
[Fact]
20-
public void SavePact_Get_Request_And_Response_WithBodyAsJson()
24+
public async Task SavePact_Get_Request_And_Response_WithBodyAsJson()
2125
{
2226
var server = WireMockServer.Start();
2327
server
@@ -46,12 +50,34 @@ public void SavePact_Get_Request_And_Response_WithBodyAsJson()
4650

4751
var folder = Path.Combine("../../../", "Pact", "files");
4852
var file = "pact-get.json";
53+
var path = Path.Combine(folder, file);
4954

5055
// Act
5156
server.SavePact(folder, file);
5257

5358
// Assert
54-
File.ReadAllBytes(Path.Combine(folder, file)).Length.Should().BeGreaterThan(1);
59+
await Verifier.VerifyFile(path);
60+
}
61+
62+
[Fact]
63+
public async Task SavePact_Post_Request_WithDescription()
64+
{
65+
var server = WireMockServer.Start();
66+
server
67+
.Given(Request.Create().UsingPost().WithPath("/tester"))
68+
.WithTitle("POST something")
69+
.WithDescription("A POST request to change something")
70+
.RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK));
71+
72+
var folder = Path.Combine("../../../", "Pact", "files");
73+
var file = "pact-post.json";
74+
var path = Path.Combine(folder, file);
75+
76+
// Act
77+
server.SavePact(folder, file);
78+
79+
// Assert
80+
await Verifier.VerifyFile(path);
5581
}
5682

5783
[Fact]
@@ -219,4 +245,5 @@ public void SavePact_Multiple_Requests()
219245
// Assert
220246
File.ReadAllBytes(Path.Combine(folder, file)).Length.Should().BeGreaterThan(1);
221247
}
222-
}
248+
}
249+
#endif

test/WireMock.Net.Tests/Pact/files/pact-get.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
},
55
"interactions": [
66
{
7-
"providerState": "A GET request to retrieve the something",
7+
"description": "A GET request to retrieve the something",
88
"request": {
99
"headers": {
1010
"Accept": "application/json"

test/WireMock.Net.Tests/Pact/files/pact-multiple.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
},
55
"interactions": [
66
{
7-
"providerState": "A GET request to retrieve the something",
7+
"description": "A GET request to retrieve the something",
88
"request": {
99
"headers": {
1010
"Accept": "application/json"
@@ -26,7 +26,7 @@
2626
}
2727
},
2828
{
29-
"providerState": "A Post request to add the something",
29+
"description": "A Post request to add the something",
3030
"request": {
3131
"headers": {
3232
"Accept": "application/json"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"consumer": {
3+
"name": "Default Consumer"
4+
},
5+
"interactions": [
6+
{
7+
"description": "A POST request to change something",
8+
"request": {
9+
"method": "POST",
10+
"path": "/tester"
11+
},
12+
"response": {
13+
"status": 200
14+
}
15+
}
16+
],
17+
"provider": {
18+
"name": "Default Provider"
19+
}
20+
}

0 commit comments

Comments
 (0)