Files
WireMock.Net/test/WireMock.Net.Tests/Serialization/WebhookMapperTests.cs
Stef Heyenrath 770a670e53 Generate C# code from Mapping (#842)
* 1

* .

* v

* .

* .

* -

* b

* res b

* Fix UT

* .

* Verify

* v

* ...

* .

* .

* dir

* m
2023-01-24 16:45:47 +01:00

135 lines
3.5 KiB
C#

#if !(NET452 || NET461 || NETCOREAPP3_1)
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using VerifyTests;
using VerifyXunit;
using WireMock.Admin.Mappings;
using WireMock.Models;
using WireMock.Serialization;
using WireMock.Types;
using WireMock.Util;
using Xunit;
namespace WireMock.Net.Tests.Serialization;
[UsesVerify]
public class WebhookMapperTests
{
[ModuleInitializer]
public static void ModuleInitializer()
{
VerifierSettings.DontScrubGuids();
VerifierSettings.DontScrubDateTimes();
}
[Fact]
public Task WebhookMapper_Map_WebhookModel_BodyAsString_And_UseTransformerIsFalse()
{
// Assign
var model = new WebhookModel
{
Request = new WebhookRequestModel
{
Url = "https://localhost",
Method = "get",
Headers = new Dictionary<string, string>
{
{ "x", "y" }
},
Body = "test",
UseTransformer = false
}
};
var result = WebhookMapper.Map(model);
// Verify
return Verifier.Verify(result);
}
[Fact]
public Task WebhookMapper_Map_WebhookModel_BodyAsString_And_UseTransformerIsTrue()
{
// Assign
var model = new WebhookModel
{
Request = new WebhookRequestModel
{
Url = "https://localhost",
Method = "get",
Headers = new Dictionary<string, string>
{
{ "x", "y" }
},
Body = "test",
UseTransformer = true
}
};
var result = WebhookMapper.Map(model);
// Verify
return Verifier.Verify(result);
}
[Fact]
public Task WebhookMapper_Map_WebhookModel_BodyAsJson()
{
// Assign
var model = new WebhookModel
{
Request = new WebhookRequestModel
{
Url = "https://localhost",
Method = "get",
Headers = new Dictionary<string, string>
{
{ "x", "y" }
},
BodyAsJson = new { n = 12345 },
Delay = 4,
MinimumRandomDelay = 5,
MaximumRandomDelay = 6
},
};
var result = WebhookMapper.Map(model);
// Verify
return Verifier.Verify(result);
}
[Fact]
public Task WebhookMapper_Map_Webhook_To_Model()
{
// Assign
var webhook = new Webhook
{
Request = new WebhookRequest
{
Url = "https://localhost",
Method = "get",
Headers = new Dictionary<string, WireMockList<string>>
{
{ "x", new WireMockList<string>("y") }
},
BodyData = new BodyData
{
BodyAsJson = new { n = 12345 },
DetectedBodyType = BodyType.Json,
DetectedBodyTypeFromContentType = BodyType.Json
},
Delay = 4,
MinimumRandomDelay = 5,
MaximumRandomDelay = 6
}
};
var result = WebhookMapper.Map(webhook);
// Verify
return Verifier.Verify(result);
}
}
#endif