mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-18 07:24:34 +01: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:
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
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