From 141ed5d96c1d8d305336d74c41ba4c9c030dc250 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Tue, 23 Jan 2018 08:06:55 +0100 Subject: [PATCH] code update --- examples/WireMock.Net.StandAlone.NETCoreApp/Program.cs | 10 +++++----- src/WireMock.Net/Http/PortUtil.cs | 7 ++----- src/WireMock.Net/Server/FluentMockServer.Admin.cs | 7 ++++--- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/examples/WireMock.Net.StandAlone.NETCoreApp/Program.cs b/examples/WireMock.Net.StandAlone.NETCoreApp/Program.cs index 5871bf0a..b3af5d9d 100644 --- a/examples/WireMock.Net.StandAlone.NETCoreApp/Program.cs +++ b/examples/WireMock.Net.StandAlone.NETCoreApp/Program.cs @@ -7,15 +7,15 @@ namespace WireMock.Net.StandAlone.NETCoreApp class Program { private static int sleepTime = 30000; - private static FluentMockServer server; + private static FluentMockServer _server; static void Main(string[] args) { - server = StandAloneApp.Start(args); + _server = StandAloneApp.Start(args); Console.WriteLine($"{DateTime.UtcNow} Press Ctrl+C to shut down"); - System.Console.CancelKeyPress += (s,e) => + Console.CancelKeyPress += (s, e) => { Stop("CancelKeyPress"); }; @@ -25,7 +25,7 @@ namespace WireMock.Net.StandAlone.NETCoreApp Stop("AssemblyLoadContext.Default.Unloading"); }; - while(true) + while (true) { Console.WriteLine($"{DateTime.UtcNow} WireMock.Net server running"); Thread.Sleep(sleepTime); @@ -35,7 +35,7 @@ namespace WireMock.Net.StandAlone.NETCoreApp private static void Stop(string why) { Console.WriteLine($"{DateTime.UtcNow} WireMock.Net server stopping because '{why}'"); - server.Stop(); + _server.Stop(); Console.WriteLine($"{DateTime.UtcNow} WireMock.Net server stopped"); } } diff --git a/src/WireMock.Net/Http/PortUtil.cs b/src/WireMock.Net/Http/PortUtil.cs index 0f101c75..4ebba7df 100644 --- a/src/WireMock.Net/Http/PortUtil.cs +++ b/src/WireMock.Net/Http/PortUtil.cs @@ -5,18 +5,15 @@ using System.Text.RegularExpressions; namespace WireMock.Http { /// - /// Utility class + /// Port Utility class /// public static class PortUtil { private static readonly Regex UrlDetailsRegex = new Regex(@"^(?\w+)://[^/]+?(?\d+)?/", RegexOptions.Compiled); /// - /// The find free TCP port. + /// Finds a free TCP port. /// - /// - /// The . - /// /// see http://stackoverflow.com/questions/138043/find-the-next-tcp-port-in-net. public static int FindFreeTcpPort() { diff --git a/src/WireMock.Net/Server/FluentMockServer.Admin.cs b/src/WireMock.Net/Server/FluentMockServer.Admin.cs index 21072672..e09747a6 100644 --- a/src/WireMock.Net/Server/FluentMockServer.Admin.cs +++ b/src/WireMock.Net/Server/FluentMockServer.Admin.cs @@ -29,6 +29,7 @@ namespace WireMock.Server public partial class FluentMockServer { private static readonly string AdminMappingsFolder = Path.Combine("__admin", "mappings"); + private const string ContentTypeJson = "application/json"; private const string AdminMappings = "/__admin/mappings"; private const string AdminRequests = "/__admin/requests"; private const string AdminSettings = "/__admin/settings"; @@ -86,12 +87,12 @@ namespace WireMock.Server { // __admin/settings Given(Request.Create().WithPath(AdminSettings).UsingGet()).RespondWith(new DynamicResponseProvider(SettingsGet)); - Given(Request.Create().WithPath(AdminSettings).UsingVerb("PUT", "POST").WithHeader("Content-Type", "application/json")).RespondWith(new DynamicResponseProvider(SettingsUpdate)); + Given(Request.Create().WithPath(AdminSettings).UsingVerb("PUT", "POST").WithHeader(HttpKnownHeaderNames.ContentType, ContentTypeJson)).RespondWith(new DynamicResponseProvider(SettingsUpdate)); // __admin/mappings Given(Request.Create().WithPath(AdminMappings).UsingGet()).RespondWith(new DynamicResponseProvider(MappingsGet)); - Given(Request.Create().WithPath(AdminMappings).UsingPost().WithHeader("Content-Type", "application/json")).RespondWith(new DynamicResponseProvider(MappingsPost)); + Given(Request.Create().WithPath(AdminMappings).UsingPost().WithHeader(HttpKnownHeaderNames.ContentType, ContentTypeJson)).RespondWith(new DynamicResponseProvider(MappingsPost)); Given(Request.Create().WithPath(AdminMappings).UsingDelete()).RespondWith(new DynamicResponseProvider(MappingsDelete)); // __admin/mappings/reset @@ -99,7 +100,7 @@ namespace WireMock.Server // __admin/mappings/{guid} Given(Request.Create().WithPath(_adminMappingsGuidPathMatcher).UsingGet()).RespondWith(new DynamicResponseProvider(MappingGet)); - Given(Request.Create().WithPath(_adminMappingsGuidPathMatcher).UsingPut().WithHeader("Content-Type", "application/json")).RespondWith(new DynamicResponseProvider(MappingPut)); + Given(Request.Create().WithPath(_adminMappingsGuidPathMatcher).UsingPut().WithHeader(HttpKnownHeaderNames.ContentType, ContentTypeJson)).RespondWith(new DynamicResponseProvider(MappingPut)); Given(Request.Create().WithPath(_adminMappingsGuidPathMatcher).UsingDelete()).RespondWith(new DynamicResponseProvider(MappingDelete)); // __admin/mappings/save