Remove interface for all Settings (#736)

This commit is contained in:
Stef Heyenrath
2022-03-10 20:58:18 +01:00
committed by GitHub
parent 3087ce55b1
commit bb3147eb8d
34 changed files with 238 additions and 511 deletions

View File

@@ -16,11 +16,11 @@ namespace WireMock.Net.StandAlone
private static readonly string Version = typeof(StandAloneApp).GetTypeInfo().Assembly.GetName().Version.ToString(); private static readonly string Version = typeof(StandAloneApp).GetTypeInfo().Assembly.GetName().Version.ToString();
/// <summary> /// <summary>
/// Start WireMock.Net standalone Server based on the IWireMockServerSettings. /// Start WireMock.Net standalone Server based on the WireMockServerSettings.
/// </summary> /// </summary>
/// <param name="settings">The IWireMockServerSettings</param> /// <param name="settings">The WireMockServerSettings</param>
[PublicAPI] [PublicAPI]
public static WireMockServer Start([NotNull] IWireMockServerSettings settings) public static WireMockServer Start([NotNull] WireMockServerSettings settings)
{ {
Guard.NotNull(settings, nameof(settings)); Guard.NotNull(settings, nameof(settings));

View File

@@ -7,7 +7,7 @@ namespace WireMock.Http
{ {
internal static class HttpClientBuilder internal static class HttpClientBuilder
{ {
public static HttpClient Build(IHttpClientSettings settings) public static HttpClient Build(HttpClientSettings settings)
{ {
#if NETSTANDARD || NETCOREAPP3_1 || NET5_0 || NET6_0 #if NETSTANDARD || NETCOREAPP3_1 || NET5_0 || NET6_0
var handler = new HttpClientHandler var handler = new HttpClientHandler

View File

@@ -19,9 +19,9 @@ namespace WireMock.Http
{ {
private const string ClientIp = "::1"; private const string ClientIp = "::1";
private readonly IWireMockServerSettings _settings; private readonly WireMockServerSettings _settings;
public WebhookSender(IWireMockServerSettings settings) public WebhookSender(WireMockServerSettings settings)
{ {
_settings = settings ?? throw new ArgumentNullException(nameof(settings)); _settings = settings ?? throw new ArgumentNullException(nameof(settings));
} }

View File

@@ -76,8 +76,8 @@ namespace WireMock
/// <summary> /// <summary>
/// The WireMockServerSettings. /// The WireMockServerSettings.
/// </summary> /// </summary>
IWireMockServerSettings Settings { get; } WireMockServerSettings Settings { get; }
/// <summary> /// <summary>
/// Is State started ? /// Is State started ?
/// </summary> /// </summary>
@@ -90,7 +90,7 @@ namespace WireMock
/// <c>true</c> if this mapping is an Admin Interface; otherwise, <c>false</c>. /// <c>true</c> if this mapping is an Admin Interface; otherwise, <c>false</c>.
/// </value> /// </value>
bool IsAdminInterface { get; } bool IsAdminInterface { get; }
/// <summary> /// <summary>
/// Gets a value indicating whether this mapping to be logged. /// Gets a value indicating whether this mapping to be logged.
/// </summary> /// </summary>

View File

@@ -44,7 +44,7 @@ namespace WireMock
public IResponseProvider Provider { get; } public IResponseProvider Provider { get; }
/// <inheritdoc /> /// <inheritdoc />
public IWireMockServerSettings Settings { get; } public WireMockServerSettings Settings { get; }
/// <inheritdoc /> /// <inheritdoc />
public bool IsStartState => Scenario == null || Scenario != null && NextState != null && ExecutionConditionState == null; public bool IsStartState => Scenario == null || Scenario != null && NextState != null && ExecutionConditionState == null;
@@ -81,7 +81,7 @@ namespace WireMock
Guid guid, Guid guid,
[CanBeNull] string title, [CanBeNull] string title,
[CanBeNull] string path, [CanBeNull] string path,
[NotNull] IWireMockServerSettings settings, [NotNull] WireMockServerSettings settings,
[NotNull] IRequestMatcher requestMatcher, [NotNull] IRequestMatcher requestMatcher,
[NotNull] IResponseProvider provider, [NotNull] IResponseProvider provider,
int priority, int priority,

View File

@@ -17,15 +17,15 @@ namespace WireMock.Proxy
{ {
internal class ProxyHelper internal class ProxyHelper
{ {
private readonly IWireMockServerSettings _settings; private readonly WireMockServerSettings _settings;
public ProxyHelper([NotNull] IWireMockServerSettings settings) public ProxyHelper([NotNull] WireMockServerSettings settings)
{ {
_settings = Guard.NotNull(settings, nameof(settings)); _settings = Guard.NotNull(settings, nameof(settings));
} }
public async Task<(ResponseMessage Message, IMapping Mapping)> SendAsync( public async Task<(ResponseMessage Message, IMapping Mapping)> SendAsync(
[NotNull] IProxyAndRecordSettings proxyAndRecordSettings, [NotNull] ProxyAndRecordSettings proxyAndRecordSettings,
[NotNull] HttpClient client, [NotNull] HttpClient client,
[NotNull] RequestMessage requestMessage, [NotNull] RequestMessage requestMessage,
[NotNull] string url) [NotNull] string url)
@@ -59,7 +59,7 @@ namespace WireMock.Proxy
return (responseMessage, mapping); return (responseMessage, mapping);
} }
private IMapping ToMapping(IProxyAndRecordSettings proxyAndRecordSettings, RequestMessage requestMessage, ResponseMessage responseMessage) private IMapping ToMapping(ProxyAndRecordSettings proxyAndRecordSettings, RequestMessage requestMessage, ResponseMessage responseMessage)
{ {
string[] excludedHeaders = proxyAndRecordSettings.ExcludedHeaders ?? new string[] { }; string[] excludedHeaders = proxyAndRecordSettings.ExcludedHeaders ?? new string[] { };
string[] excludedCookies = proxyAndRecordSettings.ExcludedCookies ?? new string[] { }; string[] excludedCookies = proxyAndRecordSettings.ExcludedCookies ?? new string[] { };

View File

@@ -1,4 +1,4 @@
using JetBrains.Annotations; using JetBrains.Annotations;
using WireMock.Settings; using WireMock.Settings;
namespace WireMock.ResponseBuilders namespace WireMock.ResponseBuilders
@@ -21,6 +21,6 @@ namespace WireMock.ResponseBuilders
/// </summary> /// </summary>
/// <param name="settings">The IProxyAndRecordSettings.</param> /// <param name="settings">The IProxyAndRecordSettings.</param>
/// <returns>A <see cref="IResponseBuilder"/>.</returns> /// <returns>A <see cref="IResponseBuilder"/>.</returns>
IResponseBuilder WithProxy([NotNull] IProxyAndRecordSettings settings); IResponseBuilder WithProxy([NotNull] ProxyAndRecordSettings settings);
} }
} }

View File

@@ -10,7 +10,7 @@ namespace WireMock.ResponseBuilders
{ {
/// <summary> /// <summary>
/// The with status code. /// The with status code.
/// By default all status codes are allowed, to change this behaviour, see <inheritdoc cref="IWireMockServerSettings.AllowOnlyDefinedHttpStatusCodeInResponse"/>. /// By default all status codes are allowed, to change this behaviour, see <inheritdoc cref="WireMockServerSettings.AllowOnlyDefinedHttpStatusCodeInResponse"/>.
/// </summary> /// </summary>
/// <param name="code">The code.</param> /// <param name="code">The code.</param>
/// <returns>The <see cref="IResponseBuilder"/>.</returns> /// <returns>The <see cref="IResponseBuilder"/>.</returns>
@@ -18,7 +18,7 @@ namespace WireMock.ResponseBuilders
/// <summary> /// <summary>
/// The with status code. /// The with status code.
/// By default all status codes are allowed, to change this behaviour, see <inheritdoc cref="IWireMockServerSettings.AllowOnlyDefinedHttpStatusCodeInResponse"/>. /// By default all status codes are allowed, to change this behaviour, see <inheritdoc cref="WireMockServerSettings.AllowOnlyDefinedHttpStatusCodeInResponse"/>.
/// </summary> /// </summary>
/// <param name="code">The code.</param> /// <param name="code">The code.</param>
/// <returns>The <see cref="IResponseBuilder"/>.</returns> /// <returns>The <see cref="IResponseBuilder"/>.</returns>
@@ -26,7 +26,7 @@ namespace WireMock.ResponseBuilders
/// <summary> /// <summary>
/// The with status code. /// The with status code.
/// By default all status codes are allowed, to change this behaviour, see <inheritdoc cref="IWireMockServerSettings.AllowOnlyDefinedHttpStatusCodeInResponse"/>. /// By default all status codes are allowed, to change this behaviour, see <inheritdoc cref="WireMockServerSettings.AllowOnlyDefinedHttpStatusCodeInResponse"/>.
/// </summary> /// </summary>
/// <param name="code">The code.</param> /// <param name="code">The code.</param>
/// <returns>The <see cref="IResponseBuilder"/>.</returns> /// <returns>The <see cref="IResponseBuilder"/>.</returns>

View File

@@ -1,4 +1,4 @@
using System.Net.Http; using System.Net.Http;
using WireMock.Http; using WireMock.Http;
using WireMock.Settings; using WireMock.Settings;
using Stef.Validation; using Stef.Validation;
@@ -12,7 +12,7 @@ namespace WireMock.ResponseBuilders
/// <summary> /// <summary>
/// The WebProxy settings. /// The WebProxy settings.
/// </summary> /// </summary>
public IProxyAndRecordSettings ProxyAndRecordSettings { get; private set; } public ProxyAndRecordSettings ProxyAndRecordSettings { get; private set; }
/// <inheritdoc cref="IProxyResponseBuilder.WithProxy(string, string)"/> /// <inheritdoc cref="IProxyResponseBuilder.WithProxy(string, string)"/>
public IResponseBuilder WithProxy(string proxyUrl, string clientX509Certificate2ThumbprintOrSubjectName = null) public IResponseBuilder WithProxy(string proxyUrl, string clientX509Certificate2ThumbprintOrSubjectName = null)
@@ -29,7 +29,7 @@ namespace WireMock.ResponseBuilders
} }
/// <inheritdoc cref="IProxyResponseBuilder.WithProxy(IProxyAndRecordSettings)"/> /// <inheritdoc cref="IProxyResponseBuilder.WithProxy(IProxyAndRecordSettings)"/>
public IResponseBuilder WithProxy(IProxyAndRecordSettings settings) public IResponseBuilder WithProxy(ProxyAndRecordSettings settings)
{ {
Guard.NotNull(settings, nameof(settings)); Guard.NotNull(settings, nameof(settings));

View File

@@ -385,8 +385,8 @@ namespace WireMock.ResponseBuilders
return this; return this;
} }
/// <inheritdoc cref="IResponseProvider.ProvideResponseAsync(RequestMessage, IWireMockServerSettings)"/> /// <inheritdoc cref="IResponseProvider.ProvideResponseAsync(RequestMessage, WireMockServerSettings)"/>
public async Task<(ResponseMessage Message, IMapping Mapping)> ProvideResponseAsync(RequestMessage requestMessage, IWireMockServerSettings settings) public async Task<(ResponseMessage Message, IMapping Mapping)> ProvideResponseAsync(RequestMessage requestMessage, WireMockServerSettings settings)
{ {
Guard.NotNull(requestMessage, nameof(requestMessage)); Guard.NotNull(requestMessage, nameof(requestMessage));
Guard.NotNull(settings, nameof(settings)); Guard.NotNull(settings, nameof(settings));

View File

@@ -13,7 +13,7 @@ namespace WireMock.ResponseProviders
_responseMessageFunc = responseMessageFunc; _responseMessageFunc = responseMessageFunc;
} }
public async Task<(ResponseMessage Message, IMapping Mapping)> ProvideResponseAsync(RequestMessage requestMessage, IWireMockServerSettings settings) public async Task<(ResponseMessage Message, IMapping Mapping)> ProvideResponseAsync(RequestMessage requestMessage, WireMockServerSettings settings)
{ {
return (await _responseMessageFunc(requestMessage).ConfigureAwait(false), null); return (await _responseMessageFunc(requestMessage).ConfigureAwait(false), null);
} }

View File

@@ -1,4 +1,4 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using WireMock.Settings; using WireMock.Settings;
@@ -13,7 +13,7 @@ namespace WireMock.ResponseProviders
_responseMessageFunc = responseMessageFunc; _responseMessageFunc = responseMessageFunc;
} }
public Task<(ResponseMessage Message, IMapping Mapping)> ProvideResponseAsync(RequestMessage requestMessage, IWireMockServerSettings settings) public Task<(ResponseMessage Message, IMapping Mapping)> ProvideResponseAsync(RequestMessage requestMessage, WireMockServerSettings settings)
{ {
(ResponseMessage responseMessage, IMapping mapping) result = (_responseMessageFunc(requestMessage), null); (ResponseMessage responseMessage, IMapping mapping) result = (_responseMessageFunc(requestMessage), null);
return Task.FromResult(result); return Task.FromResult(result);

View File

@@ -17,6 +17,6 @@ namespace WireMock.ResponseProviders
/// <param name="requestMessage">The request.</param> /// <param name="requestMessage">The request.</param>
/// <param name="settings">The WireMockServerSettings.</param> /// <param name="settings">The WireMockServerSettings.</param>
/// <returns>The <see cref="ResponseMessage"/> including a new (optional) <see cref="IMapping"/>.</returns> /// <returns>The <see cref="ResponseMessage"/> including a new (optional) <see cref="IMapping"/>.</returns>
Task<(ResponseMessage Message, IMapping Mapping)> ProvideResponseAsync([NotNull] RequestMessage requestMessage, [NotNull] IWireMockServerSettings settings); Task<(ResponseMessage Message, IMapping Mapping)> ProvideResponseAsync([NotNull] RequestMessage requestMessage, [NotNull] WireMockServerSettings settings);
} }
} }

View File

@@ -6,16 +6,16 @@ namespace WireMock.ResponseProviders
{ {
internal class ProxyAsyncResponseProvider : IResponseProvider internal class ProxyAsyncResponseProvider : IResponseProvider
{ {
private readonly Func<RequestMessage, IWireMockServerSettings, Task<ResponseMessage>> _responseMessageFunc; private readonly Func<RequestMessage, WireMockServerSettings, Task<ResponseMessage>> _responseMessageFunc;
private readonly IWireMockServerSettings _settings; private readonly WireMockServerSettings _settings;
public ProxyAsyncResponseProvider(Func<RequestMessage, IWireMockServerSettings, Task<ResponseMessage>> responseMessageFunc, IWireMockServerSettings settings) public ProxyAsyncResponseProvider(Func<RequestMessage, WireMockServerSettings, Task<ResponseMessage>> responseMessageFunc, WireMockServerSettings settings)
{ {
_responseMessageFunc = responseMessageFunc; _responseMessageFunc = responseMessageFunc;
_settings = settings; _settings = settings;
} }
public async Task<(ResponseMessage Message, IMapping Mapping)> ProvideResponseAsync(RequestMessage requestMessage, IWireMockServerSettings settings) public async Task<(ResponseMessage Message, IMapping Mapping)> ProvideResponseAsync(RequestMessage requestMessage, WireMockServerSettings settings)
{ {
return (await _responseMessageFunc(requestMessage, _settings).ConfigureAwait(false), null); return (await _responseMessageFunc(requestMessage, _settings).ConfigureAwait(false), null);
} }

View File

@@ -209,7 +209,7 @@ namespace WireMock.Serialization
return mappingModel; return mappingModel;
} }
private static WebProxyModel MapWebProxy(IWebProxySettings settings) private static WebProxyModel MapWebProxy(WebProxySettings settings)
{ {
return settings != null ? new WebProxyModel return settings != null ? new WebProxyModel
{ {

View File

@@ -8,10 +8,10 @@ namespace WireMock.Serialization
{ {
internal class MappingToFileSaver internal class MappingToFileSaver
{ {
private readonly IWireMockServerSettings _settings; private readonly WireMockServerSettings _settings;
private readonly MappingConverter _mappingConverter; private readonly MappingConverter _mappingConverter;
public MappingToFileSaver(IWireMockServerSettings settings, MappingConverter mappingConverter) public MappingToFileSaver(WireMockServerSettings settings, MappingConverter mappingConverter)
{ {
Guard.NotNull(settings, nameof(settings)); Guard.NotNull(settings, nameof(settings));

View File

@@ -15,9 +15,9 @@ namespace WireMock.Serialization
{ {
internal class MatcherMapper internal class MatcherMapper
{ {
private readonly IWireMockServerSettings _settings; private readonly WireMockServerSettings _settings;
public MatcherMapper(IWireMockServerSettings settings) public MatcherMapper(WireMockServerSettings settings)
{ {
_settings = settings ?? throw new ArgumentNullException(nameof(settings)); _settings = settings ?? throw new ArgumentNullException(nameof(settings));
} }
@@ -54,7 +54,7 @@ namespace WireMock.Serialization
return PluginLoader.Load<ICSharpCodeMatcher>(matchBehaviour, stringPatterns); return PluginLoader.Load<ICSharpCodeMatcher>(matchBehaviour, stringPatterns);
} }
throw new NotSupportedException("It's not allowed to use the 'CSharpCodeMatcher' because IWireMockServerSettings.AllowCSharpCodeMatcher is not set to 'true'."); throw new NotSupportedException("It's not allowed to use the 'CSharpCodeMatcher' because WireMockServerSettings.AllowCSharpCodeMatcher is not set to 'true'.");
case nameof(LinqMatcher): case nameof(LinqMatcher):
return new LinqMatcher(matchBehaviour, throwExceptionWhenMatcherFails, stringPatterns); return new LinqMatcher(matchBehaviour, throwExceptionWhenMatcherFails, stringPatterns);

View File

@@ -27,7 +27,7 @@ namespace WireMock.Server
private int _timesInSameState = 1; private int _timesInSameState = 1;
private readonly RegistrationCallback _registrationCallback; private readonly RegistrationCallback _registrationCallback;
private readonly IRequestMatcher _requestMatcher; private readonly IRequestMatcher _requestMatcher;
private readonly IWireMockServerSettings _settings; private readonly WireMockServerSettings _settings;
private readonly bool _saveToFile; private readonly bool _saveToFile;
public Guid Guid { get; private set; } = Guid.NewGuid(); public Guid Guid { get; private set; } = Guid.NewGuid();
@@ -43,7 +43,7 @@ namespace WireMock.Server
/// <param name="requestMatcher">The request matcher.</param> /// <param name="requestMatcher">The request matcher.</param>
/// <param name="settings">The WireMockServerSettings.</param> /// <param name="settings">The WireMockServerSettings.</param>
/// <param name="saveToFile">Optional boolean to indicate if this mapping should be saved as static mapping file.</param> /// <param name="saveToFile">Optional boolean to indicate if this mapping should be saved as static mapping file.</param>
public RespondWithAProvider(RegistrationCallback registrationCallback, IRequestMatcher requestMatcher, IWireMockServerSettings settings, bool saveToFile = false) public RespondWithAProvider(RegistrationCallback registrationCallback, IRequestMatcher requestMatcher, WireMockServerSettings settings, bool saveToFile = false)
{ {
_registrationCallback = registrationCallback; _registrationCallback = registrationCallback;
_requestMatcher = requestMatcher; _requestMatcher = requestMatcher;

View File

@@ -209,7 +209,7 @@ namespace WireMock.Server
#region Proxy and Record #region Proxy and Record
private HttpClient _httpClientForProxy; private HttpClient _httpClientForProxy;
private void InitProxyAndRecord(IWireMockServerSettings settings) private void InitProxyAndRecord(WireMockServerSettings settings)
{ {
_httpClientForProxy = HttpClientBuilder.Build(settings.ProxyAndRecordSettings); _httpClientForProxy = HttpClientBuilder.Build(settings.ProxyAndRecordSettings);
@@ -222,7 +222,7 @@ namespace WireMock.Server
respondProvider.RespondWith(new ProxyAsyncResponseProvider(ProxyAndRecordAsync, settings)); respondProvider.RespondWith(new ProxyAsyncResponseProvider(ProxyAndRecordAsync, settings));
} }
private async Task<ResponseMessage> ProxyAndRecordAsync(RequestMessage requestMessage, IWireMockServerSettings settings) private async Task<ResponseMessage> ProxyAndRecordAsync(RequestMessage requestMessage, WireMockServerSettings settings)
{ {
var requestUri = new Uri(requestMessage.Url); var requestUri = new Uri(requestMessage.Url);
var proxyUri = new Uri(settings.ProxyAndRecordSettings.Url); var proxyUri = new Uri(settings.ProxyAndRecordSettings.Url);

View File

@@ -29,7 +29,7 @@ namespace WireMock.Server
{ {
private const int ServerStartDelayInMs = 100; private const int ServerStartDelayInMs = 100;
private readonly IWireMockServerSettings _settings; private readonly WireMockServerSettings _settings;
private readonly IOwinSelfHost _httpServer; private readonly IOwinSelfHost _httpServer;
private readonly IWireMockMiddlewareOptions _options = new WireMockMiddlewareOptions(); private readonly IWireMockMiddlewareOptions _options = new WireMockMiddlewareOptions();
private readonly MappingConverter _mappingConverter; private readonly MappingConverter _mappingConverter;
@@ -92,7 +92,7 @@ namespace WireMock.Server
/// <param name="settings">The WireMockServerSettings.</param> /// <param name="settings">The WireMockServerSettings.</param>
/// <returns>The <see cref="WireMockServer"/>.</returns> /// <returns>The <see cref="WireMockServer"/>.</returns>
[PublicAPI] [PublicAPI]
public static WireMockServer Start([NotNull] IWireMockServerSettings settings) public static WireMockServer Start([NotNull] WireMockServerSettings settings)
{ {
Guard.NotNull(settings, nameof(settings)); Guard.NotNull(settings, nameof(settings));
@@ -193,7 +193,7 @@ namespace WireMock.Server
/// Service start failed with error: {startTask.Exception.Message} /// Service start failed with error: {startTask.Exception.Message}
/// </exception> /// </exception>
/// <exception cref="TimeoutException">Service start timed out after {TimeSpan.FromMilliseconds(settings.StartTimeout)}</exception> /// <exception cref="TimeoutException">Service start timed out after {TimeSpan.FromMilliseconds(settings.StartTimeout)}</exception>
protected WireMockServer(IWireMockServerSettings settings) protected WireMockServer(WireMockServerSettings settings)
{ {
_settings = settings; _settings = settings;

View File

@@ -1,17 +1,24 @@
namespace WireMock.Settings namespace WireMock.Settings
{ {
/// <summary> /// <summary>
/// HttpClientSettings /// HttpClientSettings
/// </summary> /// </summary>
public class HttpClientSettings : IHttpClientSettings public class HttpClientSettings
{ {
/// <inheritdoc cref="IHttpClientSettings.ClientX509Certificate2ThumbprintOrSubjectName"/> /// <summary>
/// The clientCertificate thumbprint or subject name fragment to use.
/// Example thumbprint : "D2DBF135A8D06ACCD0E1FAD9BFB28678DF7A9818". Example subject name: "www.google.com""
/// </summary>
public string ClientX509Certificate2ThumbprintOrSubjectName { get; set; } public string ClientX509Certificate2ThumbprintOrSubjectName { get; set; }
/// <inheritdoc cref="IHttpClientSettings.WebProxySettings"/> /// <summary>
public IWebProxySettings WebProxySettings { get; set; } /// Defines the WebProxySettings.
/// </summary>
public WebProxySettings WebProxySettings { get; set; }
/// <inheritdoc cref="IHttpClientSettings.AllowAutoRedirect"/> /// <summary>
/// Proxy requests should follow redirection (30x).
/// </summary>
public bool? AllowAutoRedirect { get; set; } public bool? AllowAutoRedirect { get; set; }
} }
} }

View File

@@ -1,24 +0,0 @@
namespace WireMock.Settings
{
/// <summary>
/// IHttpClientSettings
/// </summary>
public interface IHttpClientSettings
{
/// <summary>
/// The clientCertificate thumbprint or subject name fragment to use.
/// Example thumbprint : "D2DBF135A8D06ACCD0E1FAD9BFB28678DF7A9818". Example subject name: "www.google.com""
/// </summary>
string ClientX509Certificate2ThumbprintOrSubjectName { get; set; }
/// <summary>
/// Defines the WebProxySettings.
/// </summary>
IWebProxySettings WebProxySettings { get; set; }
/// <summary>
/// Proxy requests should follow redirection (30x).
/// </summary>
bool? AllowAutoRedirect { get; set; }
}
}

View File

@@ -1,42 +0,0 @@
using JetBrains.Annotations;
namespace WireMock.Settings
{
/// <summary>
/// IProxyAndRecordSettings
/// </summary>
public interface IProxyAndRecordSettings : IHttpClientSettings
{
/// <summary>
/// The URL to proxy.
/// </summary>
string Url { get; set; }
/// <summary>
/// Save the mapping for each request/response to the internal Mappings.
/// </summary>
bool SaveMapping { get; set; }
/// <summary>
/// Only save request/response to the internal Mappings if the status code is included in this pattern. (Note that SaveMapping must also be set to true.)
/// The pattern can contain a single value like "200", but also ranges like "2xx", "100,300,600" or "100-299,6xx" are supported.
/// </summary>
[CanBeNull]
string SaveMappingForStatusCodePattern { get; set; }
/// <summary>
/// Save the mapping for each request/response to a .json mapping file.
/// </summary>
bool SaveMappingToFile { get; set; }
/// <summary>
/// Defines a list from headers which will be excluded from the saved mappings.
/// </summary>
string[] ExcludedHeaders { get; set; }
/// <summary>
/// Defines a list of cookies which will be excluded from the saved mappings.
/// </summary>
string[] ExcludedCookies { get; set; }
}
}

View File

@@ -1,23 +0,0 @@
namespace WireMock.Settings
{
/// <summary>
/// IWebProxySettings
/// </summary>
public interface IWebProxySettings
{
/// <summary>
/// A string instance that contains the address of the proxy server.
/// </summary>
string Address { get; set; }
/// <summary>
/// The user name associated with the credentials.
/// </summary>
string UserName { get; set; }
/// <summary>
/// The password for the user name associated with the credentials.
/// </summary>
string Password { get; set; }
}
}

View File

@@ -1,9 +0,0 @@
namespace WireMock.Settings
{
/// <summary>
/// IWebhookSettings
/// </summary>
public interface IWebhookSettings : IHttpClientSettings
{
}
}

View File

@@ -1,44 +0,0 @@
namespace WireMock.Settings
{
/// <summary>
/// If https is used, these settings can be used to configure the CertificateSettings in case a custom certificate instead the default .NET certificate should be used.
///
/// X509StoreName and X509StoreLocation should be defined
/// OR
/// X509CertificateFilePath and X509CertificatePassword should be defined
/// </summary>
public interface IWireMockCertificateSettings
{
/// <summary>
/// X509 StoreName (AddressBook, AuthRoot, CertificateAuthority, My, Root, TrustedPeople or TrustedPublisher)
/// </summary>
string X509StoreName { get; set; }
/// <summary>
/// X509 StoreLocation (CurrentUser or LocalMachine)
/// </summary>
string X509StoreLocation { get; set; }
/// <summary>
/// X509 Thumbprint or SubjectName (if not defined, the 'host' is used)
/// </summary>
string X509StoreThumbprintOrSubjectName { get; set; }
/// <summary>
/// X509Certificate FilePath
/// </summary>
string X509CertificateFilePath { get; set; }
/// <summary>
/// X509Certificate Password
/// </summary>
string X509CertificatePassword { get; set; }
/// <summary>
/// X509StoreName and X509StoreLocation should be defined
/// OR
/// X509CertificateFilePath and X509CertificatePassword should be defined
/// </summary>
bool IsDefined { get; }
}
}

View File

@@ -1,249 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using HandlebarsDotNet;
using JetBrains.Annotations;
using Newtonsoft.Json;
using WireMock.Admin.Mappings;
using WireMock.Handlers;
using WireMock.Logging;
using WireMock.Matchers;
using WireMock.RegularExpressions;
#if USE_ASPNETCORE
using Microsoft.Extensions.DependencyInjection;
using WireMock.Types;
#endif
namespace WireMock.Settings
{
/// <summary>
/// IWireMockServerSettings
/// </summary>
public interface IWireMockServerSettings
{
/// <summary>
/// Gets or sets the port.
/// </summary>
[PublicAPI]
int? Port { get; set; }
/// <summary>
/// Gets or sets the use SSL.
/// </summary>
// ReSharper disable once InconsistentNaming
[PublicAPI]
bool? UseSSL { get; set; }
/// <summary>
/// Gets or sets whether to start admin interface.
/// </summary>
[PublicAPI]
bool? StartAdminInterface { get; set; }
/// <summary>
/// Gets or sets if the static mappings should be read at startup.
/// </summary>
[PublicAPI]
bool? ReadStaticMappings { get; set; }
/// <summary>
/// Watch the static mapping files + folder for changes when running.
/// </summary>
[PublicAPI]
bool? WatchStaticMappings { get; set; }
/// <summary>
/// A value indicating whether subdirectories within the static mappings path should be monitored.
/// </summary>
[PublicAPI]
bool? WatchStaticMappingsInSubdirectories { get; set; }
/// <summary>
/// Gets or sets if the proxy and record settings.
/// </summary>
[PublicAPI]
IProxyAndRecordSettings ProxyAndRecordSettings { get; set; }
/// <summary>
/// Gets or sets the urls.
/// </summary>
[PublicAPI]
string[] Urls { get; set; }
/// <summary>
/// StartTimeout
/// </summary>
[PublicAPI]
int StartTimeout { get; set; }
/// <summary>
/// Allow Partial Mapping (default set to false).
/// </summary>
[PublicAPI]
bool? AllowPartialMapping { get; set; }
/// <summary>
/// The username needed for __admin access.
/// </summary>
[PublicAPI]
string AdminUsername { get; set; }
/// <summary>
/// The password needed for __admin access.
/// </summary>
[PublicAPI]
string AdminPassword { get; set; }
/// <summary>
/// The AzureAD Tenant needed for __admin access.
/// </summary>
[PublicAPI]
string AdminAzureADTenant { get; set; }
/// <summary>
/// The AzureAD Audience / Resource for __admin access.
/// </summary>
[PublicAPI]
string AdminAzureADAudience { get; set; }
/// <summary>
/// The RequestLog expiration in hours (optional).
/// </summary>
[PublicAPI]
int? RequestLogExpirationDuration { get; set; }
/// <summary>
/// The MaxRequestLog count (optional).
/// </summary>
[PublicAPI]
int? MaxRequestLogCount { get; set; }
/// <summary>
/// Action which is called (with the IAppBuilder or IApplicationBuilder) before the internal WireMockMiddleware is initialized. [Optional]
/// </summary>
[PublicAPI]
Action<object> PreWireMockMiddlewareInit { get; set; }
/// <summary>
/// Action which is called (with the IAppBuilder or IApplicationBuilder) after the internal WireMockMiddleware is initialized. [Optional]
/// </summary>
[PublicAPI]
Action<object> PostWireMockMiddlewareInit { get; set; }
#if USE_ASPNETCORE
/// <summary>
/// Action which is called with IServiceCollection when ASP.NET Core DI is being configured. [Optional]
/// </summary>
[PublicAPI]
Action<IServiceCollection> AdditionalServiceRegistration { get; set; }
/// <summary>
/// Policies to use when using CORS. By default CORS is disabled. [Optional]
/// </summary>
[PublicAPI]
CorsPolicyOptions? CorsPolicyOptions { get; set; }
#endif
/// <summary>
/// The IWireMockLogger which logs Debug, Info, Warning or Error
/// </summary>
[PublicAPI]
IWireMockLogger Logger { get; set; }
/// <summary>
/// Handler to interact with the file system to read and write static mapping files.
/// </summary>
[PublicAPI]
IFileSystemHandler FileSystemHandler { get; set; }
/// <summary>
/// Action which can be used to add additional Handlebars registrations. [Optional]
/// </summary>
[PublicAPI]
Action<IHandlebars, IFileSystemHandler> HandlebarsRegistrationCallback { get; set; }
/// <summary>
/// Allow the usage of CSharpCodeMatcher (default is not allowed).
/// </summary>
[PublicAPI]
bool? AllowCSharpCodeMatcher { get; set; }
/// <summary>
/// Allow a Body for all HTTP Methods. (default set to false).
/// </summary>
[PublicAPI]
bool? AllowBodyForAllHttpMethods { get; set; }
/// <summary>
/// Allow only a HttpStatus Code in the response which is defined. (default set to false).
/// - false : also null, 0, empty or invalid HttpStatus codes are allowed.
/// - true : only codes defined in <see cref="System.Net.HttpStatusCode"/> are allowed.
/// </summary>
[PublicAPI]
bool? AllowOnlyDefinedHttpStatusCodeInResponse { get; set; }
/// <summary>
/// Set to true to disable Json deserialization when processing requests. (default set to false).
/// </summary>
[PublicAPI]
bool? DisableJsonBodyParsing { get; set; }
/// <summary>
/// Disable support for GZip and Deflate request body decompression. (default set to false).
/// </summary>
[PublicAPI]
bool? DisableRequestBodyDecompressing { get; set; }
/// <summary>
/// Handle all requests synchronously. (default set to false).
/// </summary>
[PublicAPI]
bool? HandleRequestsSynchronously { get; set; }
/// <summary>
/// Throw an exception when the <see cref="IMatcher"/> fails because of invalid input. (default set to false).
/// </summary>
[PublicAPI]
bool? ThrowExceptionWhenMatcherFails { get; set; }
/// <summary>
/// If https is used, these settings can be used to configure the CertificateSettings in case a custom certificate instead the default .NET certificate should be used.
///
/// X509StoreName and X509StoreLocation should be defined
/// OR
/// X509CertificateFilePath and X509CertificatePassword should be defined
/// </summary>
[PublicAPI]
IWireMockCertificateSettings CertificateSettings { get; set; }
/// <summary>
/// Defines if custom CertificateSettings are defined
/// </summary>
[PublicAPI]
bool CustomCertificateDefined { get; }
/// <summary>
/// Defines the global IWebhookSettings to use.
/// </summary>
[PublicAPI]
IWebhookSettings WebhookSettings { get; set; }
/// <summary>
/// Use the <see cref="RegexExtended"/> instead of the default <see cref="Regex"/> (default set to true).
/// </summary>
[PublicAPI]
bool? UseRegexExtended { get; set; }
/// <summary>
/// Save unmatched requests to a file using the <see cref="IFileSystemHandler"/> (default set to false).
/// </summary>
[PublicAPI]
bool? SaveUnmatchedRequests { get; set; }
/// <summary>
/// Custom matcher mappings for static mappings
/// </summary>
[PublicAPI, JsonIgnore]
IDictionary<string, Func<MatcherModel, IMatcher>> CustomMatcherMappings { get; set; }
}
}

View File

@@ -1,11 +1,11 @@
using JetBrains.Annotations; using JetBrains.Annotations;
namespace WireMock.Settings namespace WireMock.Settings
{ {
/// <summary> /// <summary>
/// ProxyAndRecordSettings /// ProxyAndRecordSettings
/// </summary> /// </summary>
public class ProxyAndRecordSettings : HttpClientSettings, IProxyAndRecordSettings public class ProxyAndRecordSettings : HttpClientSettings
{ {
/// <summary> /// <summary>
/// The URL to proxy. /// The URL to proxy.
@@ -32,11 +32,15 @@ namespace WireMock.Settings
[PublicAPI] [PublicAPI]
public string SaveMappingForStatusCodePattern { get; set; } = "*"; public string SaveMappingForStatusCodePattern { get; set; } = "*";
/// <inheritdoc cref="IProxyAndRecordSettings.ExcludedHeaders"/> /// <summary>
/// Defines a list from headers which will be excluded from the saved mappings.
/// </summary>
[PublicAPI] [PublicAPI]
public string[] ExcludedHeaders { get; set; } public string[] ExcludedHeaders { get; set; }
/// <inheritdoc cref="IProxyAndRecordSettings.ExcludedCookies"/> /// <summary>
/// Defines a list of cookies which will be excluded from the saved mappings.
/// </summary>
[PublicAPI] [PublicAPI]
public string[] ExcludedCookies { get; set; } public string[] ExcludedCookies { get; set; }
} }

View File

@@ -1,19 +1,27 @@
using JetBrains.Annotations; using JetBrains.Annotations;
namespace WireMock.Settings namespace WireMock.Settings
{ {
/// <seealso cref="IWebProxySettings" /> /// <summary>
public class WebProxySettings : IWebProxySettings /// WebProxySettings
/// </summary>
public class WebProxySettings
{ {
/// <inheritdoc cref="IWebProxySettings.Address"/> /// <summary>
/// A string instance that contains the address of the proxy server.
/// </summary>
[PublicAPI] [PublicAPI]
public string Address { get; set; } public string Address { get; set; }
/// <inheritdoc cref="IWebProxySettings.UserName"/> /// <summary>
/// The user name associated with the credentials.
/// </summary>
[PublicAPI] [PublicAPI]
public string UserName { get; set; } public string UserName { get; set; }
/// <inheritdoc cref="IWebProxySettings.Password"/> /// <summary>
/// The password for the user name associated with the credentials.
/// </summary>
[PublicAPI] [PublicAPI]
public string Password { get; set; } public string Password { get; set; }
} }

View File

@@ -1,9 +1,9 @@
namespace WireMock.Settings namespace WireMock.Settings
{ {
/// <summary> /// <summary>
/// WebhookSettings /// WebhookSettings
/// </summary> /// </summary>
public class WebhookSettings : HttpClientSettings, IWebhookSettings public class WebhookSettings : HttpClientSettings
{ {
} }
} }

View File

@@ -3,31 +3,49 @@ using JetBrains.Annotations;
namespace WireMock.Settings namespace WireMock.Settings
{ {
/// <summary> /// <summary>
/// <see cref="IWireMockCertificateSettings"/> /// If https is used, these settings can be used to configure the CertificateSettings in case a custom certificate instead the default .NET certificate should be used.
///
/// X509StoreName and X509StoreLocation should be defined
/// OR
/// X509CertificateFilePath and X509CertificatePassword should be defined
/// </summary> /// </summary>
public class WireMockCertificateSettings : IWireMockCertificateSettings public class WireMockCertificateSettings
{ {
/// <inheritdoc cref="IWireMockCertificateSettings.X509StoreName"/> /// <summary>
/// X509 StoreName (AddressBook, AuthRoot, CertificateAuthority, My, Root, TrustedPeople or TrustedPublisher)
/// </summary>
[PublicAPI] [PublicAPI]
public string X509StoreName { get; set; } public string X509StoreName { get; set; }
/// <inheritdoc cref="IWireMockCertificateSettings.X509StoreLocation"/> /// <summary>
/// X509 StoreLocation (CurrentUser or LocalMachine)
/// </summary>
[PublicAPI] [PublicAPI]
public string X509StoreLocation { get; set; } public string X509StoreLocation { get; set; }
/// <inheritdoc cref="IWireMockCertificateSettings.X509StoreThumbprintOrSubjectName"/> /// <summary>
/// X509 Thumbprint or SubjectName (if not defined, the 'host' is used)
/// </summary>
[PublicAPI] [PublicAPI]
public string X509StoreThumbprintOrSubjectName { get; set; } public string X509StoreThumbprintOrSubjectName { get; set; }
/// <inheritdoc cref="IWireMockCertificateSettings.X509CertificateFilePath"/> /// <summary>
/// X509Certificate FilePath
/// </summary>
[PublicAPI] [PublicAPI]
public string X509CertificateFilePath { get; set; } public string X509CertificateFilePath { get; set; }
/// <inheritdoc cref="IWireMockCertificateSettings.X509CertificatePassword"/> /// <summary>
/// X509Certificate Password
/// </summary>
[PublicAPI] [PublicAPI]
public string X509CertificatePassword { get; set; } public string X509CertificatePassword { get; set; }
/// <inheritdoc cref="IWireMockCertificateSettings.IsDefined"/> /// <summary>
/// X509StoreName and X509StoreLocation should be defined
/// OR
/// X509CertificateFilePath and X509CertificatePassword should be defined
/// </summary>
[PublicAPI] [PublicAPI]
public bool IsDefined => public bool IsDefined =>
!string.IsNullOrEmpty(X509StoreName) && !string.IsNullOrEmpty(X509StoreLocation) || !string.IsNullOrEmpty(X509StoreName) && !string.IsNullOrEmpty(X509StoreLocation) ||

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text.RegularExpressions;
using HandlebarsDotNet; using HandlebarsDotNet;
using JetBrains.Annotations; using JetBrains.Annotations;
using Newtonsoft.Json; using Newtonsoft.Json;
@@ -7,6 +8,7 @@ using WireMock.Admin.Mappings;
using WireMock.Handlers; using WireMock.Handlers;
using WireMock.Logging; using WireMock.Logging;
using WireMock.Matchers; using WireMock.Matchers;
using WireMock.RegularExpressions;
using WireMock.Types; using WireMock.Types;
#if USE_ASPNETCORE #if USE_ASPNETCORE
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
@@ -17,157 +19,236 @@ namespace WireMock.Settings
/// <summary> /// <summary>
/// WireMockServerSettings /// WireMockServerSettings
/// </summary> /// </summary>
public class WireMockServerSettings : IWireMockServerSettings public class WireMockServerSettings
{ {
/// <inheritdoc cref="IWireMockServerSettings.Port"/> /// <summary>
/// Gets or sets the port.
/// </summary>
[PublicAPI] [PublicAPI]
public int? Port { get; set; } public int? Port { get; set; }
/// <inheritdoc cref="IWireMockServerSettings.UseSSL"/> /// <summary>
/// Gets or sets the use SSL.
/// </summary>
// ReSharper disable once InconsistentNaming
[PublicAPI] [PublicAPI]
public bool? UseSSL { get; set; } public bool? UseSSL { get; set; }
/// <inheritdoc cref="IWireMockServerSettings.StartAdminInterface"/> /// <summary>
/// Gets or sets whether to start admin interface.
/// </summary>
[PublicAPI] [PublicAPI]
public bool? StartAdminInterface { get; set; } public bool? StartAdminInterface { get; set; }
/// <inheritdoc cref="IWireMockServerSettings.ReadStaticMappings"/> /// <summary>
/// Gets or sets if the static mappings should be read at startup.
/// </summary>
[PublicAPI] [PublicAPI]
public bool? ReadStaticMappings { get; set; } public bool? ReadStaticMappings { get; set; }
/// <inheritdoc cref="IWireMockServerSettings.WatchStaticMappings"/> /// <summary>
/// Watch the static mapping files + folder for changes when running.
/// </summary>
[PublicAPI] [PublicAPI]
public bool? WatchStaticMappings { get; set; } public bool? WatchStaticMappings { get; set; }
/// <inheritdoc cref="IWireMockServerSettings.WatchStaticMappingsInSubdirectories"/> /// <summary>
/// A value indicating whether subdirectories within the static mappings path should be monitored.
/// </summary>
[PublicAPI] [PublicAPI]
public bool? WatchStaticMappingsInSubdirectories { get; set; } public bool? WatchStaticMappingsInSubdirectories { get; set; }
/// <inheritdoc cref="IWireMockServerSettings.ProxyAndRecordSettings"/> /// <summary>
/// Gets or sets if the proxy and record settings.
/// </summary>
[PublicAPI] [PublicAPI]
public IProxyAndRecordSettings ProxyAndRecordSettings { get; set; } public ProxyAndRecordSettings ProxyAndRecordSettings { get; set; }
/// <inheritdoc cref="IWireMockServerSettings.Urls"/> /// <summary>
/// Gets or sets the urls.
/// </summary>
[PublicAPI] [PublicAPI]
public string[] Urls { get; set; } public string[] Urls { get; set; }
/// <inheritdoc cref="IWireMockServerSettings.StartTimeout"/> /// <summary>
/// StartTimeout
/// </summary>
[PublicAPI] [PublicAPI]
public int StartTimeout { get; set; } = 10000; public int StartTimeout { get; set; } = 10000;
/// <inheritdoc cref="IWireMockServerSettings.AllowPartialMapping"/> /// <summary>
/// Allow Partial Mapping (default set to false).
/// </summary>
[PublicAPI] [PublicAPI]
public bool? AllowPartialMapping { get; set; } public bool? AllowPartialMapping { get; set; }
/// <inheritdoc cref="IWireMockServerSettings.AdminUsername"/> /// <summary>
/// The username needed for __admin access.
/// </summary>
[PublicAPI] [PublicAPI]
public string AdminUsername { get; set; } public string AdminUsername { get; set; }
/// <inheritdoc cref="IWireMockServerSettings.AdminPassword"/> /// <summary>
/// The password needed for __admin access.
/// </summary>
[PublicAPI] [PublicAPI]
public string AdminPassword { get; set; } public string AdminPassword { get; set; }
/// <inheritdoc cref="IWireMockServerSettings.AdminAzureADTenant"/> /// <summary>
/// The AzureAD Tenant needed for __admin access.
/// </summary>
[PublicAPI] [PublicAPI]
public string AdminAzureADTenant { get; set; } public string AdminAzureADTenant { get; set; }
/// <inheritdoc cref="IWireMockServerSettings.AdminAzureADAudience"/> /// <summary>
/// The AzureAD Audience / Resource for __admin access.
/// </summary>
[PublicAPI] [PublicAPI]
public string AdminAzureADAudience { get; set; } public string AdminAzureADAudience { get; set; }
/// <inheritdoc cref="IWireMockServerSettings.RequestLogExpirationDuration"/> /// <summary>
/// The RequestLog expiration in hours (optional).
/// </summary>
[PublicAPI] [PublicAPI]
public int? RequestLogExpirationDuration { get; set; } public int? RequestLogExpirationDuration { get; set; }
/// <inheritdoc cref="IWireMockServerSettings.MaxRequestLogCount"/> /// <summary>
/// The MaxRequestLog count (optional).
/// </summary>
[PublicAPI] [PublicAPI]
public int? MaxRequestLogCount { get; set; } public int? MaxRequestLogCount { get; set; }
/// <inheritdoc cref="IWireMockServerSettings.PreWireMockMiddlewareInit"/> /// <summary>
/// Action which is called (with the IAppBuilder or IApplicationBuilder) before the internal WireMockMiddleware is initialized. [Optional]
/// </summary>
[PublicAPI] [PublicAPI]
[JsonIgnore] [JsonIgnore]
public Action<object> PreWireMockMiddlewareInit { get; set; } public Action<object> PreWireMockMiddlewareInit { get; set; }
/// <inheritdoc cref="IWireMockServerSettings.PostWireMockMiddlewareInit"/> /// <summary>
/// Action which is called (with the IAppBuilder or IApplicationBuilder) after the internal WireMockMiddleware is initialized. [Optional]
/// </summary>
[PublicAPI] [PublicAPI]
[JsonIgnore] [JsonIgnore]
public Action<object> PostWireMockMiddlewareInit { get; set; } public Action<object> PostWireMockMiddlewareInit { get; set; }
#if USE_ASPNETCORE #if USE_ASPNETCORE
/// <inheritdoc cref="IWireMockServerSettings.AdditionalServiceRegistration"/> /// <summary>
/// Action which is called with IServiceCollection when ASP.NET Core DI is being configured. [Optional]
/// </summary>
[PublicAPI] [PublicAPI]
[JsonIgnore] [JsonIgnore]
public Action<IServiceCollection> AdditionalServiceRegistration { get; set; } public Action<IServiceCollection> AdditionalServiceRegistration { get; set; }
/// <inheritdoc cref="IWireMockServerSettings.CorsPolicyOptions"/> /// <summary>
/// Policies to use when using CORS. By default CORS is disabled. [Optional]
/// </summary>
[PublicAPI] [PublicAPI]
public CorsPolicyOptions? CorsPolicyOptions { get; set; } public CorsPolicyOptions? CorsPolicyOptions { get; set; }
#endif #endif
/// <inheritdoc cref="IWireMockServerSettings.Logger"/> /// <summary>
/// The IWireMockLogger which logs Debug, Info, Warning or Error
/// </summary>
[PublicAPI] [PublicAPI]
[JsonIgnore] [JsonIgnore]
public IWireMockLogger Logger { get; set; } public IWireMockLogger Logger { get; set; }
/// <inheritdoc cref="IWireMockServerSettings.FileSystemHandler"/> /// <summary>
/// Handler to interact with the file system to read and write static mapping files.
/// </summary>
[PublicAPI] [PublicAPI]
[JsonIgnore] [JsonIgnore]
public IFileSystemHandler FileSystemHandler { get; set; } public IFileSystemHandler FileSystemHandler { get; set; }
/// <inheritdoc cref="IWireMockServerSettings.HandlebarsRegistrationCallback"/> /// <summary>
/// Action which can be used to add additional Handlebars registrations. [Optional]
/// </summary>
[PublicAPI] [PublicAPI]
[JsonIgnore] [JsonIgnore]
public Action<IHandlebars, IFileSystemHandler> HandlebarsRegistrationCallback { get; set; } public Action<IHandlebars, IFileSystemHandler> HandlebarsRegistrationCallback { get; set; }
/// <inheritdoc cref="IWireMockServerSettings.AllowCSharpCodeMatcher"/> /// <summary>
/// Allow the usage of CSharpCodeMatcher (default is not allowed).
/// </summary>
[PublicAPI] [PublicAPI]
public bool? AllowCSharpCodeMatcher { get; set; } public bool? AllowCSharpCodeMatcher { get; set; }
/// <inheritdoc cref="IWireMockServerSettings.AllowBodyForAllHttpMethods"/> /// <summary>
/// Allow a Body for all HTTP Methods. (default set to false).
/// </summary>
[PublicAPI] [PublicAPI]
public bool? AllowBodyForAllHttpMethods { get; set; } public bool? AllowBodyForAllHttpMethods { get; set; }
/// <inheritdoc cref="IWireMockServerSettings.AllowOnlyDefinedHttpStatusCodeInResponse"/> /// <summary>
/// Allow only a HttpStatus Code in the response which is defined. (default set to false).
/// - false : also null, 0, empty or invalid HttpStatus codes are allowed.
/// - true : only codes defined in <see cref="System.Net.HttpStatusCode"/> are allowed.
/// </summary>
[PublicAPI] [PublicAPI]
public bool? AllowOnlyDefinedHttpStatusCodeInResponse { get; set; } public bool? AllowOnlyDefinedHttpStatusCodeInResponse { get; set; }
/// <inheritdoc cref="IWireMockServerSettings.DisableJsonBodyParsing"/> /// <summary>
/// Set to true to disable Json deserialization when processing requests. (default set to false).
/// </summary>
[PublicAPI] [PublicAPI]
public bool? DisableJsonBodyParsing { get; set; } public bool? DisableJsonBodyParsing { get; set; }
/// <inheritdoc cref="IWireMockServerSettings.DisableRequestBodyDecompressing"/> /// <summary>
/// Disable support for GZip and Deflate request body decompression. (default set to false).
/// </summary>
[PublicAPI] [PublicAPI]
public bool? DisableRequestBodyDecompressing { get; set; } public bool? DisableRequestBodyDecompressing { get; set; }
/// <inheritdoc cref="IWireMockServerSettings.HandleRequestsSynchronously"/> /// <summary>
/// Handle all requests synchronously. (default set to false).
/// </summary>
[PublicAPI] [PublicAPI]
public bool? HandleRequestsSynchronously { get; set; } public bool? HandleRequestsSynchronously { get; set; }
/// <inheritdoc cref="IWireMockServerSettings.ThrowExceptionWhenMatcherFails"/> /// <summary>
/// Throw an exception when the <see cref="IMatcher"/> fails because of invalid input. (default set to false).
/// </summary>
[PublicAPI] [PublicAPI]
public bool? ThrowExceptionWhenMatcherFails { get; set; } public bool? ThrowExceptionWhenMatcherFails { get; set; }
/// <inheritdoc cref="IWireMockServerSettings.CertificateSettings"/> /// <summary>
/// If https is used, these settings can be used to configure the CertificateSettings in case a custom certificate instead the default .NET certificate should be used.
///
/// X509StoreName and X509StoreLocation should be defined
/// OR
/// X509CertificateFilePath and X509CertificatePassword should be defined
/// </summary>
[PublicAPI] [PublicAPI]
public IWireMockCertificateSettings CertificateSettings { get; set; } public WireMockCertificateSettings CertificateSettings { get; set; }
/// <inheritdoc cref="IWireMockServerSettings.CustomCertificateDefined"/> /// <summary>
/// Defines if custom CertificateSettings are defined
/// </summary>
[PublicAPI] [PublicAPI]
public bool CustomCertificateDefined => CertificateSettings?.IsDefined == true; public bool CustomCertificateDefined => CertificateSettings?.IsDefined == true;
/// <inheritdoc cref="IWireMockServerSettings.WebhookSettings"/> /// <summary>
/// Defines the global IWebhookSettings to use.
/// </summary>
[PublicAPI] [PublicAPI]
public IWebhookSettings WebhookSettings { get; set; } public WebhookSettings WebhookSettings { get; set; }
/// <inheritdoc cref="IWireMockServerSettings.UseRegexExtended"/> /// <summary>
/// Use the <see cref="RegexExtended"/> instead of the default <see cref="Regex"/> (default set to true).
/// </summary>
[PublicAPI] [PublicAPI]
public bool? UseRegexExtended { get; set; } = true; public bool? UseRegexExtended { get; set; } = true;
/// <inheritdoc cref="IWireMockServerSettings.SaveUnmatchedRequests"/> /// <summary>
/// Save unmatched requests to a file using the <see cref="IFileSystemHandler"/> (default set to false).
/// </summary>
[PublicAPI] [PublicAPI]
public bool? SaveUnmatchedRequests { get; set; } public bool? SaveUnmatchedRequests { get; set; }
/// <inheritdoc cref="IWireMockServerSettings.CustomMatcherMappings"/> /// <summary>
/// Custom matcher mappings for static mappings
/// </summary>
[PublicAPI, JsonIgnore] [PublicAPI, JsonIgnore]
public IDictionary<string, Func<MatcherModel, IMatcher>> CustomMatcherMappings { get; set; } public IDictionary<string, Func<MatcherModel, IMatcher>> CustomMatcherMappings { get; set; }
} }

View File

@@ -8,7 +8,7 @@ using WireMock.Types;
namespace WireMock.Settings namespace WireMock.Settings
{ {
/// <summary> /// <summary>
/// A static helper class to parse commandline arguments into IWireMockServerSettings. /// A static helper class to parse commandline arguments into WireMockServerSettings.
/// </summary> /// </summary>
public static class WireMockServerSettingsParser public static class WireMockServerSettingsParser
{ {
@@ -19,7 +19,7 @@ namespace WireMock.Settings
/// <param name="logger">The logger (optional, can be null)</param> /// <param name="logger">The logger (optional, can be null)</param>
/// <param name="settings">The parsed settings</param> /// <param name="settings">The parsed settings</param>
[PublicAPI] [PublicAPI]
public static bool TryParseArguments([NotNull] string[] args, out IWireMockServerSettings settings, [CanBeNull] IWireMockLogger logger = null) public static bool TryParseArguments([NotNull] string[] args, out WireMockServerSettings settings, [CanBeNull] IWireMockLogger logger = null)
{ {
Guard.HasNoNulls(args, nameof(args)); Guard.HasNoNulls(args, nameof(args));
@@ -42,8 +42,8 @@ namespace WireMock.Settings
WatchStaticMappingsInSubdirectories = parser.GetBoolValue("WatchStaticMappingsInSubdirectories"), WatchStaticMappingsInSubdirectories = parser.GetBoolValue("WatchStaticMappingsInSubdirectories"),
AdminUsername = parser.GetStringValue("AdminUsername"), AdminUsername = parser.GetStringValue("AdminUsername"),
AdminPassword = parser.GetStringValue("AdminPassword"), AdminPassword = parser.GetStringValue("AdminPassword"),
AdminAzureADTenant = parser.GetStringValue(nameof(IWireMockServerSettings.AdminAzureADTenant)), AdminAzureADTenant = parser.GetStringValue(nameof(WireMockServerSettings.AdminAzureADTenant)),
AdminAzureADAudience = parser.GetStringValue(nameof(IWireMockServerSettings.AdminAzureADAudience)), AdminAzureADAudience = parser.GetStringValue(nameof(WireMockServerSettings.AdminAzureADAudience)),
MaxRequestLogCount = parser.GetIntValue("MaxRequestLogCount"), MaxRequestLogCount = parser.GetIntValue("MaxRequestLogCount"),
RequestLogExpirationDuration = parser.GetIntValue("RequestLogExpirationDuration"), RequestLogExpirationDuration = parser.GetIntValue("RequestLogExpirationDuration"),
AllowCSharpCodeMatcher = parser.GetBoolValue("AllowCSharpCodeMatcher"), AllowCSharpCodeMatcher = parser.GetBoolValue("AllowCSharpCodeMatcher"),
@@ -52,13 +52,13 @@ namespace WireMock.Settings
DisableJsonBodyParsing = parser.GetBoolValue("DisableJsonBodyParsing"), DisableJsonBodyParsing = parser.GetBoolValue("DisableJsonBodyParsing"),
HandleRequestsSynchronously = parser.GetBoolValue("HandleRequestsSynchronously"), HandleRequestsSynchronously = parser.GetBoolValue("HandleRequestsSynchronously"),
ThrowExceptionWhenMatcherFails = parser.GetBoolValue("ThrowExceptionWhenMatcherFails"), ThrowExceptionWhenMatcherFails = parser.GetBoolValue("ThrowExceptionWhenMatcherFails"),
UseRegexExtended = parser.GetBoolValue(nameof(IWireMockServerSettings.UseRegexExtended), true), UseRegexExtended = parser.GetBoolValue(nameof(WireMockServerSettings.UseRegexExtended), true),
SaveUnmatchedRequests = parser.GetBoolValue(nameof(IWireMockServerSettings.SaveUnmatchedRequests)), SaveUnmatchedRequests = parser.GetBoolValue(nameof(WireMockServerSettings.SaveUnmatchedRequests)),
}; };
#if USE_ASPNETCORE #if USE_ASPNETCORE
settings.CorsPolicyOptions = parser.GetValue( settings.CorsPolicyOptions = parser.GetValue(
nameof(IWireMockServerSettings.CorsPolicyOptions), values => nameof(WireMockServerSettings.CorsPolicyOptions), values =>
{ {
var value = string.Join(string.Empty, values); var value = string.Join(string.Empty, values);
return Enum.TryParse<CorsPolicyOptions>(value, true, out var corsPolicyOptions) ? corsPolicyOptions : CorsPolicyOptions.None; return Enum.TryParse<CorsPolicyOptions>(value, true, out var corsPolicyOptions) ? corsPolicyOptions : CorsPolicyOptions.None;

View File

@@ -11,7 +11,7 @@ namespace WireMock.Net.Tests.ResponseBuilders
{ {
public class ResponseWithStatusCodeTests public class ResponseWithStatusCodeTests
{ {
private readonly Mock<IWireMockServerSettings> _settingsMock = new Mock<IWireMockServerSettings>(); private readonly Mock<WireMockServerSettings> _settingsMock = new Mock<WireMockServerSettings>();
private const string ClientIp = "::1"; private const string ClientIp = "::1";
[Theory] [Theory]