Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/WireMock.Net.Minimal/Serialization/PactMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
};
Expand Down
3 changes: 1 addition & 2 deletions test/WireMock.Net.Tests/AdminApi/WireMockAdminApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -185,7 +184,7 @@ public async Task IWireMockAdminApi_PutMappingAsync()
server.Stop();
}



[Fact]
public async Task IWireMockAdminApi_FindRequestsAsync()
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
33 changes: 30 additions & 3 deletions test/WireMock.Net.Tests/Pact/PactTests.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -219,4 +245,5 @@ public void SavePact_Multiple_Requests()
// Assert
File.ReadAllBytes(Path.Combine(folder, file)).Length.Should().BeGreaterThan(1);
}
}
}
#endif
2 changes: 1 addition & 1 deletion test/WireMock.Net.Tests/Pact/files/pact-get.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions test/WireMock.Net.Tests/Pact/files/pact-multiple.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
20 changes: 20 additions & 0 deletions test/WireMock.Net.Tests/Pact/files/pact-post.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
Loading