mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-22 08:48:46 +02:00
Add support for multiple webhooks (#615)
This commit is contained in:
@@ -16,6 +16,74 @@ namespace WireMock.Net.Tests
|
||||
{
|
||||
public class WireMockServerWebhookTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task WireMockServer_WithWebhooks_Should_Send_Message_To_Webhooks()
|
||||
{
|
||||
// Assign
|
||||
var serverReceivingTheWebhook1 = WireMockServer.Start();
|
||||
serverReceivingTheWebhook1.Given(Request.Create().UsingPost()).RespondWith(Response.Create().WithStatusCode(200));
|
||||
|
||||
var serverReceivingTheWebhook2 = WireMockServer.Start();
|
||||
serverReceivingTheWebhook2.Given(Request.Create().UsingPost()).RespondWith(Response.Create().WithStatusCode(200));
|
||||
|
||||
var webhook1 = new Webhook
|
||||
{
|
||||
Request = new WebhookRequest
|
||||
{
|
||||
Url = serverReceivingTheWebhook1.Urls[0],
|
||||
Method = "post",
|
||||
BodyData = new BodyData
|
||||
{
|
||||
BodyAsString = "1",
|
||||
DetectedBodyType = BodyType.String,
|
||||
DetectedBodyTypeFromContentType = BodyType.String
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var webhook2 = new Webhook
|
||||
{
|
||||
Request = new WebhookRequest
|
||||
{
|
||||
Url = serverReceivingTheWebhook2.Urls[0],
|
||||
Method = "post",
|
||||
BodyData = new BodyData
|
||||
{
|
||||
BodyAsString = "2",
|
||||
DetectedBodyType = BodyType.String,
|
||||
DetectedBodyTypeFromContentType = BodyType.String
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Act
|
||||
var server = WireMockServer.Start();
|
||||
server.Given(Request.Create().UsingPost())
|
||||
.WithWebhook(webhook1, webhook2)
|
||||
.RespondWith(Response.Create().WithBody("a-response"));
|
||||
|
||||
var request = new HttpRequestMessage
|
||||
{
|
||||
Method = HttpMethod.Post,
|
||||
RequestUri = new Uri($"{server.Urls[0]}/TST"),
|
||||
Content = new StringContent("test")
|
||||
};
|
||||
|
||||
// Assert
|
||||
var response = await new HttpClient().SendAsync(request);
|
||||
string content = await response.Content.ReadAsStringAsync();
|
||||
|
||||
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||
content.Should().Be("a-response");
|
||||
|
||||
serverReceivingTheWebhook1.LogEntries.Should().HaveCount(1);
|
||||
serverReceivingTheWebhook2.LogEntries.Should().HaveCount(1);
|
||||
|
||||
server.Dispose();
|
||||
serverReceivingTheWebhook1.Dispose();
|
||||
serverReceivingTheWebhook2.Dispose();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WireMockServer_WithWebhook_Should_Send_Message_To_Webhook()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user