mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-02 04:27:44 +01:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
15ece7ec09 | ||
|
|
336cb7ccae |
12
CHANGELOG.md
12
CHANGELOG.md
@@ -1,15 +1,3 @@
|
||||
# 1.5.58 (08 June 2024)
|
||||
- [#1116](https://github.com/WireMock-Net/WireMock.Net/pull/1116) - Add some methods to the BodyModelBuilder [feature] contributed by [StefH](https://github.com/StefH)
|
||||
- [#1117](https://github.com/WireMock-Net/WireMock.Net/issues/1117) - AbstractJsonPartialMatcher: Regex Value is Uppercased when IgnoreCase is set to true [bug]
|
||||
|
||||
# 1.5.57 (04 June 2024)
|
||||
- [#1113](https://github.com/WireMock-Net/WireMock.Net/pull/1113) - Add some Extension methods to IWireMockAdminApi [feature] contributed by [StefH](https://github.com/StefH)
|
||||
|
||||
# 1.5.56 (03 June 2024)
|
||||
- [#1111](https://github.com/WireMock-Net/WireMock.Net/pull/1111) - Fix Request.Create().WithBodyAsJson(...) [bug] contributed by [StefH](https://github.com/StefH)
|
||||
- [#1112](https://github.com/WireMock-Net/WireMock.Net/pull/1112) - Add "/__admin/health" endpoint [feature] contributed by [StefH](https://github.com/StefH)
|
||||
- [#1110](https://github.com/WireMock-Net/WireMock.Net/issues/1110) - Connection prematurely closed BEFORE response [bug]
|
||||
|
||||
# 1.5.55 (22 May 2024)
|
||||
- [#1107](https://github.com/WireMock-Net/WireMock.Net/pull/1107) - When only Port is provided, bind to * (Fixes #1100) [bug] contributed by [StefH](https://github.com/StefH)
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<VersionPrefix>1.5.58</VersionPrefix>
|
||||
<VersionPrefix>1.5.55</VersionPrefix>
|
||||
<PackageIcon>WireMock.Net-Logo.png</PackageIcon>
|
||||
<PackageProjectUrl>https://github.com/WireMock-Net/WireMock.Net</PackageProjectUrl>
|
||||
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
rem https://github.com/StefH/GitHubReleaseNotes
|
||||
|
||||
SET version=1.5.58
|
||||
SET version=1.5.55
|
||||
|
||||
GitHubReleaseNotes --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc duplicate example --version %version% --token %GH_TOKEN%
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
# 1.5.58 (08 June 2024)
|
||||
- #1116 Add some methods to the BodyModelBuilder [feature]
|
||||
- #1117 AbstractJsonPartialMatcher: Regex Value is Uppercased when IgnoreCase is set to true [bug]
|
||||
# 1.5.55 (22 May 2024)
|
||||
- #1107 When only Port is provided, bind to * (Fixes #1100) [bug]
|
||||
|
||||
The full release notes can be found here: https://github.com/WireMock-Net/WireMock.Net/blob/master/CHANGELOG.md
|
||||
@@ -14,13 +14,10 @@ class Program
|
||||
{
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
// Start WireMock.Net tool with Admin interface
|
||||
// dotnet-wiremock --StartAdminInterface
|
||||
|
||||
// Create an implementation of the IWireMockAdminApi and pass in the base URL for the API.
|
||||
var api = RestClient.For<IWireMockAdminApi>("http://localhost:9091");
|
||||
|
||||
await api.ResetMappingsAsync().ConfigureAwait(false);
|
||||
// await api.ResetMappingsAsync().ConfigureAwait(false);
|
||||
|
||||
var mappingBuilder = api.GetMappingBuilder();
|
||||
mappingBuilder.Given(m => m
|
||||
@@ -54,32 +51,13 @@ class Program
|
||||
.WithPath("/bla3")
|
||||
)
|
||||
.WithResponse(rsp => rsp
|
||||
.WithBodyAsJson(new
|
||||
.WithBodyAsJson(new
|
||||
{
|
||||
x = "test"
|
||||
}, true)
|
||||
)
|
||||
);
|
||||
|
||||
mappingBuilder.Given(m => m
|
||||
.WithRequest(req => req
|
||||
.WithPath("/test1")
|
||||
.UsingPost()
|
||||
.WithBody(b => b
|
||||
.WithJmesPathMatcher("things.name == 'RequiredThing'")
|
||||
)
|
||||
)
|
||||
.WithResponse(rsp => rsp
|
||||
.WithHeaders(h => h.Add("Content-Type", "application/json"))
|
||||
.WithDelay(TimeSpan.FromMilliseconds(50))
|
||||
.WithStatusCode(200)
|
||||
.WithBodyAsJson(new
|
||||
{
|
||||
status = "ok"
|
||||
}, true)
|
||||
)
|
||||
);
|
||||
|
||||
var result = await mappingBuilder.BuildAndPostAsync().ConfigureAwait(false);
|
||||
Console.WriteLine($"result = {JsonConvert.SerializeObject(result)}");
|
||||
|
||||
@@ -134,9 +112,6 @@ class Program
|
||||
var getFileResult = await api.GetFileAsync("1.cs");
|
||||
Console.WriteLine($"getFileResult = {getFileResult}");
|
||||
|
||||
Console.WriteLine("Press any key to reset mappings");
|
||||
Console.ReadKey();
|
||||
|
||||
var resetMappingsAsync = await api.ResetMappingsAsync();
|
||||
Console.WriteLine($"resetMappingsAsync = {resetMappingsAsync.Status}");
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"profiles": {
|
||||
"WSL": {
|
||||
"commandName": "WSL2",
|
||||
"distributionName": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ApplicationIcon>../../resources/WireMock.Net-Logo.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
@@ -229,6 +229,7 @@ message HelloReply {
|
||||
server.SetBasicAuthentication("a", "b");
|
||||
//server.SetAzureADAuthentication("6c2a4722-f3b9-4970-b8fc-fac41e29stef", "8587fde1-7824-42c7-8592-faf92b04stef");
|
||||
|
||||
|
||||
//var http = new HttpClient();
|
||||
//var response = await http.GetAsync($"{_wireMockServer.Url}/pricing");
|
||||
//var value = await response.Content.ReadAsStringAsync();
|
||||
|
||||
@@ -1,130 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace WireMock.Admin.Mappings;
|
||||
|
||||
/// <summary>
|
||||
/// BodyModelBuilder
|
||||
/// </summary>
|
||||
public partial class BodyModelBuilder
|
||||
{
|
||||
public BodyModelBuilder WithNotNullOrEmptyMatcher(bool rejectOnMatch = false)
|
||||
{
|
||||
return WithMatcher(mb => mb
|
||||
.WithName("NotNullOrEmptyMatcher")
|
||||
.WithRejectOnMatch(rejectOnMatch)
|
||||
);
|
||||
}
|
||||
|
||||
public BodyModelBuilder WithCSharpCodeMatcher(string pattern, bool rejectOnMatch = false)
|
||||
{
|
||||
return WithMatcher("CSharpCodeMatcher", pattern, rejectOnMatch);
|
||||
}
|
||||
|
||||
public BodyModelBuilder WithLinqMatcher(string pattern, bool rejectOnMatch = false)
|
||||
{
|
||||
return WithMatcher("LinqMatcher", pattern, rejectOnMatch);
|
||||
}
|
||||
|
||||
public BodyModelBuilder WithExactMatcher(string pattern, bool rejectOnMatch = false)
|
||||
{
|
||||
return WithMatcher("ExactMatcher", pattern, rejectOnMatch);
|
||||
}
|
||||
|
||||
public BodyModelBuilder WithExactObjectMatcher(object value, bool rejectOnMatch = false)
|
||||
{
|
||||
return WithMatcher("ExactObjectMatcher", value, rejectOnMatch);
|
||||
}
|
||||
|
||||
public BodyModelBuilder WithGraphQLMatcher(string pattern, IDictionary<string, Type>? customScalars = null, bool rejectOnMatch = false)
|
||||
{
|
||||
return WithMatcher(mb => mb
|
||||
.WithName("GraphQLMatcher")
|
||||
.WithCustomScalars(customScalars)
|
||||
.WithPattern(pattern)
|
||||
.WithRejectOnMatch(rejectOnMatch)
|
||||
);
|
||||
}
|
||||
|
||||
public BodyModelBuilder WithProtoBufMatcher(string pattern, bool rejectOnMatch = false)
|
||||
{
|
||||
return WithMatcher(mb => mb
|
||||
.WithName("ProtoBufMatcher")
|
||||
.WithPattern(pattern)
|
||||
.WithRejectOnMatch(rejectOnMatch)
|
||||
);
|
||||
}
|
||||
|
||||
public BodyModelBuilder WithRegexMatcher(string pattern, bool ignoreCase = false, bool rejectOnMatch = false)
|
||||
{
|
||||
return WithMatcher(mb => mb
|
||||
.WithName("RegexMatcher")
|
||||
.WithPattern(pattern)
|
||||
.WithIgnoreCase(ignoreCase)
|
||||
.WithRejectOnMatch(rejectOnMatch)
|
||||
);
|
||||
}
|
||||
|
||||
public BodyModelBuilder WithJsonMatcher(string pattern, bool ignoreCase = false, bool useRegex = false, bool rejectOnMatch = false)
|
||||
{
|
||||
return WithMatcher(mb => mb
|
||||
.WithName("JsonMatcher")
|
||||
.WithPattern(pattern)
|
||||
.WithIgnoreCase(ignoreCase)
|
||||
.WithRegex(useRegex)
|
||||
.WithRejectOnMatch(rejectOnMatch)
|
||||
);
|
||||
}
|
||||
|
||||
public BodyModelBuilder WithJsonPartialMatcher(string pattern, bool ignoreCase = false, bool useRegex = false, bool rejectOnMatch = false)
|
||||
{
|
||||
return WithMatcher(mb => mb
|
||||
.WithName("JsonPartialMatcher")
|
||||
.WithPattern(pattern)
|
||||
.WithIgnoreCase(ignoreCase)
|
||||
.WithRegex(useRegex)
|
||||
.WithRejectOnMatch(rejectOnMatch)
|
||||
);
|
||||
}
|
||||
|
||||
public BodyModelBuilder WithJsonPathMatcher(string pattern, bool rejectOnMatch = false)
|
||||
{
|
||||
return WithMatcher("JsonPathMatcher", pattern, rejectOnMatch);
|
||||
}
|
||||
|
||||
public BodyModelBuilder WithJmesPathMatcher(string pattern, bool rejectOnMatch = false)
|
||||
{
|
||||
return WithMatcher("JmesPathMatcher", pattern, rejectOnMatch);
|
||||
}
|
||||
|
||||
public BodyModelBuilder WithXPathMatcher(string pattern, XmlNamespace[]? xmlNamespaceMap = null, bool rejectOnMatch = false)
|
||||
{
|
||||
return WithMatcher(mb => mb
|
||||
.WithName("PathMatcher")
|
||||
.WithPattern(pattern)
|
||||
.WithXmlNamespaceMap(xmlNamespaceMap)
|
||||
.WithRejectOnMatch(rejectOnMatch)
|
||||
);
|
||||
}
|
||||
|
||||
public BodyModelBuilder WithWildcardMatcher(string pattern, bool ignoreCase = false, bool rejectOnMatch = false)
|
||||
{
|
||||
return WithMatcher("WildcardMatcher", pattern, rejectOnMatch, ignoreCase);
|
||||
}
|
||||
|
||||
public BodyModelBuilder WithSimMetricsMatcher(string pattern, bool ignoreCase = false, bool rejectOnMatch = false)
|
||||
{
|
||||
return WithMatcher("SimMetricsMatcher", pattern, rejectOnMatch, ignoreCase);
|
||||
}
|
||||
|
||||
private BodyModelBuilder WithMatcher(string name, object pattern, bool rejectOnMatch, bool ignoreCase = false)
|
||||
{
|
||||
return WithMatcher(mb => mb
|
||||
.WithName(name)
|
||||
.WithPattern(pattern)
|
||||
.WithRejectOnMatch(rejectOnMatch)
|
||||
.WithIgnoreCase(ignoreCase)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,3 @@
|
||||
using System;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Stef.Validation;
|
||||
using WireMock.Client.Builders;
|
||||
|
||||
namespace WireMock.Client.Extensions;
|
||||
@@ -13,77 +7,13 @@ namespace WireMock.Client.Extensions;
|
||||
/// </summary>
|
||||
public static class WireMockAdminApiExtensions
|
||||
{
|
||||
private const int MaxRetries = 5;
|
||||
private const int InitialWaitingTimeInMilliSeconds = 500;
|
||||
private const string HealthStatusHealthy = "Healthy";
|
||||
|
||||
/// <summary>
|
||||
/// Get a new <see cref="AdminApiMappingBuilder"/> for the <see cref="IWireMockAdminApi"/>.
|
||||
/// </summary>
|
||||
/// <param name="adminApi">See <see cref="IWireMockAdminApi"/>.</param>
|
||||
/// <param name="api">See <see cref="IWireMockAdminApi"/>.</param>
|
||||
/// <returns></returns>
|
||||
public static AdminApiMappingBuilder GetMappingBuilder(this IWireMockAdminApi adminApi)
|
||||
public static AdminApiMappingBuilder GetMappingBuilder(this IWireMockAdminApi api)
|
||||
{
|
||||
return new AdminApiMappingBuilder(adminApi);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set basic authentication to access the <see cref="IWireMockAdminApi"/>.
|
||||
/// </summary>
|
||||
/// <param name="adminApi">See <see cref="IWireMockAdminApi"/>.</param>
|
||||
/// <param name="username">The admin username.</param>
|
||||
/// <param name="password">The admin password.</param>
|
||||
/// <returns><see cref="IWireMockAdminApi"/></returns>
|
||||
public static IWireMockAdminApi WithAuthorization(this IWireMockAdminApi adminApi, string username, string password)
|
||||
{
|
||||
Guard.NotNull(adminApi);
|
||||
Guard.NotNullOrEmpty(username);
|
||||
Guard.NotNullOrEmpty(password);
|
||||
|
||||
adminApi.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes($"{username}:{password}")));
|
||||
return adminApi;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wait for the WireMock.Net server to be healthy. (The "/__admin/health" returns "Healthy").
|
||||
/// </summary>
|
||||
/// <param name="adminApi">See <see cref="IWireMockAdminApi"/>.</param>
|
||||
/// <param name="maxRetries">The maximum number of retries. Default is <c>5</c>.</param>
|
||||
/// <param name="cancellationToken">The optional <see cref="CancellationToken"/>.</param>
|
||||
/// <returns>A completed Task in case the health endpoint is available, else throws a <see cref="InvalidOperationException"/>.</returns>
|
||||
public static async Task WaitForHealthAsync(this IWireMockAdminApi adminApi, int maxRetries = MaxRetries, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Guard.NotNull(adminApi);
|
||||
|
||||
var retries = 0;
|
||||
var waitTime = InitialWaitingTimeInMilliSeconds;
|
||||
var totalWaitTime = waitTime;
|
||||
var isHealthy = await IsHealthyAsync(adminApi, cancellationToken);
|
||||
while (!isHealthy && retries < MaxRetries && !cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
waitTime = (int)(InitialWaitingTimeInMilliSeconds * Math.Pow(2, retries));
|
||||
await Task.Delay(waitTime, cancellationToken);
|
||||
isHealthy = await IsHealthyAsync(adminApi, cancellationToken);
|
||||
retries++;
|
||||
totalWaitTime += waitTime;
|
||||
}
|
||||
|
||||
if (retries >= MaxRetries)
|
||||
{
|
||||
throw new InvalidOperationException($"The /__admin/health endpoint did not return 'Healthy' after {MaxRetries} retries and {totalWaitTime / 1000.0:0.0} seconds.");
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task<bool> IsHealthyAsync(IWireMockAdminApi adminApi, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
var status = await adminApi.GetHealthAsync(cancellationToken);
|
||||
return string.Equals(status, HealthStatusHealthy, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return new AdminApiMappingBuilder(api);
|
||||
}
|
||||
}
|
||||
@@ -24,24 +24,12 @@ public interface IWireMockAdminApi
|
||||
[Header("Authorization")]
|
||||
AuthenticationHeaderValue Authorization { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Get health status.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The optional cancellationToken.</param>
|
||||
/// <returns>
|
||||
/// Returns HttpStatusCode <c>200</c> with a value <c>Healthy</c> to indicate that WireMock.Net is healthy.
|
||||
/// Else it returns HttpStatusCode <c>404</c>.
|
||||
/// </returns>
|
||||
[Get("health")]
|
||||
[AllowAnyStatusCode]
|
||||
Task<string> GetHealthAsync(CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Get the settings.
|
||||
/// </summary>
|
||||
/// <returns>SettingsModel</returns>
|
||||
[Get("settings")]
|
||||
Task<SettingsModel> GetSettingsAsync(CancellationToken cancellationToken = default);
|
||||
Task<SettingsModel> GetSettingsAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Update the settings.
|
||||
|
||||
@@ -8,7 +8,6 @@ using Microsoft.Extensions.Logging;
|
||||
using RestEase;
|
||||
using Stef.Validation;
|
||||
using WireMock.Client;
|
||||
using WireMock.Client.Extensions;
|
||||
using WireMock.Http;
|
||||
|
||||
namespace WireMock.Net.Testcontainers;
|
||||
@@ -48,7 +47,13 @@ public sealed class WireMockContainer : DockerContainer
|
||||
ValidateIfRunning();
|
||||
|
||||
var api = RestClient.For<IWireMockAdminApi>(GetPublicUri());
|
||||
return _configuration.HasBasicAuthentication ? api.WithAuthorization(_configuration.Username!, _configuration.Password!) : api;
|
||||
|
||||
if (_configuration.HasBasicAuthentication)
|
||||
{
|
||||
api.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes($"{_configuration.Username}:{_configuration.Password}")));
|
||||
}
|
||||
|
||||
return api;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -31,6 +31,7 @@ public class JsonMatcher : IJsonMatcher
|
||||
public bool Regex { get; }
|
||||
|
||||
private readonly JToken _valueAsJToken;
|
||||
private readonly Func<JToken, JToken> _jTokenConverter;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="JsonMatcher"/> class.
|
||||
@@ -69,6 +70,7 @@ public class JsonMatcher : IJsonMatcher
|
||||
|
||||
Value = value;
|
||||
_valueAsJToken = JsonUtils.ConvertValueToJToken(value);
|
||||
_jTokenConverter = ignoreCase ? Rename : jToken => jToken;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -84,7 +86,7 @@ public class JsonMatcher : IJsonMatcher
|
||||
{
|
||||
var inputAsJToken = JsonUtils.ConvertValueToJToken(input);
|
||||
|
||||
var match = IsMatch(RenameJToken(_valueAsJToken), RenameJToken(inputAsJToken));
|
||||
var match = IsMatch(_jTokenConverter(_valueAsJToken), _jTokenConverter(inputAsJToken));
|
||||
score = MatchScores.ToScore(match);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -177,59 +179,38 @@ public class JsonMatcher : IJsonMatcher
|
||||
}
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/questions/11679804/json-net-rename-properties
|
||||
private JToken RenameJToken(JToken input)
|
||||
{
|
||||
if (!IgnoreCase)
|
||||
{
|
||||
return input;
|
||||
}
|
||||
|
||||
return input switch
|
||||
{
|
||||
JProperty property => RenameJProperty(property),
|
||||
JArray array => RenameJArray(array),
|
||||
JObject obj => RenameJObject(obj),
|
||||
_ => input
|
||||
};
|
||||
}
|
||||
|
||||
private JProperty RenameJProperty(JProperty property)
|
||||
{
|
||||
if (!IgnoreCase)
|
||||
{
|
||||
return property;
|
||||
}
|
||||
|
||||
var propertyValue = property.Value;
|
||||
if (propertyValue.Type == JTokenType.String && !Regex)
|
||||
{
|
||||
var stringValue = propertyValue.Value<string>()!;
|
||||
propertyValue = ToUpper(stringValue);
|
||||
}
|
||||
|
||||
return new JProperty(ToUpper(property.Name)!, RenameJToken(propertyValue));
|
||||
}
|
||||
|
||||
private JArray RenameJArray(JArray array)
|
||||
{
|
||||
if (Regex)
|
||||
{
|
||||
return array;
|
||||
}
|
||||
|
||||
var renamedValues = array.Select(RenameJToken);
|
||||
return new JArray(renamedValues);
|
||||
}
|
||||
|
||||
private JObject RenameJObject(JObject obj)
|
||||
{
|
||||
var renamedProperties = obj.Properties().Select(RenameJProperty);
|
||||
return new JObject(renamedProperties);
|
||||
}
|
||||
|
||||
private static string? ToUpper(string? input)
|
||||
{
|
||||
return input?.ToUpperInvariant();
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/questions/11679804/json-net-rename-properties
|
||||
private static JToken Rename(JToken json)
|
||||
{
|
||||
if (json is JProperty property)
|
||||
{
|
||||
JToken propertyValue = property.Value;
|
||||
if (propertyValue.Type == JTokenType.String)
|
||||
{
|
||||
string stringValue = propertyValue.Value<string>()!;
|
||||
propertyValue = ToUpper(stringValue);
|
||||
}
|
||||
|
||||
return new JProperty(ToUpper(property.Name)!, Rename(propertyValue));
|
||||
}
|
||||
|
||||
if (json is JArray array)
|
||||
{
|
||||
var renamedValues = array.Select(Rename);
|
||||
return new JArray(renamedValues);
|
||||
}
|
||||
|
||||
if (json is JObject obj)
|
||||
{
|
||||
var renamedProperties = obj.Properties().Select(Rename);
|
||||
return new JObject(renamedProperties);
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,6 @@ public partial class WireMockServer
|
||||
{
|
||||
private const int EnhancedFileSystemWatcherTimeoutMs = 1000;
|
||||
private const string AdminFiles = "/__admin/files";
|
||||
private const string AdminHealth = "/__admin/health";
|
||||
private const string AdminMappings = "/__admin/mappings";
|
||||
private const string AdminMappingsCode = "/__admin/mappings/code";
|
||||
private const string AdminMappingsWireMockOrg = "/__admin/mappings/wiremock.org";
|
||||
@@ -55,9 +54,6 @@ public partial class WireMockServer
|
||||
#region InitAdmin
|
||||
private void InitAdmin()
|
||||
{
|
||||
// __admin/health
|
||||
Given(Request.Create().WithPath(AdminHealth).UsingGet()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(HealthGet));
|
||||
|
||||
// __admin/settings
|
||||
Given(Request.Create().WithPath(AdminSettings).UsingGet()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(SettingsGet));
|
||||
Given(Request.Create().WithPath(AdminSettings).UsingMethod("PUT", "POST").WithHeader(HttpKnownHeaderNames.ContentType, AdminRequestContentTypeJson)).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(SettingsUpdate));
|
||||
@@ -222,22 +218,6 @@ public partial class WireMockServer
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Health
|
||||
private static IResponseMessage HealthGet(IRequestMessage requestMessage)
|
||||
{
|
||||
return new ResponseMessage
|
||||
{
|
||||
BodyData = new BodyData
|
||||
{
|
||||
DetectedBodyType = BodyType.String,
|
||||
BodyAsString = "Healthy"
|
||||
},
|
||||
StatusCode = (int)HttpStatusCode.OK,
|
||||
Headers = new Dictionary<string, WireMockList<string>> { { HttpKnownHeaderNames.ContentType, new WireMockList<string>(WireMockConstants.ContentTypeTextPlain) } }
|
||||
};
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Settings
|
||||
private IResponseMessage SettingsGet(IRequestMessage requestMessage)
|
||||
{
|
||||
@@ -850,4 +830,4 @@ public partial class WireMockServer
|
||||
var singleResult = ((JObject)value).ToObject<T>();
|
||||
return new[] { singleResult! };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ using VerifyXunit;
|
||||
using WireMock.Admin.Mappings;
|
||||
using WireMock.Admin.Settings;
|
||||
using WireMock.Client;
|
||||
using WireMock.Client.Extensions;
|
||||
using WireMock.Handlers;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Matchers;
|
||||
@@ -42,47 +41,6 @@ public partial class WireMockAdminApiTests
|
||||
VerifyNewtonsoftJson.Enable(VerifySettings);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task IWireMockAdminApi_WaitForHealthAsync_AndCall_GetHealthAsync_OK()
|
||||
{
|
||||
// Arrange
|
||||
var adminUsername = $"username_{Guid.NewGuid()}";
|
||||
var adminPassword = $"password_{Guid.NewGuid()}";
|
||||
var server = WireMockServer.Start(w =>
|
||||
{
|
||||
w.StartAdminInterface = true;
|
||||
w.AdminUsername = adminUsername;
|
||||
w.AdminPassword = adminPassword;
|
||||
});
|
||||
var api = RestClient.For<IWireMockAdminApi>(server.Urls[0])
|
||||
.WithAuthorization(adminUsername, adminPassword);
|
||||
|
||||
// Act 1
|
||||
await api.WaitForHealthAsync().ConfigureAwait(false);
|
||||
|
||||
// Act 2
|
||||
var status = await api.GetHealthAsync().ConfigureAwait(false);
|
||||
status.Should().Be("Healthy");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task IWireMockAdminApi_WaitForHealthAsync_AndCall_GetHealthAsync_ThrowsException()
|
||||
{
|
||||
// Arrange
|
||||
var server = WireMockServer.Start(w =>
|
||||
{
|
||||
w.StartAdminInterface = true;
|
||||
w.AdminUsername = $"username_{Guid.NewGuid()}";
|
||||
w.AdminPassword = $"password_{Guid.NewGuid()}";
|
||||
});
|
||||
|
||||
var api = RestClient.For<IWireMockAdminApi>(server.Urls[0]);
|
||||
|
||||
// Act
|
||||
Func<Task> act = () => api.WaitForHealthAsync(maxRetries: 3);
|
||||
await act.Should().ThrowAsync<InvalidOperationException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task IWireMockAdminApi_GetSettingsAsync()
|
||||
{
|
||||
|
||||
@@ -385,22 +385,4 @@ public class JsonPartialWildcardMatcherTests
|
||||
// Assert
|
||||
Assert.Equal(0.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialWildcardMatcher_IsMatch_WithIgnoreCaseTrueAndRegexTrue_JObject()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialWildcardMatcher(new { id = 1, Number = "^\\d+$" }, ignoreCase: true, regex: true);
|
||||
|
||||
// Act
|
||||
var jObject = new JObject
|
||||
{
|
||||
{ "Id", new JValue(1) },
|
||||
{ "Number", new JValue(1) }
|
||||
};
|
||||
double match = matcher.IsMatch(jObject).Score;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
#if NET6_0_OR_GREATER
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using FluentAssertions.Execution;
|
||||
@@ -14,12 +13,9 @@ public class TestcontainersTests
|
||||
public async Task WireMockContainer_Build_and_StartAsync_and_StopAsync()
|
||||
{
|
||||
// Act
|
||||
var adminUsername = $"username_{Guid.NewGuid()}";
|
||||
var adminPassword = $"password_{Guid.NewGuid()}";
|
||||
var wireMockContainer = new WireMockContainerBuilder()
|
||||
.WithAutoRemove(true)
|
||||
.WithCleanUp(true)
|
||||
.WithAdminUserNameAndPassword(adminUsername, adminPassword)
|
||||
.Build();
|
||||
|
||||
try
|
||||
|
||||
@@ -117,7 +117,7 @@ public class WireMockServerProxyTests
|
||||
}
|
||||
|
||||
// Assert
|
||||
server.Mappings.Should().HaveCount(36);
|
||||
server.Mappings.Should().HaveCount(35);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -81,7 +81,7 @@ public class WireMockServerSettingsTests
|
||||
|
||||
// Assert
|
||||
server.Mappings.Should().NotBeNull();
|
||||
server.Mappings.Should().HaveCount(34);
|
||||
server.Mappings.Should().HaveCount(33);
|
||||
server.Mappings.All(m => m.Priority == WireMockConstants.AdminPriority).Should().BeTrue();
|
||||
}
|
||||
|
||||
@@ -100,9 +100,9 @@ public class WireMockServerSettingsTests
|
||||
|
||||
// Assert
|
||||
server.Mappings.Should().NotBeNull();
|
||||
server.Mappings.Should().HaveCount(35);
|
||||
server.Mappings.Should().HaveCount(34);
|
||||
|
||||
server.Mappings.Count(m => m.Priority == WireMockConstants.AdminPriority).Should().Be(34);
|
||||
server.Mappings.Count(m => m.Priority == WireMockConstants.AdminPriority).Should().Be(33);
|
||||
server.Mappings.Count(m => m.Priority == WireMockConstants.ProxyPriority).Should().Be(1);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user