Initial code for proxy and record #27

This commit is contained in:
Stef Heyenrath
2017-05-09 21:43:10 +02:00
parent b25371cf15
commit 31261ec45d
14 changed files with 160 additions and 10 deletions

View File

@@ -16,6 +16,9 @@ using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
using WireMock.Util;
using WireMock.Validation;
using WireMock.Http;
using System.Threading.Tasks;
using WireMock.Settings;
namespace WireMock.Server
{
@@ -117,6 +120,20 @@ namespace WireMock.Server
Given(Request.Create().WithPath(AdminRequests + "/find").UsingPost()).RespondWith(new DynamicResponseProvider(RequestsFind));
}
private void InitProxyAndRecord(ProxyAndRecordSettings settings)
{
Given(Request.Create().WithPath("/*").UsingAnyVerb()).RespondWith(new ProxyAsyncResponseProvider(ProxyAndRecordAsync, settings));
}
#region Proxy and Record
private async Task<ResponseMessage> ProxyAndRecordAsync(RequestMessage requestMessage, ProxyAndRecordSettings settings)
{
var responseMessage = await HttpClientHelper.SendAsync(requestMessage, settings.Url);
return responseMessage;
}
#endregion
#region Settings
private ResponseMessage SettingsGet(RequestMessage requestMessage)
{

View File

@@ -9,6 +9,7 @@ using WireMock.Http;
using WireMock.Matchers;
using WireMock.Matchers.Request;
using WireMock.RequestBuilders;
using WireMock.Settings;
using WireMock.Validation;
using WireMock.Owin;
@@ -181,6 +182,11 @@ namespace WireMock.Server
{
ReadStaticMappings();
}
if (settings.ProxyAndRecordSettings != null)
{
InitProxyAndRecord(settings.ProxyAndRecordSettings);
}
}
/// <summary>
@@ -235,7 +241,7 @@ namespace WireMock.Server
{
lock (((ICollection)_options.Mappings).SyncRoot)
{
_options.Mappings = _options.Mappings.Where(m => m.Provider is DynamicResponseProvider).ToList();
_options.Mappings = _options.Mappings.Where(m => m.IsAdminInterface).ToList();
}
}

View File

@@ -1,54 +0,0 @@
namespace WireMock.Server
{
/// <summary>
/// FluentMockServerSettings
/// </summary>
public class FluentMockServerSettings
{
/// <summary>
/// Gets or sets the port.
/// </summary>
/// <value>
/// The port.
/// </value>
public int? Port { get; set; }
/// <summary>
/// Gets or sets the use SSL.
/// </summary>
/// <value>
/// The use SSL.
/// </value>
// ReSharper disable once InconsistentNaming
public bool? UseSSL { get; set; }
/// <summary>
/// Gets or sets the start admin interface.
/// </summary>
/// <value>
/// The start admin interface.
/// </value>
public bool? StartAdminInterface { get; set; }
/// <summary>
/// Gets or sets the read static mappings.
/// </summary>
/// <value>
/// The read static mappings.
/// </value>
public bool? ReadStaticMappings { get; set; }
/// <summary>
/// Gets or sets the urls.
/// </summary>
/// <value>
/// The urls.
/// </value>
public string[] Urls { get; set; }
/// <summary>
/// StartTimeout
/// </summary>
public int StartTimeout { get; set; } = 10000;
}
}

View File

@@ -1,4 +1,5 @@
using System;
using System.Threading.Tasks;
namespace WireMock.Server
{
@@ -38,9 +39,13 @@ namespace WireMock.Server
/// <summary>
/// The respond with.
/// </summary>
/// <param name="provider">
/// The provider.
/// </param>
/// <param name="provider">The provider.</param>
void RespondWith(IResponseProvider provider);
///// <summary>
///// The respond with.
///// </summary>
///// <param name="provider">The provider.</param>
//Task RespondWithAsync(IResponseProvider provider);
}
}