Files
WireMock.Net-wiremock/test/WireMock.Net.Tests/Pact/PactTests.cs
Stef Heyenrath 5e301fd74b Swagger support (#749)
* r

* fix

* sw

* x

* s

* .

* .

* .

* CreateTypeFromJObject

* .

* .

* f

* c

* .

* .

* .

* .

* .

* .

* ok

* ,

* .

* .

* .

* .

* n

* pact

* fix

* schema

* null

* fluent

* r

* -p

* .

* .

* refs

* .
2022-05-13 22:01:46 +02:00

94 lines
3.1 KiB
C#

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")
.WithGuid("23e2aedb-166c-467b-b9f6-9b0817cb1636")
.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")
.WithGuid("f3f8abe7-7d1e-4518-afa1-d295ce7dadfd")
.RespondWith(
Response.Create()
.WithStatusCode(HttpStatusCode.RedirectMethod)
.WithBodyAsJson(new
{
Id = "1",
FirstName = "Totally"
})
);
server.SavePact(Path.Combine("../../../", "Pact", "files"), "pact-multiple.json");
}
}