mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-18 07:13:46 +01:00
PreWireMockMiddlewareInit / PostWireMockMiddlewareInit
This commit is contained in:
@@ -46,7 +46,9 @@ namespace WireMock.Owin
|
||||
_host = new WebHostBuilder()
|
||||
.Configure(appBuilder =>
|
||||
{
|
||||
_options.PreWireMockMiddlewareInit?.Invoke(appBuilder);
|
||||
appBuilder.UseMiddleware<WireMockMiddleware>(_options);
|
||||
_options.PostWireMockMiddlewareInit?.Invoke(appBuilder);
|
||||
})
|
||||
.UseKestrel()
|
||||
.UseUrls(_uriPrefixes)
|
||||
|
||||
@@ -57,11 +57,13 @@ namespace WireMock.Owin
|
||||
|
||||
private void StartServers()
|
||||
{
|
||||
System.Console.WriteLine("WireMock.Net server using .net 4.5.x or .net 4.6.x");
|
||||
Console.WriteLine("WireMock.Net server using .net 4.5.x or .net 4.6.x");
|
||||
|
||||
Action<IAppBuilder> startup = app =>
|
||||
{
|
||||
_options.PreWireMockMiddlewareInit?.Invoke(app);
|
||||
app.Use<WireMockMiddleware>(_options);
|
||||
_options.PostWireMockMiddlewareInit?.Invoke(app);
|
||||
};
|
||||
|
||||
var servers = new List<IDisposable>();
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace WireMock.Owin
|
||||
RequestMatchResult requestMatchResult = null;
|
||||
try
|
||||
{
|
||||
foreach (var mapping in _options.Mappings.Where(m => m.Scenario != null))
|
||||
foreach (var mapping in _options.Mappings.Where(m => m?.Scenario != null))
|
||||
{
|
||||
// Set start
|
||||
if (!_options.Scenarios.ContainsKey(mapping.Scenario) && mapping.IsStartState)
|
||||
|
||||
@@ -4,6 +4,11 @@ using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Matchers;
|
||||
#if !NETSTANDARD
|
||||
using Owin;
|
||||
#else
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
#endif
|
||||
|
||||
namespace WireMock.Owin
|
||||
{
|
||||
@@ -24,5 +29,15 @@ namespace WireMock.Owin
|
||||
public int? MaxRequestLogCount { get; set; }
|
||||
|
||||
public IDictionary<string, object> Scenarios { get; } = new ConcurrentDictionary<string, object>();
|
||||
|
||||
#if !NETSTANDARD
|
||||
public Action<IAppBuilder> PreWireMockMiddlewareInit { get; set; }
|
||||
|
||||
public Action<IAppBuilder> PostWireMockMiddlewareInit { get; set; }
|
||||
#else
|
||||
public Action<IApplicationBuilder> PreWireMockMiddlewareInit { get; set; }
|
||||
|
||||
public Action<IApplicationBuilder> PostWireMockMiddlewareInit { get; set; }
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
namespace WireMock.ResponseBuilders
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the BodyDestinationFormat
|
||||
/// </summary>
|
||||
public static class BodyDestinationFormat
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -162,6 +162,9 @@ namespace WireMock.Server
|
||||
Urls = new[] { (settings.UseSSL == true ? "https" : "http") + "://localhost:" + port + "/" };
|
||||
}
|
||||
|
||||
_options.PreWireMockMiddlewareInit = settings.PreWireMockMiddlewareInit;
|
||||
_options.PostWireMockMiddlewareInit = settings.PostWireMockMiddlewareInit;
|
||||
|
||||
#if NETSTANDARD
|
||||
_httpServer = new AspNetCoreSelfHost(_options, Urls);
|
||||
#else
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
namespace WireMock.Settings
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace WireMock.Settings
|
||||
{
|
||||
/// <summary>
|
||||
/// FluentMockServerSettings
|
||||
@@ -8,76 +11,87 @@
|
||||
/// <summary>
|
||||
/// Gets or sets the port.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The port.
|
||||
/// </value>
|
||||
[PublicAPI]
|
||||
public int? Port { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the use SSL.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The use SSL.
|
||||
/// </value>
|
||||
// ReSharper disable once InconsistentNaming
|
||||
[PublicAPI]
|
||||
public bool? UseSSL { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the start admin interface.
|
||||
/// Gets or sets wether to start admin interface.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The start admin interface.
|
||||
/// </value>
|
||||
[PublicAPI]
|
||||
public bool? StartAdminInterface { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets if the static mappings should be read at startup.
|
||||
/// </summary>
|
||||
/// <value>true/false</value>
|
||||
[PublicAPI]
|
||||
public bool? ReadStaticMappings { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets if the server should record and save requests and responses.
|
||||
/// </summary>
|
||||
/// <value>true/false</value>
|
||||
[PublicAPI]
|
||||
public ProxyAndRecordSettings ProxyAndRecordSettings { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the urls.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The urls.
|
||||
/// </value>
|
||||
[PublicAPI]
|
||||
public string[] Urls { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// StartTimeout
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
public int StartTimeout { get; set; } = 10000;
|
||||
|
||||
/// <summary>
|
||||
/// Allow Partial Mapping (default set to false).
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
public bool? AllowPartialMapping { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The username needed for __admin access.
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
public string AdminUsername { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The password needed for __admin access.
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
public string AdminPassword { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The RequestLog expiration in hours (optional).
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
public int? RequestLogExpirationDuration { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The MaxRequestLog count (optional).
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
public int? MaxRequestLogCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Action which is called (with the IAppBuilder or IApplicationBuilder) before the internal WireMockMiddleware is initialized. [Optional]
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
public Action<object> PreWireMockMiddlewareInit { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Action which is called (with the IAppBuilder or IApplicationBuilder) after the internal WireMockMiddleware is initialized. [Optional]
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
public Action<object> PostWireMockMiddlewareInit { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user