mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-23 16:58:27 +02:00
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>
This commit is contained in:
@@ -42,8 +42,7 @@ internal static class PactMapper
|
|||||||
|
|
||||||
var interaction = new Interaction
|
var interaction = new Interaction
|
||||||
{
|
{
|
||||||
Description = mapping.Description,
|
Description = !string.IsNullOrWhiteSpace(mapping.Description) ? mapping.Description : mapping.Title ?? string.Empty,
|
||||||
ProviderState = mapping.Title,
|
|
||||||
Request = MapRequest(mapping.Request, path),
|
Request = MapRequest(mapping.Request, path),
|
||||||
Response = MapResponse(mapping.Response)
|
Response = MapResponse(mapping.Response)
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ using WireMock.Client.Extensions;
|
|||||||
using WireMock.Handlers;
|
using WireMock.Handlers;
|
||||||
using WireMock.Logging;
|
using WireMock.Logging;
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using WireMock.Models;
|
|
||||||
using WireMock.Net.Tests.VerifyExtensions;
|
using WireMock.Net.Tests.VerifyExtensions;
|
||||||
using WireMock.RequestBuilders;
|
using WireMock.RequestBuilders;
|
||||||
using WireMock.ResponseBuilders;
|
using WireMock.ResponseBuilders;
|
||||||
@@ -185,7 +184,7 @@ public partial class WireMockAdminApiTests
|
|||||||
server.Stop();
|
server.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task IWireMockAdminApi_FindRequestsAsync()
|
public async Task IWireMockAdminApi_FindRequestsAsync()
|
||||||
|
|||||||
@@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,14 @@
|
|||||||
|
#if !(NET452 || NET461 || NETCOREAPP3_1)
|
||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
using VerifyXunit;
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using WireMock.RequestBuilders;
|
using WireMock.RequestBuilders;
|
||||||
using WireMock.ResponseBuilders;
|
using WireMock.ResponseBuilders;
|
||||||
@@ -14,10 +17,11 @@ using Xunit;
|
|||||||
|
|
||||||
namespace WireMock.Net.Tests.Pact;
|
namespace WireMock.Net.Tests.Pact;
|
||||||
|
|
||||||
|
[UsesVerify]
|
||||||
public class PactTests
|
public class PactTests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public void SavePact_Get_Request_And_Response_WithBodyAsJson()
|
public async Task SavePact_Get_Request_And_Response_WithBodyAsJson()
|
||||||
{
|
{
|
||||||
var server = WireMockServer.Start();
|
var server = WireMockServer.Start();
|
||||||
server
|
server
|
||||||
@@ -46,12 +50,34 @@ public class PactTests
|
|||||||
|
|
||||||
var folder = Path.Combine("../../../", "Pact", "files");
|
var folder = Path.Combine("../../../", "Pact", "files");
|
||||||
var file = "pact-get.json";
|
var file = "pact-get.json";
|
||||||
|
var path = Path.Combine(folder, file);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
server.SavePact(folder, file);
|
server.SavePact(folder, file);
|
||||||
|
|
||||||
// Assert
|
// 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]
|
[Fact]
|
||||||
@@ -219,4 +245,5 @@ public class PactTests
|
|||||||
// Assert
|
// Assert
|
||||||
File.ReadAllBytes(Path.Combine(folder, file)).Length.Should().BeGreaterThan(1);
|
File.ReadAllBytes(Path.Combine(folder, file)).Length.Should().BeGreaterThan(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
},
|
},
|
||||||
"interactions": [
|
"interactions": [
|
||||||
{
|
{
|
||||||
"providerState": "A GET request to retrieve the something",
|
"description": "A GET request to retrieve the something",
|
||||||
"request": {
|
"request": {
|
||||||
"headers": {
|
"headers": {
|
||||||
"Accept": "application/json"
|
"Accept": "application/json"
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
},
|
},
|
||||||
"interactions": [
|
"interactions": [
|
||||||
{
|
{
|
||||||
"providerState": "A GET request to retrieve the something",
|
"description": "A GET request to retrieve the something",
|
||||||
"request": {
|
"request": {
|
||||||
"headers": {
|
"headers": {
|
||||||
"Accept": "application/json"
|
"Accept": "application/json"
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"providerState": "A Post request to add the something",
|
"description": "A Post request to add the something",
|
||||||
"request": {
|
"request": {
|
||||||
"headers": {
|
"headers": {
|
||||||
"Accept": "application/json"
|
"Accept": "application/json"
|
||||||
|
|||||||
20
test/WireMock.Net.Tests/Pact/files/pact-post.json
Normal file
20
test/WireMock.Net.Tests/Pact/files/pact-post.json
Normal file
@@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user