mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-21 08:59:50 +01:00
NET Core 2.1 + support for Service Fabric commandline parameters (#209)
* netcore 2.1 * SimpleCommandLineParserTests * tests * SimpleCommandLineParserTests * test report * AspNetCoreSelfHost * Fixed Resharper warnings * tests * . * ResponseWithProxyTests ResponseWithProxyTests * postmanecho
This commit is contained in:
6
src/WireMock.Net.StandAlone/Properties/AssemblyInfo.cs
Normal file
6
src/WireMock.Net.StandAlone/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("WireMock.Net.Tests")]
|
||||
|
||||
// Needed for Moq in the UnitTest project
|
||||
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
|
||||
@@ -7,24 +7,49 @@ namespace WireMock.Net.StandAlone
|
||||
// Based on http://blog.gauffin.org/2014/12/simple-command-line-parser/
|
||||
internal class SimpleCommandLineParser
|
||||
{
|
||||
private const string Sigil = "--";
|
||||
private const string SigilAzureServiceFabric = "'--";
|
||||
|
||||
private enum SigilType
|
||||
{
|
||||
Normal,
|
||||
AzureServiceFabric
|
||||
}
|
||||
|
||||
private IDictionary<string, string[]> Arguments { get; } = new Dictionary<string, string[]>();
|
||||
|
||||
public void Parse(string[] args)
|
||||
{
|
||||
SigilType sigil = SigilType.Normal;
|
||||
string currentName = null;
|
||||
|
||||
var values = new List<string>();
|
||||
foreach (string arg in args)
|
||||
{
|
||||
if (arg.StartsWith("--"))
|
||||
if (arg.StartsWith(Sigil))
|
||||
{
|
||||
sigil = SigilType.Normal;
|
||||
|
||||
if (!string.IsNullOrEmpty(currentName))
|
||||
{
|
||||
Arguments[currentName] = values.ToArray();
|
||||
}
|
||||
|
||||
values.Clear();
|
||||
currentName = arg.Substring(2);
|
||||
currentName = arg.Substring(Sigil.Length);
|
||||
}
|
||||
// Azure Service Fabric passes the command line parameter surrounded with single quotes. (https://github.com/Microsoft/service-fabric/issues/234)
|
||||
else if (arg.StartsWith(SigilAzureServiceFabric))
|
||||
{
|
||||
sigil = SigilType.AzureServiceFabric;
|
||||
|
||||
if (!string.IsNullOrEmpty(currentName))
|
||||
{
|
||||
Arguments[currentName] = values.ToArray();
|
||||
}
|
||||
|
||||
values.Clear();
|
||||
currentName = arg.Substring(SigilAzureServiceFabric.Length);
|
||||
}
|
||||
else if (string.IsNullOrEmpty(currentName))
|
||||
{
|
||||
@@ -32,7 +57,14 @@ namespace WireMock.Net.StandAlone
|
||||
}
|
||||
else
|
||||
{
|
||||
values.Add(arg);
|
||||
if (sigil == SigilType.Normal)
|
||||
{
|
||||
values.Add(arg);
|
||||
}
|
||||
else
|
||||
{
|
||||
values.Add(arg.Substring(0, arg.Length - 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace WireMock.Net.StandAlone
|
||||
StartAdminInterface = parser.GetBoolValue("StartAdminInterface", true),
|
||||
ReadStaticMappings = parser.GetBoolValue("ReadStaticMappings"),
|
||||
WatchStaticMappings = parser.GetBoolValue("WatchStaticMappings"),
|
||||
AllowPartialMapping = parser.GetBoolValue("AllowPartialMapping", true),
|
||||
AllowPartialMapping = parser.GetBoolValue("AllowPartialMapping", false),
|
||||
AdminUsername = parser.GetStringValue("AdminUsername"),
|
||||
AdminPassword = parser.GetStringValue("AdminPassword"),
|
||||
MaxRequestLogCount = parser.GetIntValue("MaxRequestLogCount"),
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<PropertyGroup>
|
||||
<Description>Lightweight StandAlone Http Mocking Server for .Net.</Description>
|
||||
<AssemblyTitle>WireMock.Net.StandAlone</AssemblyTitle>
|
||||
<Version>1.0.4.17</Version>
|
||||
<Version>1.0.4.18</Version>
|
||||
<Authors>Stef Heyenrath</Authors>
|
||||
<TargetFrameworks>net451;net452;net46;netstandard1.3;netstandard2.0</TargetFrameworks>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
|
||||
@@ -103,18 +103,18 @@ namespace WireMock.Owin
|
||||
#endif
|
||||
.Build();
|
||||
|
||||
return Task.Run(() =>
|
||||
{
|
||||
StartServers();
|
||||
}, _cts.Token);
|
||||
return RunHost(_cts.Token);
|
||||
}
|
||||
|
||||
private void StartServers()
|
||||
private Task RunHost(CancellationToken token)
|
||||
{
|
||||
try
|
||||
{
|
||||
var appLifetime = (IApplicationLifetime)_host.Services.GetService(typeof(IApplicationLifetime));
|
||||
appLifetime.ApplicationStarted.Register(() => IsStarted = true);
|
||||
appLifetime.ApplicationStarted.Register(() =>
|
||||
{
|
||||
IsStarted = true;
|
||||
});
|
||||
|
||||
#if NETSTANDARD1_3
|
||||
_logger.Info("WireMock.Net server using netstandard1.3");
|
||||
@@ -123,21 +123,23 @@ namespace WireMock.Owin
|
||||
#elif NET46
|
||||
_logger.Info("WireMock.Net server using .net 4.6.1 or higher");
|
||||
#endif
|
||||
|
||||
#if NETSTANDARD1_3
|
||||
_host.Run(_cts.Token);
|
||||
return Task.Run(() =>
|
||||
{
|
||||
_host.Run(token);
|
||||
});
|
||||
#else
|
||||
_host.RunAsync(_cts.Token).Wait();
|
||||
return _host.RunAsync(token);
|
||||
#endif
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_runningException = e;
|
||||
_logger.Error(e.ToString());
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
IsStarted = false;
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,14 +37,12 @@ namespace WireMock.Owin
|
||||
|
||||
return (bestPartialMatch?.Mapping, bestPartialMatch?.MatchResult);
|
||||
}
|
||||
else
|
||||
{
|
||||
var perfectMatch = mappings
|
||||
.OrderBy(m => m.Mapping.Priority)
|
||||
.FirstOrDefault(m => m.MatchResult.IsPerfectMatch);
|
||||
|
||||
return (perfectMatch?.Mapping, perfectMatch?.MatchResult);
|
||||
}
|
||||
var perfectMatch = mappings
|
||||
.OrderBy(m => m.Mapping.Priority)
|
||||
.FirstOrDefault(m => m.MatchResult.IsPerfectMatch);
|
||||
|
||||
return (perfectMatch?.Mapping, perfectMatch?.MatchResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ namespace WireMock.Owin
|
||||
Check.NotNull(options, nameof(options));
|
||||
Check.NotNull(requestMapper, nameof(requestMapper));
|
||||
Check.NotNull(responseMapper, nameof(responseMapper));
|
||||
Check.NotNull(mappingMatcher, nameof(mappingMatcher));
|
||||
|
||||
_options = options;
|
||||
_requestMapper = requestMapper;
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using WireMock.Handlers;
|
||||
using WireMock.Logging;
|
||||
@@ -24,10 +25,10 @@ namespace WireMock.Server
|
||||
/// </summary>
|
||||
public partial class FluentMockServer : IDisposable
|
||||
{
|
||||
private const int ServerStartDelayInMs = 100;
|
||||
|
||||
private readonly IWireMockLogger _logger;
|
||||
private readonly IFileSystemHandler _fileSystemHandler;
|
||||
|
||||
private const int ServerStartDelay = 100;
|
||||
private readonly IOwinSelfHost _httpServer;
|
||||
private readonly IWireMockMiddlewareOptions _options = new WireMockMiddlewareOptions();
|
||||
|
||||
@@ -231,7 +232,7 @@ namespace WireMock.Server
|
||||
throw new TimeoutException($"Service start timed out after {TimeSpan.FromMilliseconds(settings.StartTimeout)}");
|
||||
}
|
||||
|
||||
ctsStartTimeout.Token.WaitHandle.WaitOne(ServerStartDelay);
|
||||
ctsStartTimeout.Token.WaitHandle.WaitOne(ServerStartDelayInMs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<PropertyGroup>
|
||||
<Description>Lightweight Http Mocking Server for .Net, inspired by WireMock from the Java landscape.</Description>
|
||||
<AssemblyTitle>WireMock.Net</AssemblyTitle>
|
||||
<Version>1.0.4.17</Version>
|
||||
<Version>1.0.4.18</Version>
|
||||
<Authors>Stef Heyenrath</Authors>
|
||||
<TargetFrameworks>net451;net452;net46;net461;netstandard1.3;netstandard2.0</TargetFrameworks>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
|
||||
Reference in New Issue
Block a user