Skip to content

Commit

Permalink
Update standalone commandline parsing (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
StefH committed May 13, 2017
1 parent 4ada6d3 commit 961e8b5
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 31 deletions.
15 changes: 15 additions & 0 deletions .axoCover/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"TestRunner": "",
"TestPlatform": "x86",
"TestApartmentState": "STA",
"TestSettings": "",
"ExcludeAttributes": "System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute",
"ExcludeFiles": "",
"ExcludeDirectories": "",
"Filters": "+[*]*",
"IsIncludingSolutionAssemblies": true,
"IsExcludingTestAssemblies": false,
"IsCoveringByTest": true,
"IsMergingByHash": true,
"IsSkippingAutoProps": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommandLineArgumentsParser" Version="3.0.9" />
<PackageReference Include="CommandLineArgumentsParser" Version="3.0.10" />
</ItemGroup>

<ItemGroup>
Expand Down
10 changes: 7 additions & 3 deletions examples/WireMock.Net.Console.Record.NETCoreApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ static class Program
{
static void Main(params string[] args)
{
string url1 = "http://localhost:9095/";
string url = "http://localhost:9095/";

var server = FluentMockServer.Start(new FluentMockServerSettings
{
Urls = new[] { url1 },
Urls = new[] { url },
StartAdminInterface = true,
ProxyAndRecordSettings = new ProxyAndRecordSettings { Url = "http://www.bbc.com" }
ProxyAndRecordSettings = new ProxyAndRecordSettings
{
Url = "http://www.bbc.com",
SaveMapping = true
}
});

System.Console.WriteLine("Press any key to stop the server");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommandLineArgumentsParser" Version="3.0.9" />
<PackageReference Include="CommandLineArgumentsParser" Version="3.0.10" />
</ItemGroup>

<ItemGroup>
Expand Down
30 changes: 23 additions & 7 deletions src/WireMock.Net.StandAlone.NETCoreApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,23 @@ class Program
{
private class Options
{
[ValueArgument(typeof(string), 'u', "Urls", Description = "URL(s) to listen on.", Optional = true, AllowMultiple = true)]
[ValueArgument(typeof(string), "Urls", Description = "URL(s) to listen on.", Optional = true, AllowMultiple = true)]
public List<string> Urls { get; set; }

[SwitchArgument('p', "AllowPartialMapping", true, Description = "Allow Partial Mapping (default set to true).", Optional = true)]
[SwitchArgument("AllowPartialMapping", true, Description = "Allow Partial Mapping (default set to true).", Optional = true)]
public bool AllowPartialMapping { get; set; }

[SwitchArgument('s', "StartAdminInterface", true, Description = "Start the AdminInterface (default set to true).", Optional = true)]
[SwitchArgument("StartAdminInterface", true, Description = "Start the AdminInterface (default set to true).", Optional = true)]
public bool StartAdminInterface { get; set; }

[SwitchArgument('r', "ReadStaticMappings", true, Description = "Read StaticMappings from ./__admin/mappings (default set to true).", Optional = true)]
[SwitchArgument("ReadStaticMappings", true, Description = "Read StaticMappings from ./__admin/mappings (default set to true).", Optional = true)]
public bool ReadStaticMappings { get; set; }

[ValueArgument(typeof(string), "ProxyURL", Description = "The ProxyURL to use.", Optional = true)]
public string ProxyURL { get; set; }

[SwitchArgument("SaveProxyMapping", false, Description = "Save the proxied request and response mapping files in ./__admin/mappings. (default set to false).", Optional = true)]
public bool SaveMapping { get; set; }
}

static void Main(string[] args)
Expand All @@ -40,13 +46,23 @@ static void Main(string[] args)
options.Urls.Add("http://localhost:9090/");
}

var server = FluentMockServer.Start(new FluentMockServerSettings
var settings = new FluentMockServerSettings
{
Urls = options.Urls.ToArray(),
StartAdminInterface = options.StartAdminInterface,
ReadStaticMappings = options.ReadStaticMappings
});
ReadStaticMappings = options.ReadStaticMappings,
};

if (!string.IsNullOrEmpty(options.ProxyURL))
{
settings.ProxyAndRecordSettings = new ProxyAndRecordSettings
{
Url = options.ProxyURL,
SaveMapping = options.SaveMapping
};
}

var server = FluentMockServer.Start(settings);
if (options.AllowPartialMapping)
{
server.AllowPartialMapping();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommandLineArgumentsParser" Version="3.0.9" />
<PackageReference Include="CommandLineArgumentsParser" Version="3.0.10" />
</ItemGroup>

<ItemGroup>
Expand Down
34 changes: 27 additions & 7 deletions src/WireMock.Net.StandAlone/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,23 @@ public class Program
{
private class Options
{
[ValueArgument(typeof(string), 'u', "Urls", Description = "URL(s) to listen on.", Optional = true, AllowMultiple = true)]
[ValueArgument(typeof(string), "Urls", Description = "URL(s) to listen on.", Optional = true, AllowMultiple = true)]
public List<string> Urls { get; set; }

[SwitchArgument('p', "AllowPartialMapping", true, Description = "Allow Partial Mapping (default set to true).", Optional = true)]
[SwitchArgument("AllowPartialMapping", true, Description = "Allow Partial Mapping (default set to true).", Optional = true)]
public bool AllowPartialMapping { get; set; }

[SwitchArgument('s', "StartAdminInterface", true, Description = "Start the AdminInterface (default set to true).", Optional = true)]
[SwitchArgument("StartAdminInterface", true, Description = "Start the AdminInterface (default set to true).", Optional = true)]
public bool StartAdminInterface { get; set; }

[SwitchArgument('r', "ReadStaticMappings", true, Description = "Read StaticMappings from ./__admin/mappings (default set to true).", Optional = true)]
[SwitchArgument("ReadStaticMappings", true, Description = "Read StaticMappings from ./__admin/mappings (default set to true).", Optional = true)]
public bool ReadStaticMappings { get; set; }

[ValueArgument(typeof(string), "ProxyURL", Description = "The ProxyURL to use.", Optional = true)]
public string ProxyURL { get; set; }

[SwitchArgument("SaveProxyMapping", false, Description = "Save the proxied request and response mapping files in ./__admin/mappings. (default set to false).", Optional = true)]
public bool SaveMapping { get; set; }
}

static void Main(params string[] args)
Expand All @@ -36,17 +42,31 @@ static void Main(params string[] args)
parser.ParseCommandLine(args);

if (!options.Urls.Any())
{
options.Urls.Add("http://localhost:9090/");
}

var server = FluentMockServer.Start(new FluentMockServerSettings
var settings = new FluentMockServerSettings
{
Urls = options.Urls.ToArray(),
StartAdminInterface = options.StartAdminInterface,
ReadStaticMappings = options.ReadStaticMappings
});
ReadStaticMappings = options.ReadStaticMappings,
};

if (!string.IsNullOrEmpty(options.ProxyURL))
{
settings.ProxyAndRecordSettings = new ProxyAndRecordSettings
{
Url = options.ProxyURL,
SaveMapping = options.SaveMapping
};
}

var server = FluentMockServer.Start(settings);
if (options.AllowPartialMapping)
{
server.AllowPartialMapping();
}

Console.WriteLine("WireMock.Net server listening at {0}", string.Join(" and ", server.Urls));
}
Expand Down
5 changes: 2 additions & 3 deletions src/WireMock.Net.StandAlone/WireMock.Net.StandAlone.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
<ApplicationIcon>..\..\WireMock.Net-Logo.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="CommandLineArgumentsParser, Version=3.0.9.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\CommandLineArgumentsParser.3.0.9\lib\net45\CommandLineArgumentsParser.dll</HintPath>
<Reference Include="CommandLineArgumentsParser, Version=3.0.10.0, Culture=neutral, PublicKeyToken=16ad7bf6f4a1666c, processorArchitecture=MSIL">
<HintPath>..\..\packages\CommandLineArgumentsParser.3.0.10\lib\net45\CommandLineArgumentsParser.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Owin.Host.HttpListener, Version=3.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Owin.Host.HttpListener.3.1.0\lib\net45\Microsoft.Owin.Host.HttpListener.dll</HintPath>
Expand All @@ -53,7 +53,6 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
3 changes: 0 additions & 3 deletions src/WireMock.Net.StandAlone/app.config

This file was deleted.

2 changes: 1 addition & 1 deletion src/WireMock.Net.StandAlone/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="CommandLineArgumentsParser" version="3.0.9" targetFramework="net452" />
<package id="CommandLineArgumentsParser" version="3.0.10" targetFramework="net452" />
<package id="Microsoft.Owin.Host.HttpListener" version="3.1.0" targetFramework="net452" />
</packages>
11 changes: 7 additions & 4 deletions src/WireMock.Net/Server/FluentMockServer.Admin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,21 @@ private void InitAdmin()
Given(Request.Create().WithPath(AdminRequests + "/find").UsingPost()).RespondWith(new DynamicResponseProvider(RequestsFind));
}

#region Proxy and Record
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);

var mapping = ToMapping(requestMessage, responseMessage);
SaveMappingToFile(mapping);
if (settings.SaveMapping)
{
var mapping = ToMapping(requestMessage, responseMessage);
SaveMappingToFile(mapping);
}

return responseMessage;
}
Expand Down

0 comments on commit 961e8b5

Please sign in to comment.