Add unit tests for AdminApiMappingBuilder (#1133)

This commit is contained in:
Stef Heyenrath
2024-07-08 21:41:05 +02:00
committed by GitHub
parent 780c233ef3
commit ecb8e620ed
2 changed files with 99 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
{
Guid: 53241df5-582c-458a-a67b-6de3d1d0508e,
UpdatedAt: DateTime_1,
Title: This is my title 1,
Request: {
Path: {
Matchers: [
{
Name: WildcardMatcher,
Pattern: /bla1,
IgnoreCase: false
}
]
},
Methods: [
POST
],
Body: {
Matcher: {
Name: JsonPartialMatcher,
Pattern: {
test: abc
},
IgnoreCase: false,
Regex: false
}
}
},
Response: {
Body: The Response
}
}

View File

@@ -0,0 +1,67 @@
#if !(NET452 || NET461 || NETCOREAPP3_1)
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading.Tasks;
using FluentAssertions;
using VerifyTests;
using VerifyXunit;
using WireMock.Client;
using WireMock.Client.Extensions;
using WireMock.Net.Tests.VerifyExtensions;
using WireMock.Server;
using Xunit;
namespace WireMock.Net.Tests.Client.Builders;
[ExcludeFromCodeCoverage]
[UsesVerify]
public class AdminApiMappingBuilderTests
{
private static readonly VerifySettings VerifySettings = new();
static AdminApiMappingBuilderTests()
{
VerifyNewtonsoftJson.Enable(VerifySettings);
}
[Fact]
public async Task GetMappingBuilder_BuildAndPostAsync()
{
using var server = WireMockServer.StartWithAdminInterface();
var api = RestEase.RestClient.For<IWireMockAdminApi>(server.Url!);
var guid = Guid.Parse("53241df5-582c-458a-a67b-6de3d1d0508e");
var mappingBuilder = api.GetMappingBuilder();
mappingBuilder.Given(m => m
.WithTitle("This is my title 1")
.WithGuid(guid)
.WithRequest(req => req
.UsingPost()
.WithPath("/bla1")
.WithBody(body => body
.WithMatcher(matcher => matcher
.WithName("JsonPartialMatcher")
.WithPattern(new { test = "abc" })
)
)
)
.WithResponse(rsp => rsp
.WithBody("The Response")
)
);
// Act
var status = await mappingBuilder.BuildAndPostAsync().ConfigureAwait(false);
// Assert
status.Status.Should().Be("Mapping added");
var getMappingResult = await api.GetMappingAsync(guid).ConfigureAwait(false);
await Verifier.Verify(getMappingResult, VerifySettings).DontScrubGuids();
server.Stop();
}
}
#endif