mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-11 03:37:11 +02:00
Initial support for converting the mappings to a Pact(flow) json file (#748)
* WithDescription * WithConsumer / WithProvider * x * . * . * . * . * fix * pact * nullable * ficx * . * fix
This commit is contained in:
92
test/WireMock.Net.Tests/Pact/PactTests.cs
Normal file
92
test/WireMock.Net.Tests/Pact/PactTests.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.ResponseBuilders;
|
||||
using WireMock.Server;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Pact;
|
||||
|
||||
public class PactTests
|
||||
{
|
||||
[Fact]
|
||||
public void SavePact_Get_Request()
|
||||
{
|
||||
var server = WireMockServer.Start();
|
||||
server
|
||||
.WithConsumer("Something API Consumer Get")
|
||||
.WithProvider("Something API")
|
||||
|
||||
.Given(Request.Create()
|
||||
.UsingGet()
|
||||
.WithPath("/tester")
|
||||
.WithParam("q1", "test")
|
||||
.WithParam("q2", "ok")
|
||||
.WithHeader("Accept", "application/json")
|
||||
)
|
||||
.WithTitle("A GET request to retrieve the something")
|
||||
.RespondWith(
|
||||
Response.Create()
|
||||
.WithStatusCode(HttpStatusCode.OK)
|
||||
.WithHeader("Content-Type", "application/json; charset=utf-8")
|
||||
.WithBodyAsJson(new
|
||||
{
|
||||
Id = "tester",
|
||||
FirstName = "Totally",
|
||||
LastName = "Awesome"
|
||||
})
|
||||
);
|
||||
|
||||
server.SavePact(Path.Combine("../../../", "Pact", "files"), "pact-get.json");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SavePact_Multiple_Requests()
|
||||
{
|
||||
var server = WireMockServer.Start();
|
||||
server
|
||||
.WithConsumer("Something API Consumer Multiple")
|
||||
.WithProvider("Something API")
|
||||
|
||||
.Given(Request.Create()
|
||||
.UsingPost()
|
||||
.WithPath("/tester")
|
||||
.WithParam("q1", "test")
|
||||
.WithParam("q2", "ok")
|
||||
.WithHeader("Accept", "application/json")
|
||||
)
|
||||
.WithTitle("A GET request to retrieve the something")
|
||||
.RespondWith(
|
||||
Response.Create()
|
||||
.WithStatusCode(HttpStatusCode.OK)
|
||||
.WithHeader("Content-Type", "application/json; charset=utf-8")
|
||||
.WithBodyAsJson(new
|
||||
{
|
||||
Id = "tester",
|
||||
FirstName = "Totally",
|
||||
LastName = "Awesome"
|
||||
})
|
||||
);
|
||||
|
||||
server
|
||||
.Given(Request.Create()
|
||||
.UsingPost()
|
||||
.WithPath("/add")
|
||||
.WithHeader("Accept", "application/json")
|
||||
.WithBody(new JsonMatcher("{ \"Id\" : \"1\", \"FirstName\" : \"Totally\" }"))
|
||||
)
|
||||
.WithTitle("A Post request to add the something")
|
||||
.RespondWith(
|
||||
Response.Create()
|
||||
.WithStatusCode(HttpStatusCode.RedirectMethod)
|
||||
.WithBodyAsJson(new
|
||||
{
|
||||
Id = "1",
|
||||
FirstName = "Totally"
|
||||
})
|
||||
);
|
||||
|
||||
server.SavePact(Path.Combine("../../../", "Pact", "files"), "pact-multiple.json");
|
||||
}
|
||||
}
|
||||
32
test/WireMock.Net.Tests/Pact/files/pact-get.json
Normal file
32
test/WireMock.Net.Tests/Pact/files/pact-get.json
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"Consumer": {
|
||||
"Name": "Something API Consumer Get"
|
||||
},
|
||||
"Interactions": [
|
||||
{
|
||||
"ProviderState": "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"
|
||||
}
|
||||
}
|
||||
50
test/WireMock.Net.Tests/Pact/files/pact-multiple.json
Normal file
50
test/WireMock.Net.Tests/Pact/files/pact-multiple.json
Normal file
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"Consumer": {
|
||||
"Name": "Something API Consumer Multiple"
|
||||
},
|
||||
"Interactions": [
|
||||
{
|
||||
"ProviderState": "A Post request to add the something",
|
||||
"Request": {
|
||||
"Headers": {
|
||||
"Accept": "application/json"
|
||||
},
|
||||
"Method": "POST",
|
||||
"Path": "/add",
|
||||
"Body": "{ \"Id\" : \"1\", \"FirstName\" : \"Totally\" }"
|
||||
},
|
||||
"Response": {
|
||||
"Body": {
|
||||
"Id": "1",
|
||||
"FirstName": "Totally"
|
||||
},
|
||||
"Status": 303
|
||||
}
|
||||
},
|
||||
{
|
||||
"ProviderState": "A GET request to retrieve the something",
|
||||
"Request": {
|
||||
"Headers": {
|
||||
"Accept": "application/json"
|
||||
},
|
||||
"Method": "POST",
|
||||
"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"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user