mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-08-11 06:09:25 +02:00
Add some more tests for WireMockList + move AdminPaths.cs file (#1491)
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System.Linq;
|
||||
|
||||
namespace WireMock.Types;
|
||||
|
||||
/// <summary>
|
||||
/// A special List which overrides the ToString() to return first value.
|
||||
/// A special List which overrides the ToString() to return first value in case of a single element.
|
||||
/// Else it will return a comma separated list of all values.
|
||||
/// If null or empty, it will return an empty string.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The generic type</typeparam>
|
||||
/// <seealso cref="List{T}" />
|
||||
@@ -61,11 +61,11 @@ public class WireMockList<T> : List<T>
|
||||
{
|
||||
return strValue;
|
||||
}
|
||||
|
||||
return this[0]?.ToString();
|
||||
|
||||
return this[0]?.ToString() ?? string.Empty;
|
||||
|
||||
default:
|
||||
var strings = this.Select(x => x as string ?? x?.ToString());
|
||||
var strings = this.Select(x => x as string ?? x?.ToString() ?? string.Empty);
|
||||
return string.Join(", ", strings);
|
||||
}
|
||||
}
|
||||
|
||||
+21
-2
@@ -12,29 +12,48 @@ internal sealed class AdminPaths(string? adminPath) : IAdminPaths
|
||||
private readonly string _prefix = adminPath ?? DefaultAdminPathPrefix;
|
||||
|
||||
public string Files => $"{_prefix}/files";
|
||||
|
||||
public string Health => $"{_prefix}/health";
|
||||
|
||||
public string Mappings => $"{_prefix}/mappings";
|
||||
|
||||
public string MappingsCode => $"{_prefix}/mappings/code";
|
||||
|
||||
public string MappingsWireMockOrg => $"{_prefix}/mappings/wiremock.org";
|
||||
|
||||
public string Requests => $"{_prefix}/requests";
|
||||
|
||||
public string Settings => $"{_prefix}/settings";
|
||||
|
||||
public string Scenarios => $"{_prefix}/scenarios";
|
||||
|
||||
public string OpenApi => $"{_prefix}/openapi";
|
||||
|
||||
public string ProtoDefinitions => $"{_prefix}/protodefinitions";
|
||||
|
||||
private string PrefixRegexEscaped => Regex.Escape(_prefix);
|
||||
|
||||
public RegexMatcher MappingsGuidPathMatcher => new($@"^{PrefixRegexEscaped}\/mappings\/([0-9A-Fa-f]{{8}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{12}})$");
|
||||
|
||||
public RegexMatcher MappingsGuidEnablePathMatcher => new($@"^{PrefixRegexEscaped}\/mappings\/([0-9A-Fa-f]{{8}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{12}})\/enable$");
|
||||
|
||||
public RegexMatcher MappingsGuidDisablePathMatcher => new($@"^{PrefixRegexEscaped}\/mappings\/([0-9A-Fa-f]{{8}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{12}})\/disable$");
|
||||
|
||||
public RegexMatcher MappingsCodeGuidPathMatcher => new($@"^{PrefixRegexEscaped}\/mappings\/code\/([0-9A-Fa-f]{{8}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{12}})$");
|
||||
|
||||
public RegexMatcher RequestsGuidPathMatcher => new($@"^{PrefixRegexEscaped}\/requests\/([0-9A-Fa-f]{{8}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{12}})$");
|
||||
|
||||
public RegexMatcher ScenariosNameMatcher => new($@"^{PrefixRegexEscaped}\/scenarios\/.+$");
|
||||
|
||||
public RegexMatcher ScenariosNameWithStateMatcher => new($@"^{PrefixRegexEscaped}\/scenarios\/.+\/state$");
|
||||
|
||||
public RegexMatcher ScenariosNameWithResetMatcher => new($@"^{PrefixRegexEscaped}\/scenarios\/.+\/reset$");
|
||||
|
||||
public RegexMatcher FilesFilenamePathMatcher => new($@"^{PrefixRegexEscaped}\/files\/.+$");
|
||||
|
||||
public RegexMatcher ProtoDefinitionsIdPathMatcher => new($@"^{PrefixRegexEscaped}\/protodefinitions\/.+$");
|
||||
|
||||
public bool Includes(string? path) => !string.IsNullOrEmpty(path) && path.StartsWith($"{_prefix}/");
|
||||
public bool Includes(string? path) => path?.StartsWith($"{_prefix}/") ?? false;
|
||||
|
||||
public override string ToString() => _prefix;
|
||||
}
|
||||
}
|
||||
@@ -5,24 +5,44 @@ namespace WireMock.Owin;
|
||||
internal interface IAdminPaths
|
||||
{
|
||||
string Files { get; }
|
||||
|
||||
string Health { get; }
|
||||
|
||||
string Mappings { get; }
|
||||
|
||||
string MappingsCode { get; }
|
||||
|
||||
string MappingsWireMockOrg { get; }
|
||||
|
||||
RegexMatcher MappingsGuidPathMatcher { get; }
|
||||
|
||||
RegexMatcher MappingsGuidEnablePathMatcher { get; }
|
||||
|
||||
RegexMatcher MappingsGuidDisablePathMatcher { get; }
|
||||
|
||||
RegexMatcher MappingsCodeGuidPathMatcher { get; }
|
||||
|
||||
RegexMatcher RequestsGuidPathMatcher { get; }
|
||||
|
||||
RegexMatcher ScenariosNameMatcher { get; }
|
||||
|
||||
RegexMatcher ScenariosNameWithStateMatcher { get; }
|
||||
|
||||
RegexMatcher ScenariosNameWithResetMatcher { get; }
|
||||
|
||||
RegexMatcher FilesFilenamePathMatcher { get; }
|
||||
|
||||
RegexMatcher ProtoDefinitionsIdPathMatcher { get; }
|
||||
|
||||
string Requests { get; }
|
||||
|
||||
string Settings { get; }
|
||||
|
||||
string Scenarios { get; }
|
||||
|
||||
string OpenApi { get; }
|
||||
|
||||
string ProtoDefinitions { get; }
|
||||
|
||||
bool Includes(string? path);
|
||||
}
|
||||
Reference in New Issue
Block a user