mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-23 01:29:05 +01:00
Update REST Admin interface to support "Get Mapping(s) as C# Code" (#878)
* Add /__admin/mappings/code endpoint * api * fix * . * fix * . * . * .
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[
|
||||
{
|
||||
Guid: 41372914-1838-4c67-916b-b9aacdd096ce,
|
||||
Guid: Guid_1,
|
||||
UpdatedAt: 2023-01-14 15:16:17,
|
||||
Request: {
|
||||
Path: {
|
||||
@@ -19,7 +19,6 @@
|
||||
Response: {
|
||||
BodyDestination: SameAsSource,
|
||||
Body: { msg: "Hello world!"}
|
||||
},
|
||||
UseWebhooksFireAndForget: false
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -1,6 +1,6 @@
|
||||
[
|
||||
{
|
||||
Guid: 41372914-1838-4c67-916b-b9aacdd096ce,
|
||||
Guid: Guid_1,
|
||||
UpdatedAt: 2023-01-14T15:16:17,
|
||||
Request: {
|
||||
Path: {
|
||||
@@ -19,7 +19,6 @@
|
||||
Response: {
|
||||
BodyDestination: SameAsSource,
|
||||
Body: { msg: "Hello world!"}
|
||||
},
|
||||
UseWebhooksFireAndForget: false
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -1,12 +1,12 @@
|
||||
#if !(NET452 || NET461 || NETCOREAPP3_1)
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
using Moq;
|
||||
using VerifyTests;
|
||||
using VerifyXunit;
|
||||
using WireMock.Handlers;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Net.Tests.VerifyExtensions;
|
||||
using WireMock.Owin;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.ResponseBuilders;
|
||||
@@ -20,6 +20,12 @@ namespace WireMock.Net.Tests;
|
||||
[UsesVerify]
|
||||
public class MappingBuilderTests
|
||||
{
|
||||
private static readonly VerifySettings VerifySettings = new();
|
||||
static MappingBuilderTests()
|
||||
{
|
||||
VerifySettings.Init();
|
||||
}
|
||||
|
||||
private static readonly Guid NewGuid = new("98fae52e-76df-47d9-876f-2ee32e931d9b");
|
||||
private const string MappingGuid = "41372914-1838-4c67-916b-b9aacdd096ce";
|
||||
private static readonly DateTime UtcNow = new(2023, 1, 14, 15, 16, 17);
|
||||
@@ -67,13 +73,6 @@ public class MappingBuilderTests
|
||||
);
|
||||
}
|
||||
|
||||
[ModuleInitializer]
|
||||
public static void ModuleInitializer()
|
||||
{
|
||||
VerifierSettings.DontScrubGuids();
|
||||
VerifierSettings.DontScrubDateTimes();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public Task GetMappings()
|
||||
{
|
||||
@@ -81,7 +80,7 @@ public class MappingBuilderTests
|
||||
var mappings = _sut.GetMappings();
|
||||
|
||||
// Verify
|
||||
return Verifier.Verify(mappings);
|
||||
return Verifier.Verify(mappings, VerifySettings);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -91,7 +90,7 @@ public class MappingBuilderTests
|
||||
var json = _sut.ToJson();
|
||||
|
||||
// Verify
|
||||
return Verifier.VerifyJson(json);
|
||||
return Verifier.VerifyJson(json, VerifySettings);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -20,7 +20,7 @@ public class LogEntryMapperTests
|
||||
private static readonly VerifySettings VerifySettings = new();
|
||||
static LogEntryMapperTests()
|
||||
{
|
||||
VerifySettings.Init<LogEntryMapperTests>();
|
||||
VerifySettings.Init();
|
||||
}
|
||||
|
||||
private readonly IWireMockMiddlewareOptions _options = new WireMockMiddlewareOptions();
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#if !(NET452 || NET461 || NETCOREAPP3_1)
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using VerifyTests;
|
||||
using VerifyXunit;
|
||||
using WireMock.Net.Tests.VerifyExtensions;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.ResponseBuilders;
|
||||
using WireMock.Serialization;
|
||||
@@ -16,12 +16,10 @@ namespace WireMock.Net.Tests.Serialization;
|
||||
[UsesVerify]
|
||||
public partial class MappingConverterTests
|
||||
{
|
||||
|
||||
[ModuleInitializer]
|
||||
public static void ModuleInitializer()
|
||||
private static readonly VerifySettings VerifySettings = new();
|
||||
static MappingConverterTests()
|
||||
{
|
||||
VerifierSettings.DontScrubGuids();
|
||||
VerifierSettings.DontScrubDateTimes();
|
||||
VerifySettings.Init();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -41,7 +39,7 @@ public partial class MappingConverterTests
|
||||
code.Should().NotBeEmpty();
|
||||
|
||||
// Verify
|
||||
return Verifier.Verify(code);
|
||||
return Verifier.Verify(code, VerifySettings);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -61,7 +59,7 @@ public partial class MappingConverterTests
|
||||
code.Should().NotBeEmpty();
|
||||
|
||||
// Verify
|
||||
return Verifier.Verify(code);
|
||||
return Verifier.Verify(code, VerifySettings);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -81,7 +79,7 @@ public partial class MappingConverterTests
|
||||
code.Should().NotBeEmpty();
|
||||
|
||||
// Verify
|
||||
return Verifier.Verify(code);
|
||||
return Verifier.Verify(code, VerifySettings);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -101,7 +99,7 @@ public partial class MappingConverterTests
|
||||
code.Should().NotBeEmpty();
|
||||
|
||||
// Verify
|
||||
return Verifier.Verify(code);
|
||||
return Verifier.Verify(code, VerifySettings);
|
||||
}
|
||||
|
||||
private Mapping CreateMapping()
|
||||
|
||||
@@ -1,12 +1 @@
|
||||
{
|
||||
Guid: c8eeaf99-d5c4-4341-8543-4597c3fd40d9,
|
||||
UpdatedAt: 2022-12-04 11:12:13,
|
||||
Title: ,
|
||||
Description: ,
|
||||
Priority: 42,
|
||||
Request: {},
|
||||
Response: {
|
||||
Delay: 1000
|
||||
},
|
||||
UseWebhooksFireAndForget: false
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
Guid: Guid_1,
|
||||
UpdatedAt: DateTime_1,
|
||||
Title: ,
|
||||
Description: ,
|
||||
Priority: 42,
|
||||
Request: {},
|
||||
Response: {
|
||||
Delay: 1000
|
||||
},
|
||||
UseWebhooksFireAndForget: false
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
Guid: c8eeaf99-d5c4-4341-8543-4597c3fd40d9,
|
||||
UpdatedAt: 2022-12-04 11:12:13,
|
||||
Guid: Guid_1,
|
||||
UpdatedAt: DateTime_1,
|
||||
Title: ,
|
||||
Description: ,
|
||||
Priority: 42,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
Guid: c8eeaf99-d5c4-4341-8543-4597c3fd40d9,
|
||||
UpdatedAt: 2022-12-04 11:12:13,
|
||||
Guid: Guid_1,
|
||||
UpdatedAt: DateTime_1,
|
||||
Title: ,
|
||||
Description: ,
|
||||
Priority: 42,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
Guid: c8eeaf99-d5c4-4341-8543-4597c3fd40d9,
|
||||
UpdatedAt: 2022-12-04 11:12:13,
|
||||
{
|
||||
Guid: Guid_1,
|
||||
UpdatedAt: DateTime_1,
|
||||
Title: ,
|
||||
Description: ,
|
||||
Priority: 42,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
Guid: c8eeaf99-d5c4-4341-8543-4597c3fd40d9,
|
||||
Guid: Guid_1,
|
||||
UpdatedAt: 2022-12-04 11:12:13,
|
||||
TimeSettings: {
|
||||
Start: 2023-01-14 15:16:17,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
Guid: c8eeaf99-d5c4-4341-8543-4597c3fd40d9,
|
||||
UpdatedAt: 2022-12-04 11:12:13,
|
||||
Guid: Guid_1,
|
||||
UpdatedAt: DateTime_1,
|
||||
Title: my-title,
|
||||
Description: my-description,
|
||||
Request: {},
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
Guid: c8eeaf99-d5c4-4341-8543-4597c3fd40d9,
|
||||
UpdatedAt: 2022-12-04 11:12:13,
|
||||
Guid: Guid_1,
|
||||
UpdatedAt: DateTime_1,
|
||||
Title: ,
|
||||
Description: ,
|
||||
Request: {},
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
Guid: c8eeaf99-d5c4-4341-8543-4597c3fd40d9,
|
||||
UpdatedAt: 2022-12-04 11:12:13,
|
||||
Guid: Guid_1,
|
||||
UpdatedAt: DateTime_1,
|
||||
Title: ,
|
||||
Description: ,
|
||||
Request: {},
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
#if !(NET452 || NET461 || NETCOREAPP3_1)
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using VerifyTests;
|
||||
using VerifyXunit;
|
||||
using WireMock.Models;
|
||||
using WireMock.RequestBuilders;
|
||||
@@ -232,7 +230,7 @@ public partial class MappingConverterTests
|
||||
model.TimeSettings.TTL.Should().Be(ttl);
|
||||
|
||||
// Verify
|
||||
return Verifier.Verify(model);
|
||||
return Verifier.Verify(model, VerifySettings);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -262,7 +260,7 @@ public partial class MappingConverterTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public Task ToMappingModel_WithDelayAsMilleSeconds_ReturnsCorrectModel()
|
||||
public Task ToMappingModel_WithDelayAsMilliSeconds_ReturnsCorrectModel()
|
||||
{
|
||||
// Assign
|
||||
var delay = 1000;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
Guid: ff55ac0a-fea9-4d7b-be74-5e483a2c1305,
|
||||
{
|
||||
Guid: Guid_1,
|
||||
UpdatedAt: 2022-12-04,
|
||||
Title: my title,
|
||||
Description: my description,
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#if !(NET452 || NET461 || NETCOREAPP3_1)
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
using Moq;
|
||||
using VerifyTests;
|
||||
using VerifyXunit;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Net.Tests.VerifyExtensions;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.Serialization;
|
||||
using WireMock.Settings;
|
||||
@@ -17,6 +17,12 @@ namespace WireMock.Net.Tests.Serialization;
|
||||
[UsesVerify]
|
||||
public class ProxyMappingConverterTests
|
||||
{
|
||||
private static readonly VerifySettings VerifySettings = new();
|
||||
static ProxyMappingConverterTests()
|
||||
{
|
||||
VerifySettings.Init();
|
||||
}
|
||||
|
||||
private readonly WireMockServerSettings _settings = new();
|
||||
|
||||
private readonly MappingConverter _mappingConverter;
|
||||
@@ -36,13 +42,6 @@ public class ProxyMappingConverterTests
|
||||
_sut = new ProxyMappingConverter(_settings, guidUtilsMock.Object, dateTimeUtilsMock.Object);
|
||||
}
|
||||
|
||||
[ModuleInitializer]
|
||||
public static void ModuleInitializer()
|
||||
{
|
||||
VerifierSettings.DontScrubGuids();
|
||||
VerifierSettings.DontScrubDateTimes();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public Task ToMapping_UseDefinedRequestMatchers_True()
|
||||
{
|
||||
@@ -77,7 +76,7 @@ public class ProxyMappingConverterTests
|
||||
var model = _mappingConverter.ToMappingModel(proxyMapping);
|
||||
|
||||
// Verify
|
||||
return Verifier.Verify(model);
|
||||
return Verifier.Verify(model, VerifySettings);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +1,11 @@
|
||||
#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.Net.Tests.VerifyExtensions;
|
||||
using WireMock.Serialization;
|
||||
using WireMock.Types;
|
||||
using WireMock.Util;
|
||||
@@ -16,11 +16,10 @@ namespace WireMock.Net.Tests.Serialization;
|
||||
[UsesVerify]
|
||||
public class WebhookMapperTests
|
||||
{
|
||||
[ModuleInitializer]
|
||||
public static void ModuleInitializer()
|
||||
private static readonly VerifySettings VerifySettings = new();
|
||||
static WebhookMapperTests()
|
||||
{
|
||||
VerifierSettings.DontScrubGuids();
|
||||
VerifierSettings.DontScrubDateTimes();
|
||||
VerifySettings.Init();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -45,7 +44,7 @@ public class WebhookMapperTests
|
||||
var result = WebhookMapper.Map(model);
|
||||
|
||||
// Verify
|
||||
return Verifier.Verify(result);
|
||||
return Verifier.Verify(result, VerifySettings);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -70,7 +69,7 @@ public class WebhookMapperTests
|
||||
var result = WebhookMapper.Map(model);
|
||||
|
||||
// Verify
|
||||
return Verifier.Verify(result);
|
||||
return Verifier.Verify(result, VerifySettings);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -97,7 +96,7 @@ public class WebhookMapperTests
|
||||
var result = WebhookMapper.Map(model);
|
||||
|
||||
// Verify
|
||||
return Verifier.Verify(result);
|
||||
return Verifier.Verify(result, VerifySettings);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -129,7 +128,7 @@ public class WebhookMapperTests
|
||||
var result = WebhookMapper.Map(webhook);
|
||||
|
||||
// Verify
|
||||
return Verifier.Verify(result);
|
||||
return Verifier.Verify(result, VerifySettings);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,42 @@
|
||||
#if !(NET452 || NET461)
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using VerifyTests;
|
||||
|
||||
namespace WireMock.Net.Tests.VerifyExtensions;
|
||||
|
||||
internal static class VerifyNewtonsoftJson
|
||||
{
|
||||
public static void Enable(VerifySettings verifySettings)
|
||||
{
|
||||
// InnerVerifier.ThrowIfVerifyHasBeenRun();
|
||||
|
||||
verifySettings
|
||||
.AddExtraSettings(_ =>
|
||||
{
|
||||
var converters = _.Converters;
|
||||
converters.Add(new JArrayConverter());
|
||||
converters.Add(new JObjectConverter());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
internal class JArrayConverter : WriteOnlyJsonConverter<JArray>
|
||||
{
|
||||
public override void Write(VerifyJsonWriter writer, JArray value)
|
||||
{
|
||||
var list = value.ToObject<List<object>>()!;
|
||||
writer.Serialize(list);
|
||||
}
|
||||
}
|
||||
|
||||
internal class JObjectConverter : WriteOnlyJsonConverter<JObject>
|
||||
{
|
||||
public override void Write(VerifyJsonWriter writer, JObject value)
|
||||
{
|
||||
var dictionary = value.ToObject<OrderedDictionary>()!;
|
||||
writer.Serialize(dictionary);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -5,11 +5,13 @@ namespace WireMock.Net.Tests.VerifyExtensions;
|
||||
|
||||
internal static class VerifySettingsExtensions
|
||||
{
|
||||
public static void Init<T>(this VerifySettings verifySettings)
|
||||
public static void Init(this VerifySettings verifySettings)
|
||||
{
|
||||
verifySettings.DontScrubDateTimes();
|
||||
verifySettings.DontScrubDateTimes();
|
||||
verifySettings.UseDirectory($"{typeof(T).Name}.Verify");
|
||||
// verifySettings.UseDirectory($"{typeof(T).Name}.Verify");
|
||||
|
||||
VerifyNewtonsoftJson.Enable(verifySettings);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -61,7 +61,7 @@
|
||||
<PackageReference Include="Moq" Version="4.17.2" />
|
||||
<PackageReference Include="System.Threading" Version="4.3.0" />
|
||||
<PackageReference Include="RestEase" Version="1.5.7" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
|
||||
<PackageReference Include="NFluent" Version="2.8.0" />
|
||||
<PackageReference Include="SimMetrics.Net" Version="1.0.5" />
|
||||
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.2.23" />
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
Guid: 90356dba-b36c-469a-a17e-669cd84f1f05,
|
||||
UpdatedAt: DateTime_1,
|
||||
Request: {
|
||||
Path: {
|
||||
Matchers: [
|
||||
{
|
||||
Name: WildcardMatcher,
|
||||
Pattern: /1,
|
||||
IgnoreCase: false
|
||||
}
|
||||
]
|
||||
},
|
||||
Body: {
|
||||
Matcher: {
|
||||
Name: RegexMatcher,
|
||||
Pattern: hello,
|
||||
IgnoreCase: true
|
||||
}
|
||||
}
|
||||
},
|
||||
Response: {
|
||||
Body: world
|
||||
},
|
||||
UseWebhooksFireAndForget: false
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
Guid: 90356dba-b36c-469a-a17e-669cd84f1f05,
|
||||
UpdatedAt: DateTime_1,
|
||||
Request: {
|
||||
Path: {
|
||||
Matchers: [
|
||||
{
|
||||
Name: WildcardMatcher,
|
||||
Pattern: /foo1,
|
||||
IgnoreCase: false
|
||||
}
|
||||
]
|
||||
},
|
||||
Methods: [
|
||||
GET
|
||||
],
|
||||
Params: [
|
||||
{
|
||||
Name: p1,
|
||||
Matchers: [
|
||||
{
|
||||
Name: ExactMatcher,
|
||||
Pattern: xyz,
|
||||
IgnoreCase: false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
Response: {
|
||||
StatusCode: 200,
|
||||
BodyDestination: SameAsSource,
|
||||
Body: 1
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
var server = WireMockServer.Start();
|
||||
server
|
||||
.Given(Request.Create()
|
||||
.UsingMethod("GET")
|
||||
.WithPath("/foo1")
|
||||
.WithParam("p1", "xyz")
|
||||
)
|
||||
.WithGuid("90356dba-b36c-469a-a17e-669cd84f1f05")
|
||||
.RespondWith(Response.Create()
|
||||
.WithBody("1")
|
||||
);
|
||||
@@ -0,0 +1,24 @@
|
||||
var server = WireMockServer.Start();
|
||||
server
|
||||
.Given(Request.Create()
|
||||
.UsingMethod("GET")
|
||||
.WithPath("/foo1")
|
||||
.WithParam("p1", "xyz")
|
||||
)
|
||||
.WithGuid("90356dba-b36c-469a-a17e-669cd84f1f05")
|
||||
.RespondWith(Response.Create()
|
||||
.WithBody("1")
|
||||
);
|
||||
|
||||
server
|
||||
.Given(Request.Create()
|
||||
.UsingMethod("GET")
|
||||
.WithPath("/foo2")
|
||||
.WithParam("p2", "abc")
|
||||
)
|
||||
.WithGuid("1b731398-4a5b-457f-a6e3-d65e541c428f")
|
||||
.RespondWith(Response.Create()
|
||||
.WithHeader("hk)", "hv")
|
||||
.WithBody("2")
|
||||
);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#if !NET452 && !NET461
|
||||
#if !(NET452 || NET461 || NETCOREAPP3_1)
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
@@ -9,20 +9,32 @@ using FluentAssertions;
|
||||
using Moq;
|
||||
using NFluent;
|
||||
using RestEase;
|
||||
using VerifyTests;
|
||||
using VerifyXunit;
|
||||
using WireMock.Admin.Mappings;
|
||||
using WireMock.Admin.Settings;
|
||||
using WireMock.Client;
|
||||
using WireMock.Handlers;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Models;
|
||||
using WireMock.Net.Tests.VerifyExtensions;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.ResponseBuilders;
|
||||
using WireMock.Server;
|
||||
using WireMock.Settings;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests;
|
||||
|
||||
[UsesVerify]
|
||||
public class WireMockAdminApiTests
|
||||
{
|
||||
private static readonly VerifySettings VerifySettings = new();
|
||||
static WireMockAdminApiTests()
|
||||
{
|
||||
VerifyNewtonsoftJson.Enable(VerifySettings);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task IWireMockAdminApi_GetSettingsAsync()
|
||||
{
|
||||
@@ -298,9 +310,9 @@ public class WireMockAdminApiTests
|
||||
public async Task IWireMockAdminApi_GetMappingAsync_WithBodyModelMatcherModel_WithoutMethods_ShouldReturnCorrectMappingModel()
|
||||
{
|
||||
// Arrange
|
||||
var guid = Guid.NewGuid();
|
||||
var guid = Guid.Parse("90356dba-b36c-469a-a17e-669cd84f1f05");
|
||||
var server = WireMockServer.StartWithAdminInterface();
|
||||
var api = RestClient.For<IWireMockAdminApi>(server.Urls[0]);
|
||||
var api = RestClient.For<IWireMockAdminApi>(server.Url);
|
||||
|
||||
// Act
|
||||
var model = new MappingModel
|
||||
@@ -330,9 +342,8 @@ public class WireMockAdminApiTests
|
||||
mapping.Should().NotBeNull();
|
||||
|
||||
var getMappingResult = await api.GetMappingAsync(guid).ConfigureAwait(false);
|
||||
getMappingResult.Should().NotBeNull();
|
||||
|
||||
getMappingResult.Request.Body.Should().BeEquivalentTo(model.Request.Body);
|
||||
await Verifier.Verify(getMappingResult, VerifySettings).DontScrubGuids();
|
||||
|
||||
server.Stop();
|
||||
}
|
||||
@@ -629,5 +640,125 @@ public class WireMockAdminApiTests
|
||||
var status = await api.ResetScenarioAsync(name).ConfigureAwait(false);
|
||||
status.Status.Should().Be("No scenario found by name 'x'.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task IWireMockAdminApi_GetMappingByGuidAsync()
|
||||
{
|
||||
// Arrange
|
||||
var guid = Guid.Parse("90356dba-b36c-469a-a17e-669cd84f1f05");
|
||||
var server = WireMockServer.StartWithAdminInterface();
|
||||
|
||||
server
|
||||
.Given(
|
||||
Request.Create()
|
||||
.WithPath("/foo1")
|
||||
.WithParam("p1", "xyz")
|
||||
.UsingGet()
|
||||
)
|
||||
.WithGuid(guid)
|
||||
.RespondWith(
|
||||
Response.Create()
|
||||
.WithStatusCode(200)
|
||||
.WithBody("1")
|
||||
);
|
||||
|
||||
// Act
|
||||
var api = RestClient.For<IWireMockAdminApi>(server.Url);
|
||||
var getMappingResult = await api.GetMappingAsync(guid).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
var mapping = server.Mappings.FirstOrDefault(m => m.Guid == guid);
|
||||
mapping.Should().NotBeNull();
|
||||
|
||||
await Verifier.Verify(getMappingResult, VerifySettings).DontScrubGuids();
|
||||
|
||||
server.Stop();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task IWireMockAdminApi_GetMappingCodeByGuidAsync()
|
||||
{
|
||||
// Arrange
|
||||
var guid = Guid.Parse("90356dba-b36c-469a-a17e-669cd84f1f05");
|
||||
var server = WireMockServer.StartWithAdminInterface();
|
||||
|
||||
server
|
||||
.Given(
|
||||
Request.Create()
|
||||
.WithPath("/foo1")
|
||||
.WithParam("p1", "xyz")
|
||||
.UsingGet()
|
||||
)
|
||||
.WithGuid(guid)
|
||||
.RespondWith(
|
||||
Response.Create()
|
||||
.WithStatusCode(200)
|
||||
.WithBody("1")
|
||||
);
|
||||
|
||||
// Act
|
||||
var api = RestClient.For<IWireMockAdminApi>(server.Url);
|
||||
|
||||
var mappings = await api.GetMappingsAsync().ConfigureAwait(false);
|
||||
mappings.Should().HaveCount(1);
|
||||
|
||||
var code = await api.GetMappingCodeAsync(guid).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
await Verifier.Verify(code).DontScrubDateTimes().DontScrubGuids();
|
||||
|
||||
server.Stop();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task IWireMockAdminApi_GetMappingsCode()
|
||||
{
|
||||
// Arrange
|
||||
var guid1 = Guid.Parse("90356dba-b36c-469a-a17e-669cd84f1f05");
|
||||
var guid2 = Guid.Parse("1b731398-4a5b-457f-a6e3-d65e541c428f");
|
||||
var server = WireMockServer.StartWithAdminInterface();
|
||||
|
||||
server
|
||||
.Given(
|
||||
Request.Create()
|
||||
.WithPath("/foo1")
|
||||
.WithParam("p1", "xyz")
|
||||
.UsingGet()
|
||||
)
|
||||
.WithGuid(guid1)
|
||||
.RespondWith(
|
||||
Response.Create()
|
||||
.WithStatusCode(200)
|
||||
.WithBody("1")
|
||||
);
|
||||
|
||||
server
|
||||
.Given(
|
||||
Request.Create()
|
||||
.WithPath("/foo2")
|
||||
.WithParam("p2", "abc")
|
||||
.UsingGet()
|
||||
)
|
||||
.WithGuid(guid2)
|
||||
.RespondWith(
|
||||
Response.Create()
|
||||
.WithStatusCode(201)
|
||||
.WithHeader("hk", "hv")
|
||||
.WithBody("2")
|
||||
);
|
||||
|
||||
// Act
|
||||
var api = RestClient.For<IWireMockAdminApi>(server.Url);
|
||||
|
||||
var mappings = await api.GetMappingsAsync().ConfigureAwait(false);
|
||||
mappings.Should().HaveCount(2);
|
||||
|
||||
var code = await api.GetMappingsCodeAsync().ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
await Verifier.Verify(code).DontScrubDateTimes().DontScrubGuids();
|
||||
|
||||
server.Stop();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -117,7 +117,7 @@ public class WireMockServerProxyTests
|
||||
}
|
||||
|
||||
// Assert
|
||||
server.Mappings.Should().HaveCount(30);
|
||||
server.Mappings.Should().HaveCount(32);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -10,187 +10,186 @@ using WireMock.Server;
|
||||
using WireMock.Settings;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests
|
||||
namespace WireMock.Net.Tests;
|
||||
|
||||
public class WireMockServerSettingsTests
|
||||
{
|
||||
public class WireMockServerSettingsTests
|
||||
private readonly Mock<IWireMockLogger> _loggerMock;
|
||||
|
||||
public WireMockServerSettingsTests()
|
||||
{
|
||||
private readonly Mock<IWireMockLogger> _loggerMock;
|
||||
_loggerMock = new Mock<IWireMockLogger>();
|
||||
_loggerMock.Setup(l => l.Info(It.IsAny<string>(), It.IsAny<object[]>()));
|
||||
}
|
||||
|
||||
public WireMockServerSettingsTests()
|
||||
[Fact]
|
||||
public void WireMockServer_WireMockServerSettings_StartAdminInterfaceTrue_BasicAuthenticationIsSet()
|
||||
{
|
||||
// Assign and Act
|
||||
var server = WireMockServer.Start(new WireMockServerSettings
|
||||
{
|
||||
_loggerMock = new Mock<IWireMockLogger>();
|
||||
_loggerMock.Setup(l => l.Info(It.IsAny<string>(), It.IsAny<object[]>()));
|
||||
}
|
||||
StartAdminInterface = true,
|
||||
AdminUsername = "u",
|
||||
AdminPassword = "p"
|
||||
});
|
||||
|
||||
[Fact]
|
||||
public void WireMockServer_WireMockServerSettings_StartAdminInterfaceTrue_BasicAuthenticationIsSet()
|
||||
// Assert
|
||||
var options = server.GetPrivateFieldValue<IWireMockMiddlewareOptions>("_options");
|
||||
options.AuthenticationMatcher.Should().NotBeNull().And.BeOfType<BasicAuthenticationMatcher>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WireMockServer_WireMockServerSettings_StartAdminInterfaceTrue_AzureADAuthenticationIsSet()
|
||||
{
|
||||
// Assign and Act
|
||||
var server = WireMockServer.Start(new WireMockServerSettings
|
||||
{
|
||||
// Assign and Act
|
||||
var server = WireMockServer.Start(new WireMockServerSettings
|
||||
StartAdminInterface = true,
|
||||
AdminAzureADTenant = "t",
|
||||
AdminAzureADAudience = "a"
|
||||
});
|
||||
|
||||
// Assert
|
||||
var options = server.GetPrivateFieldValue<IWireMockMiddlewareOptions>("_options");
|
||||
options.AuthenticationMatcher.Should().NotBeNull().And.BeOfType<AzureADAuthenticationMatcher>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WireMockServer_WireMockServerSettings_StartAdminInterfaceFalse_BasicAuthenticationIsNotSet()
|
||||
{
|
||||
// Assign and Act
|
||||
var server = WireMockServer.Start(new WireMockServerSettings
|
||||
{
|
||||
StartAdminInterface = false,
|
||||
AdminUsername = "u",
|
||||
AdminPassword = "p"
|
||||
});
|
||||
|
||||
// Assert
|
||||
var options = server.GetPrivateFieldValue<IWireMockMiddlewareOptions>("_options");
|
||||
Check.That(options.AuthenticationMatcher).IsNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WireMockServer_WireMockServerSettings_PriorityFromAllAdminMappingsIsLow_When_StartAdminInterface_IsTrue()
|
||||
{
|
||||
// Assign and Act
|
||||
var server = WireMockServer.Start(new WireMockServerSettings
|
||||
{
|
||||
StartAdminInterface = true
|
||||
});
|
||||
|
||||
// Assert
|
||||
server.Mappings.Should().NotBeNull();
|
||||
server.Mappings.Should().HaveCount(30);
|
||||
server.Mappings.All(m => m.Priority == WireMockConstants.AdminPriority).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WireMockServer_WireMockServerSettings_ProxyAndRecordSettings_ProxyPriority_IsMinus2000000_When_StartAdminInterface_IsTrue()
|
||||
{
|
||||
// Assign and Act
|
||||
var server = WireMockServer.Start(new WireMockServerSettings
|
||||
{
|
||||
StartAdminInterface = true,
|
||||
ProxyAndRecordSettings = new ProxyAndRecordSettings
|
||||
{
|
||||
StartAdminInterface = true,
|
||||
AdminUsername = "u",
|
||||
AdminPassword = "p"
|
||||
});
|
||||
Url = "www.google.com"
|
||||
}
|
||||
});
|
||||
|
||||
// Assert
|
||||
var options = server.GetPrivateFieldValue<IWireMockMiddlewareOptions>("_options");
|
||||
options.AuthenticationMatcher.Should().NotBeNull().And.BeOfType<BasicAuthenticationMatcher>();
|
||||
}
|
||||
// Assert
|
||||
server.Mappings.Should().NotBeNull();
|
||||
server.Mappings.Should().HaveCount(31);
|
||||
|
||||
[Fact]
|
||||
public void WireMockServer_WireMockServerSettings_StartAdminInterfaceTrue_AzureADAuthenticationIsSet()
|
||||
server.Mappings.Count(m => m.Priority == WireMockConstants.AdminPriority).Should().Be(30);
|
||||
server.Mappings.Count(m => m.Priority == WireMockConstants.ProxyPriority).Should().Be(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WireMockServer_WireMockServerSettings_ProxyAndRecordSettings_ProxyPriority_Is0_When_StartAdminInterface_IsFalse()
|
||||
{
|
||||
// Assign and Act
|
||||
var server = WireMockServer.Start(new WireMockServerSettings
|
||||
{
|
||||
// Assign and Act
|
||||
var server = WireMockServer.Start(new WireMockServerSettings
|
||||
ProxyAndRecordSettings = new ProxyAndRecordSettings
|
||||
{
|
||||
StartAdminInterface = true,
|
||||
AdminAzureADTenant = "t",
|
||||
AdminAzureADAudience = "a"
|
||||
});
|
||||
Url = "www.google.com"
|
||||
}
|
||||
});
|
||||
|
||||
// Assert
|
||||
var options = server.GetPrivateFieldValue<IWireMockMiddlewareOptions>("_options");
|
||||
options.AuthenticationMatcher.Should().NotBeNull().And.BeOfType<AzureADAuthenticationMatcher>();
|
||||
}
|
||||
// Assert
|
||||
var mappings = server.Mappings.ToArray();
|
||||
Check.That(mappings.Count()).IsEqualTo(1);
|
||||
Check.That(mappings[0].Priority).IsEqualTo(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WireMockServer_WireMockServerSettings_StartAdminInterfaceFalse_BasicAuthenticationIsNotSet()
|
||||
[Fact]
|
||||
public void WireMockServer_WireMockServerSettings_AllowPartialMapping()
|
||||
{
|
||||
// Assign and Act
|
||||
var server = WireMockServer.Start(new WireMockServerSettings
|
||||
{
|
||||
// Assign and Act
|
||||
var server = WireMockServer.Start(new WireMockServerSettings
|
||||
{
|
||||
StartAdminInterface = false,
|
||||
AdminUsername = "u",
|
||||
AdminPassword = "p"
|
||||
});
|
||||
Logger = _loggerMock.Object,
|
||||
AllowPartialMapping = true
|
||||
});
|
||||
|
||||
// Assert
|
||||
var options = server.GetPrivateFieldValue<IWireMockMiddlewareOptions>("_options");
|
||||
Check.That(options.AuthenticationMatcher).IsNull();
|
||||
}
|
||||
// Assert
|
||||
var options = server.GetPrivateFieldValue<IWireMockMiddlewareOptions>("_options");
|
||||
Check.That(options.AllowPartialMapping).Equals(true);
|
||||
|
||||
[Fact]
|
||||
public void WireMockServer_WireMockServerSettings_PriorityFromAllAdminMappingsIsLow_When_StartAdminInterface_IsTrue()
|
||||
// Verify
|
||||
_loggerMock.Verify(l => l.Info(It.IsAny<string>(), It.IsAny<bool>()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WireMockServer_WireMockServerSettings_AllowBodyForAllHttpMethods()
|
||||
{
|
||||
// Assign and Act
|
||||
var server = WireMockServer.Start(new WireMockServerSettings
|
||||
{
|
||||
// Assign and Act
|
||||
var server = WireMockServer.Start(new WireMockServerSettings
|
||||
{
|
||||
StartAdminInterface = true
|
||||
});
|
||||
Logger = _loggerMock.Object,
|
||||
AllowBodyForAllHttpMethods = true
|
||||
});
|
||||
|
||||
// Assert
|
||||
server.Mappings.Should().NotBeNull();
|
||||
server.Mappings.Should().HaveCount(28);
|
||||
server.Mappings.All(m => m.Priority == WireMockConstants.AdminPriority).Should().BeTrue();
|
||||
}
|
||||
// Assert
|
||||
var options = server.GetPrivateFieldValue<IWireMockMiddlewareOptions>("_options");
|
||||
Check.That(options.AllowBodyForAllHttpMethods).Equals(true);
|
||||
|
||||
[Fact]
|
||||
public void WireMockServer_WireMockServerSettings_ProxyAndRecordSettings_ProxyPriority_IsMinus2000000_When_StartAdminInterface_IsTrue()
|
||||
// Verify
|
||||
_loggerMock.Verify(l => l.Info(It.Is<string>(s => s.Contains("AllowBodyForAllHttpMethods") && s.Contains("True"))));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WireMockServer_WireMockServerSettings_AllowOnlyDefinedHttpStatusCodeInResponse()
|
||||
{
|
||||
// Assign and Act
|
||||
var server = WireMockServer.Start(new WireMockServerSettings
|
||||
{
|
||||
// Assign and Act
|
||||
var server = WireMockServer.Start(new WireMockServerSettings
|
||||
{
|
||||
StartAdminInterface = true,
|
||||
ProxyAndRecordSettings = new ProxyAndRecordSettings
|
||||
{
|
||||
Url = "www.google.com"
|
||||
}
|
||||
});
|
||||
Logger = _loggerMock.Object,
|
||||
AllowOnlyDefinedHttpStatusCodeInResponse = true
|
||||
});
|
||||
|
||||
// Assert
|
||||
server.Mappings.Should().NotBeNull();
|
||||
server.Mappings.Should().HaveCount(29);
|
||||
// Assert
|
||||
var options = server.GetPrivateFieldValue<IWireMockMiddlewareOptions>("_options");
|
||||
Check.That(options.AllowOnlyDefinedHttpStatusCodeInResponse).Equals(true);
|
||||
|
||||
server.Mappings.Count(m => m.Priority == WireMockConstants.AdminPriority).Should().Be(28);
|
||||
server.Mappings.Count(m => m.Priority == WireMockConstants.ProxyPriority).Should().Be(1);
|
||||
}
|
||||
// Verify
|
||||
_loggerMock.Verify(l => l.Info(It.Is<string>(s => s.Contains("AllowOnlyDefinedHttpStatusCodeInResponse") && s.Contains("True"))));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WireMockServer_WireMockServerSettings_ProxyAndRecordSettings_ProxyPriority_Is0_When_StartAdminInterface_IsFalse()
|
||||
[Fact]
|
||||
public void WireMockServer_WireMockServerSettings_RequestLogExpirationDuration()
|
||||
{
|
||||
// Assign and Act
|
||||
var server = WireMockServer.Start(new WireMockServerSettings
|
||||
{
|
||||
// Assign and Act
|
||||
var server = WireMockServer.Start(new WireMockServerSettings
|
||||
{
|
||||
ProxyAndRecordSettings = new ProxyAndRecordSettings
|
||||
{
|
||||
Url = "www.google.com"
|
||||
}
|
||||
});
|
||||
Logger = _loggerMock.Object,
|
||||
RequestLogExpirationDuration = 1
|
||||
});
|
||||
|
||||
// Assert
|
||||
var mappings = server.Mappings.ToArray();
|
||||
Check.That(mappings.Count()).IsEqualTo(1);
|
||||
Check.That(mappings[0].Priority).IsEqualTo(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WireMockServer_WireMockServerSettings_AllowPartialMapping()
|
||||
{
|
||||
// Assign and Act
|
||||
var server = WireMockServer.Start(new WireMockServerSettings
|
||||
{
|
||||
Logger = _loggerMock.Object,
|
||||
AllowPartialMapping = true
|
||||
});
|
||||
|
||||
// Assert
|
||||
var options = server.GetPrivateFieldValue<IWireMockMiddlewareOptions>("_options");
|
||||
Check.That(options.AllowPartialMapping).Equals(true);
|
||||
|
||||
// Verify
|
||||
_loggerMock.Verify(l => l.Info(It.IsAny<string>(), It.IsAny<bool>()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WireMockServer_WireMockServerSettings_AllowBodyForAllHttpMethods()
|
||||
{
|
||||
// Assign and Act
|
||||
var server = WireMockServer.Start(new WireMockServerSettings
|
||||
{
|
||||
Logger = _loggerMock.Object,
|
||||
AllowBodyForAllHttpMethods = true
|
||||
});
|
||||
|
||||
// Assert
|
||||
var options = server.GetPrivateFieldValue<IWireMockMiddlewareOptions>("_options");
|
||||
Check.That(options.AllowBodyForAllHttpMethods).Equals(true);
|
||||
|
||||
// Verify
|
||||
_loggerMock.Verify(l => l.Info(It.Is<string>(s => s.Contains("AllowBodyForAllHttpMethods") && s.Contains("True"))));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WireMockServer_WireMockServerSettings_AllowOnlyDefinedHttpStatusCodeInResponse()
|
||||
{
|
||||
// Assign and Act
|
||||
var server = WireMockServer.Start(new WireMockServerSettings
|
||||
{
|
||||
Logger = _loggerMock.Object,
|
||||
AllowOnlyDefinedHttpStatusCodeInResponse = true
|
||||
});
|
||||
|
||||
// Assert
|
||||
var options = server.GetPrivateFieldValue<IWireMockMiddlewareOptions>("_options");
|
||||
Check.That(options.AllowOnlyDefinedHttpStatusCodeInResponse).Equals(true);
|
||||
|
||||
// Verify
|
||||
_loggerMock.Verify(l => l.Info(It.Is<string>(s => s.Contains("AllowOnlyDefinedHttpStatusCodeInResponse") && s.Contains("True"))));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WireMockServer_WireMockServerSettings_RequestLogExpirationDuration()
|
||||
{
|
||||
// Assign and Act
|
||||
var server = WireMockServer.Start(new WireMockServerSettings
|
||||
{
|
||||
Logger = _loggerMock.Object,
|
||||
RequestLogExpirationDuration = 1
|
||||
});
|
||||
|
||||
// Assert
|
||||
var options = server.GetPrivateFieldValue<IWireMockMiddlewareOptions>("_options");
|
||||
Check.That(options.RequestLogExpirationDuration).IsEqualTo(1);
|
||||
}
|
||||
// Assert
|
||||
var options = server.GetPrivateFieldValue<IWireMockMiddlewareOptions>("_options");
|
||||
Check.That(options.RequestLogExpirationDuration).IsEqualTo(1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user