From 3c22526905184c3943e7379c61a408500969a698 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Tue, 23 May 2017 21:56:53 +0200 Subject: [PATCH] Added some RestEase interfaces --- WireMock.Net Solution.sln | 9 +++- src/WireMock.Net.Client/Program.cs | 41 +++++++++++++++ .../WireMock.Net.Client.csproj | 18 +++++++ .../Client/IFluentMockServerAdmin.cs | 51 +++++++++++++++++++ src/WireMock.Net/WireMock.Net.csproj | 1 + 5 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 src/WireMock.Net.Client/Program.cs create mode 100644 src/WireMock.Net.Client/WireMock.Net.Client.csproj create mode 100644 src/WireMock.Net/Client/IFluentMockServerAdmin.cs diff --git a/WireMock.Net Solution.sln b/WireMock.Net Solution.sln index e26675b6..741353b0 100644 --- a/WireMock.Net Solution.sln +++ b/WireMock.Net Solution.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26403.7 +VisualStudioVersion = 15.0.26430.6 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{EF242EDF-7133-4277-9A0C-18744DE08707}" EndProject @@ -37,6 +37,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.Console.NETCor EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.Console.Record.NETCoreApp", "examples\WireMock.Net.Console.Record.NETCoreApp\WireMock.Net.Console.Record.NETCoreApp.csproj", "{1995E414-F197-4AB4-90C2-68D806B5AF59}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.Client", "src\WireMock.Net.Client\WireMock.Net.Client.csproj", "{058D4B6C-C03E-49D0-91DB-A535B058FA0D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -71,6 +73,10 @@ Global {1995E414-F197-4AB4-90C2-68D806B5AF59}.Debug|Any CPU.Build.0 = Debug|Any CPU {1995E414-F197-4AB4-90C2-68D806B5AF59}.Release|Any CPU.ActiveCfg = Release|Any CPU {1995E414-F197-4AB4-90C2-68D806B5AF59}.Release|Any CPU.Build.0 = Release|Any CPU + {058D4B6C-C03E-49D0-91DB-A535B058FA0D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {058D4B6C-C03E-49D0-91DB-A535B058FA0D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {058D4B6C-C03E-49D0-91DB-A535B058FA0D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {058D4B6C-C03E-49D0-91DB-A535B058FA0D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -83,5 +89,6 @@ Global {14D7298C-2BE5-42C3-A3D5-9433E77218F9} = {EF242EDF-7133-4277-9A0C-18744DE08707} {FE281639-B014-4C8A-96FA-141164A74713} = {F0C22C47-DF71-463C-9B04-B4E0F3B8708A} {1995E414-F197-4AB4-90C2-68D806B5AF59} = {F0C22C47-DF71-463C-9B04-B4E0F3B8708A} + {058D4B6C-C03E-49D0-91DB-A535B058FA0D} = {EF242EDF-7133-4277-9A0C-18744DE08707} EndGlobalSection EndGlobal diff --git a/src/WireMock.Net.Client/Program.cs b/src/WireMock.Net.Client/Program.cs new file mode 100644 index 00000000..93acddd2 --- /dev/null +++ b/src/WireMock.Net.Client/Program.cs @@ -0,0 +1,41 @@ +using Newtonsoft.Json; +using RestEase; +using System; +using System.Net.Http.Headers; +using System.Text; +using WireMock.Client; + +namespace WireMock.Net.Client +{ + class Program + { + static void Main(string[] args) + { + // Create an implementation of the IFluentMockServerAdmin and pass in the base URL for the API. + var api = RestClient.For("http://localhost:9090"); + + // Set BASIC Auth + var value = Convert.ToBase64String(Encoding.ASCII.GetBytes("a:b")); + api.Authorization = new AuthenticationHeaderValue("Basic", value); + + var settings1 = api.GetSettingsAsync().Result; + Console.WriteLine($"settings1 = {JsonConvert.SerializeObject(settings1)}"); + + settings1.GlobalProcessingDelay = 1077; + api.PostSettingsAsync(settings1).Wait(); + + var settings2 = api.GetSettingsAsync().Result; + Console.WriteLine($"settings2 = {JsonConvert.SerializeObject(settings2)}"); + + var mappings = api.GetMappingsAsync().Result; + Console.WriteLine($"mappings = {JsonConvert.SerializeObject(mappings)}"); + + var guid = Guid.Parse("11111110-a633-40e8-a244-5cb80bc0ab66"); + var mapping = api.GetMappingAsync(guid).Result; + Console.WriteLine($"mapping = {JsonConvert.SerializeObject(mapping)}"); + + Console.WriteLine("Press any key to quit"); + Console.ReadKey(); + } + } +} \ No newline at end of file diff --git a/src/WireMock.Net.Client/WireMock.Net.Client.csproj b/src/WireMock.Net.Client/WireMock.Net.Client.csproj new file mode 100644 index 00000000..168e85f2 --- /dev/null +++ b/src/WireMock.Net.Client/WireMock.Net.Client.csproj @@ -0,0 +1,18 @@ + + + + Exe + netcoreapp1.1 + ../../WireMock.Net-Logo.ico + + + + + + + + + + + + \ No newline at end of file diff --git a/src/WireMock.Net/Client/IFluentMockServerAdmin.cs b/src/WireMock.Net/Client/IFluentMockServerAdmin.cs new file mode 100644 index 00000000..4bb603b9 --- /dev/null +++ b/src/WireMock.Net/Client/IFluentMockServerAdmin.cs @@ -0,0 +1,51 @@ +using RestEase; +using System; +using System.Collections.Generic; +using System.Net.Http.Headers; +using System.Threading.Tasks; +using WireMock.Admin.Mappings; +using WireMock.Admin.Settings; + +namespace WireMock.Client +{ + /// + /// The RestEase interface which defines all admin commands. + /// + public interface IFluentMockServerAdmin + { + /// + /// Authentication header + /// + [Header("Authorization")] + AuthenticationHeaderValue Authorization { get; set; } + + /// + /// Get the settings. + /// + /// SettingsModel + [Get("__admin/settings")] + Task GetSettingsAsync(); + + /// + /// Post the settings + /// + /// SettingsModel + [Post("__admin/settings")] + Task PostSettingsAsync([Body] SettingsModel settings); + + /// + /// Get the mappings. + /// + /// MappingModels + [Get("__admin/mappings")] + Task> GetMappingsAsync(); + + /// + /// Get a mappings based on the guid + /// + /// The Guid + /// MappingModel + [Get("__admin/mappings/{guid}")] + Task GetMappingAsync([Path] Guid guid); + } +} \ No newline at end of file diff --git a/src/WireMock.Net/WireMock.Net.csproj b/src/WireMock.Net/WireMock.Net.csproj index beaef03e..a2d7a087 100644 --- a/src/WireMock.Net/WireMock.Net.csproj +++ b/src/WireMock.Net/WireMock.Net.csproj @@ -34,6 +34,7 @@ +