mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-19 15:31:39 +02:00
Added some RestEase interfaces
This commit is contained in:
41
src/WireMock.Net.Client/Program.cs
Normal file
41
src/WireMock.Net.Client/Program.cs
Normal file
@@ -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<IFluentMockServerAdmin>("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();
|
||||
}
|
||||
}
|
||||
}
|
||||
18
src/WireMock.Net.Client/WireMock.Net.Client.csproj
Normal file
18
src/WireMock.Net.Client/WireMock.Net.Client.csproj
Normal file
@@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp1.1</TargetFramework>
|
||||
<ApplicationIcon>../../WireMock.Net-Logo.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="10.0.2" />
|
||||
<PackageReference Include="RestEase" Version="1.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\WireMock.Net\WireMock.Net.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
51
src/WireMock.Net/Client/IFluentMockServerAdmin.cs
Normal file
51
src/WireMock.Net/Client/IFluentMockServerAdmin.cs
Normal file
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// The RestEase interface which defines all admin commands.
|
||||
/// </summary>
|
||||
public interface IFluentMockServerAdmin
|
||||
{
|
||||
/// <summary>
|
||||
/// Authentication header
|
||||
/// </summary>
|
||||
[Header("Authorization")]
|
||||
AuthenticationHeaderValue Authorization { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Get the settings.
|
||||
/// </summary>
|
||||
/// <returns>SettingsModel</returns>
|
||||
[Get("__admin/settings")]
|
||||
Task<SettingsModel> GetSettingsAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Post the settings
|
||||
/// </summary>
|
||||
/// <param name="settings">SettingsModel</param>
|
||||
[Post("__admin/settings")]
|
||||
Task PostSettingsAsync([Body] SettingsModel settings);
|
||||
|
||||
/// <summary>
|
||||
/// Get the mappings.
|
||||
/// </summary>
|
||||
/// <returns>MappingModels</returns>
|
||||
[Get("__admin/mappings")]
|
||||
Task<IList<MappingModel>> GetMappingsAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Get a mappings based on the guid
|
||||
/// </summary>
|
||||
/// <param name="guid">The Guid</param>
|
||||
/// <returns>MappingModel</returns>
|
||||
[Get("__admin/mappings/{guid}")]
|
||||
Task<MappingModel> GetMappingAsync([Path] Guid guid);
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,7 @@
|
||||
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
|
||||
<PackageReference Include="SimMetrics.Net" Version="1.0.3" />
|
||||
<PackageReference Include="System.Net.Http" Version="4.3.2" />
|
||||
<PackageReference Include="RestEase" Version="1.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
|
||||
|
||||
Reference in New Issue
Block a user