mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-18 15:10:17 +02:00
AdminApiMappingBuilder (#890)
* AdminApiMappingBuilder * . * IWireMockAdminApi * add methods * .
This commit is contained in:
@@ -1,78 +1,125 @@
|
|||||||
using Newtonsoft.Json;
|
|
||||||
using RestEase;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using RestEase;
|
||||||
using WireMock.Admin.Settings;
|
using WireMock.Admin.Settings;
|
||||||
using WireMock.Client;
|
using WireMock.Client;
|
||||||
|
using WireMock.Client.Extensions;
|
||||||
|
|
||||||
namespace WireMock.Net.Client
|
namespace WireMock.Net.Client;
|
||||||
|
|
||||||
|
class Program
|
||||||
{
|
{
|
||||||
class Program
|
static async Task Main(string[] args)
|
||||||
{
|
{
|
||||||
static async Task Main(string[] args)
|
// Create an implementation of the IWireMockAdminApi and pass in the base URL for the API.
|
||||||
|
var api = RestClient.For<IWireMockAdminApi>("http://localhost:9091");
|
||||||
|
|
||||||
|
// await api.ResetMappingsAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
|
var mappingBuilder = api.GetMappingBuilder();
|
||||||
|
mappingBuilder.Given(m => m
|
||||||
|
.WithTitle("This is my title 1")
|
||||||
|
.WithRequest(req => req
|
||||||
|
.UsingGet()
|
||||||
|
.WithPath("/bla1")
|
||||||
|
)
|
||||||
|
.WithResponse(rsp => rsp
|
||||||
|
.WithBody("x1")
|
||||||
|
.WithHeaders(h => h.Add("h1", "v1"))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
mappingBuilder.Given(m => m
|
||||||
|
.WithTitle("This is my title 2")
|
||||||
|
.WithRequest(req => req
|
||||||
|
.UsingGet()
|
||||||
|
.WithPath("/bla2")
|
||||||
|
)
|
||||||
|
.WithResponse(rsp => rsp
|
||||||
|
.WithBody("x2")
|
||||||
|
.WithHeaders(h => h.Add("h2", "v2"))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
mappingBuilder.Given(m => m
|
||||||
|
.WithTitle("This is my title 3")
|
||||||
|
.WithRequest(req => req
|
||||||
|
.UsingGet()
|
||||||
|
.WithPath("/bla3")
|
||||||
|
)
|
||||||
|
.WithResponse(rsp => rsp
|
||||||
|
.WithBodyAsJson(new
|
||||||
|
{
|
||||||
|
x = "test"
|
||||||
|
}, true)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
var result = await mappingBuilder.BuildAndPostAsync().ConfigureAwait(false);
|
||||||
|
Console.WriteLine($"result = {JsonConvert.SerializeObject(result)}");
|
||||||
|
|
||||||
|
var mappings = await api.GetMappingsAsync();
|
||||||
|
Console.WriteLine($"mappings = {JsonConvert.SerializeObject(mappings)}");
|
||||||
|
|
||||||
|
// Set BASIC Auth
|
||||||
|
var value = Convert.ToBase64String(Encoding.ASCII.GetBytes("a:b"));
|
||||||
|
api.Authorization = new AuthenticationHeaderValue("Basic", value);
|
||||||
|
|
||||||
|
var settings1 = await api.GetSettingsAsync();
|
||||||
|
Console.WriteLine($"settings1 = {JsonConvert.SerializeObject(settings1)}");
|
||||||
|
|
||||||
|
var settingsViaBuilder = new SettingsModelBuilder()
|
||||||
|
.WithGlobalProcessingDelay(1077)
|
||||||
|
.WithoutGlobalProcessingDelay()
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
settings1.GlobalProcessingDelay = 1077;
|
||||||
|
api.PostSettingsAsync(settings1).Wait();
|
||||||
|
|
||||||
|
var settings2 = await api.GetSettingsAsync();
|
||||||
|
Console.WriteLine($"settings2 = {JsonConvert.SerializeObject(settings2)}");
|
||||||
|
|
||||||
|
mappings = await api.GetMappingsAsync();
|
||||||
|
Console.WriteLine($"mappings = {JsonConvert.SerializeObject(mappings)}");
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
// Create an implementation of the IWireMockAdminApi and pass in the base URL for the API.
|
var guid = Guid.Parse("11111110-a633-40e8-a244-5cb80bc0ab66");
|
||||||
var api = RestClient.For<IWireMockAdminApi>("http://localhost:9091");
|
var mapping = await api.GetMappingAsync(guid);
|
||||||
|
Console.WriteLine($"mapping = {JsonConvert.SerializeObject(mapping)}");
|
||||||
// Set BASIC Auth
|
|
||||||
var value = Convert.ToBase64String(Encoding.ASCII.GetBytes("a:b"));
|
|
||||||
api.Authorization = new AuthenticationHeaderValue("Basic", value);
|
|
||||||
|
|
||||||
var settings1 = await api.GetSettingsAsync();
|
|
||||||
Console.WriteLine($"settings1 = {JsonConvert.SerializeObject(settings1)}");
|
|
||||||
|
|
||||||
var settingsViaBuilder = new SettingsModelBuilder()
|
|
||||||
.WithGlobalProcessingDelay(1077)
|
|
||||||
.WithoutGlobalProcessingDelay()
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
settings1.GlobalProcessingDelay = 1077;
|
|
||||||
api.PostSettingsAsync(settings1).Wait();
|
|
||||||
|
|
||||||
var settings2 = await api.GetSettingsAsync();
|
|
||||||
Console.WriteLine($"settings2 = {JsonConvert.SerializeObject(settings2)}");
|
|
||||||
|
|
||||||
var mappings = await api.GetMappingsAsync();
|
|
||||||
Console.WriteLine($"mappings = {JsonConvert.SerializeObject(mappings)}");
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var guid = Guid.Parse("11111110-a633-40e8-a244-5cb80bc0ab66");
|
|
||||||
var mapping = await api.GetMappingAsync(guid);
|
|
||||||
Console.WriteLine($"mapping = {JsonConvert.SerializeObject(mapping)}");
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
var request = await api.GetRequestsAsync();
|
|
||||||
Console.WriteLine($"request = {JsonConvert.SerializeObject(request)}");
|
|
||||||
|
|
||||||
//var deleteRequestsAsync = api.DeleteRequestsAsync().Result;
|
|
||||||
//Console.WriteLine($"DeleteRequestsAsync = {deleteRequestsAsync.Status}");
|
|
||||||
|
|
||||||
//var resetRequestsAsync = api.ResetRequestsAsync().Result;
|
|
||||||
//Console.WriteLine($"ResetRequestsAsync = {resetRequestsAsync.Status}");
|
|
||||||
|
|
||||||
var scenarioStates = await api.GetScenariosAsync();
|
|
||||||
Console.WriteLine($"GetScenariosAsync = {JsonConvert.SerializeObject(scenarioStates)}");
|
|
||||||
|
|
||||||
var postFileResult = await api.PostFileAsync("1.cs", "C# Hello");
|
|
||||||
Console.WriteLine($"postFileResult = {JsonConvert.SerializeObject(postFileResult)}");
|
|
||||||
|
|
||||||
var getFileResult = await api.GetFileAsync("1.cs");
|
|
||||||
Console.WriteLine($"getFileResult = {getFileResult}");
|
|
||||||
|
|
||||||
var resetMappingsAsync = await api.ResetMappingsAsync();
|
|
||||||
Console.WriteLine($"resetMappingsAsync = {resetMappingsAsync.Status}");
|
|
||||||
|
|
||||||
var resetMappingsAndReloadStaticMappingsAsync = await api.ResetMappingsAsync(true);
|
|
||||||
Console.WriteLine($"resetMappingsAndReloadStaticMappingsAsync = {resetMappingsAndReloadStaticMappingsAsync.Status}");
|
|
||||||
|
|
||||||
Console.WriteLine("Press any key to quit");
|
|
||||||
Console.ReadKey();
|
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
var request = await api.GetRequestsAsync();
|
||||||
|
Console.WriteLine($"request = {JsonConvert.SerializeObject(request)}");
|
||||||
|
|
||||||
|
//var deleteRequestsAsync = api.DeleteRequestsAsync().Result;
|
||||||
|
//Console.WriteLine($"DeleteRequestsAsync = {deleteRequestsAsync.Status}");
|
||||||
|
|
||||||
|
//var resetRequestsAsync = api.ResetRequestsAsync().Result;
|
||||||
|
//Console.WriteLine($"ResetRequestsAsync = {resetRequestsAsync.Status}");
|
||||||
|
|
||||||
|
var scenarioStates = await api.GetScenariosAsync();
|
||||||
|
Console.WriteLine($"GetScenariosAsync = {JsonConvert.SerializeObject(scenarioStates)}");
|
||||||
|
|
||||||
|
var postFileResult = await api.PostFileAsync("1.cs", "C# Hello");
|
||||||
|
Console.WriteLine($"postFileResult = {JsonConvert.SerializeObject(postFileResult)}");
|
||||||
|
|
||||||
|
var getFileResult = await api.GetFileAsync("1.cs");
|
||||||
|
Console.WriteLine($"getFileResult = {getFileResult}");
|
||||||
|
|
||||||
|
var resetMappingsAsync = await api.ResetMappingsAsync();
|
||||||
|
Console.WriteLine($"resetMappingsAsync = {resetMappingsAsync.Status}");
|
||||||
|
|
||||||
|
var resetMappingsAndReloadStaticMappingsAsync = await api.ResetMappingsAsync(true);
|
||||||
|
Console.WriteLine($"resetMappingsAndReloadStaticMappingsAsync = {resetMappingsAndReloadStaticMappingsAsync.Status}");
|
||||||
|
|
||||||
|
Console.WriteLine("Press any key to quit");
|
||||||
|
Console.ReadKey();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,19 +1,13 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
<ApplicationIcon>../../resources/WireMock.Net-Logo.ico</ApplicationIcon>
|
<ApplicationIcon>../../resources/WireMock.Net-Logo.ico</ApplicationIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
<ProjectReference Include="..\..\src\WireMock.Net.RestClient\WireMock.Net.RestClient.csproj" />
|
||||||
<PackageReference Include="RestEase" Version="1.5.7" />
|
</ItemGroup>
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\..\src\WireMock.Net.Abstractions\WireMock.Net.Abstractions.csproj" />
|
|
||||||
<ProjectReference Include="..\..\src\WireMock.Net.RestClient\WireMock.Net.RestClient.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
@@ -0,0 +1,139 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
// ReSharper disable once CheckNamespace
|
||||||
|
namespace WireMock.Admin.Mappings;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// RequestModelBuilder
|
||||||
|
/// </summary>
|
||||||
|
public partial class RequestModelBuilder
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// UsingConnect: add HTTP Method matching on `CONNECT`.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The <see cref="RequestModelBuilder"/>.</returns>
|
||||||
|
public RequestModelBuilder UsingConnect() => WithMethods("CONNECT");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// UsingDelete: add HTTP Method matching on `DELETE`.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The <see cref="RequestModelBuilder"/>.</returns>
|
||||||
|
public RequestModelBuilder UsingDelete() => WithMethods("DELETE");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// UsingGet: add HTTP Method matching on `GET`.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The <see cref="RequestModelBuilder"/>.</returns>
|
||||||
|
public RequestModelBuilder UsingGet() => WithMethods("GET");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// UsingHead: Add HTTP Method matching on `HEAD`.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The <see cref="RequestModelBuilder"/>.</returns>
|
||||||
|
public RequestModelBuilder UsingHead() => WithMethods("HEAD");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// UsingPost: add HTTP Method matching on `POST`.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The <see cref="RequestModelBuilder"/>.</returns>
|
||||||
|
public RequestModelBuilder UsingPost() => WithMethods("POST");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// UsingPatch: add HTTP Method matching on `PATCH`.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The <see cref="RequestModelBuilder"/>.</returns>
|
||||||
|
public RequestModelBuilder UsingPatch() => WithMethods("PATCH");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// UsingPut: add HTTP Method matching on `OPTIONS`.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The <see cref="RequestModelBuilder"/>.</returns>
|
||||||
|
public RequestModelBuilder UsingOptions() => WithMethods("OPTIONS");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// UsingPut: add HTTP Method matching on `PUT`.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The <see cref="RequestModelBuilder"/>.</returns>
|
||||||
|
public RequestModelBuilder UsingPut() => WithMethods("PUT");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// UsingTrace: add HTTP Method matching on `TRACE`.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The <see cref="RequestModelBuilder"/>.</returns>
|
||||||
|
public RequestModelBuilder UsingTrace() => WithMethods("TRACE");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// UsingAnyMethod: add HTTP Method matching on any method.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The <see cref="RequestModelBuilder"/>.</returns>
|
||||||
|
public RequestModelBuilder UsingAnyMethod() => this;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Set the ClientIP.
|
||||||
|
/// </summary>
|
||||||
|
public RequestModelBuilder WithClientIP(string value) => WithClientIP(() => value);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Set the ClientIP.
|
||||||
|
/// </summary>
|
||||||
|
public RequestModelBuilder WithClientIP(ClientIPModel value) => WithClientIP(() => value);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Set the ClientIP.
|
||||||
|
/// </summary>
|
||||||
|
public RequestModelBuilder WithClientIP(Action<ClientIPModelBuilder> action)
|
||||||
|
{
|
||||||
|
return WithClientIP(() =>
|
||||||
|
{
|
||||||
|
var builder = new ClientIPModelBuilder();
|
||||||
|
action(builder);
|
||||||
|
return builder.Build();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Set the Path.
|
||||||
|
/// </summary>
|
||||||
|
public RequestModelBuilder WithPath(string value) => WithPath(() => value);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Set the Path.
|
||||||
|
/// </summary>
|
||||||
|
public RequestModelBuilder WithPath(PathModel value) => WithPath(() => value);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Set the Path.
|
||||||
|
/// </summary>
|
||||||
|
public RequestModelBuilder WithPath(Action<PathModelBuilder> action)
|
||||||
|
{
|
||||||
|
return WithPath(() =>
|
||||||
|
{
|
||||||
|
var builder = new PathModelBuilder();
|
||||||
|
action(builder);
|
||||||
|
return builder.Build();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Set the Url.
|
||||||
|
/// </summary>
|
||||||
|
public RequestModelBuilder WithUrl(string value) => WithUrl(() => value);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Set the Url.
|
||||||
|
/// </summary>
|
||||||
|
public RequestModelBuilder WithUrl(UrlModel value) => WithUrl(() => value);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Set the Url.
|
||||||
|
/// </summary>
|
||||||
|
public RequestModelBuilder WithUrl(Action<UrlModelBuilder> action)
|
||||||
|
{
|
||||||
|
return WithUrl(() =>
|
||||||
|
{
|
||||||
|
var builder = new UrlModelBuilder();
|
||||||
|
action(builder);
|
||||||
|
return builder.Build();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
using System;
|
||||||
|
using System.Net;
|
||||||
|
|
||||||
|
// ReSharper disable once CheckNamespace
|
||||||
|
namespace WireMock.Admin.Mappings;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ResponseModelBuilder
|
||||||
|
/// </summary>
|
||||||
|
public partial class ResponseModelBuilder
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Set the StatusCode.
|
||||||
|
/// </summary>
|
||||||
|
public ResponseModelBuilder WithStatusCode(int value) => WithStatusCode(() => value);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Set the StatusCode.
|
||||||
|
/// </summary>
|
||||||
|
public ResponseModelBuilder WithStatusCode(HttpStatusCode value) => WithStatusCode(() => value);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Set the Delay.
|
||||||
|
/// </summary>
|
||||||
|
public ResponseModelBuilder WithDelay(TimeSpan value) => WithDelay((int) value.TotalMilliseconds);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Set the MinimumRandomDelay.
|
||||||
|
/// </summary>
|
||||||
|
public ResponseModelBuilder WithMinimumRandomDelay(TimeSpan value) => WithMinimumRandomDelay((int)value.TotalMilliseconds);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Set the MaximumRandomDelay.
|
||||||
|
/// </summary>
|
||||||
|
public ResponseModelBuilder WithMaximumRandomDelay(TimeSpan value) => WithMaximumRandomDelay((int)value.TotalMilliseconds);
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Stef.Validation;
|
||||||
|
using WireMock.Admin.Mappings;
|
||||||
|
|
||||||
|
namespace WireMock.Client.Builders;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// AdminApiMappingBuilder
|
||||||
|
/// </summary>
|
||||||
|
public class AdminApiMappingBuilder
|
||||||
|
{
|
||||||
|
private readonly List<Action<MappingModelBuilder>> _mappingModelBuilderActions = new();
|
||||||
|
|
||||||
|
private readonly IWireMockAdminApi _api;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// AdminApiMappingBuilder
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="api">The <see cref="IWireMockAdminApi"/>.</param>
|
||||||
|
public AdminApiMappingBuilder(IWireMockAdminApi api)
|
||||||
|
{
|
||||||
|
_api = Guard.NotNull(api);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Given
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="mappingModelBuilderAction">The action.</param>
|
||||||
|
public void Given(Action<MappingModelBuilder> mappingModelBuilderAction)
|
||||||
|
{
|
||||||
|
_mappingModelBuilderActions.Add(Guard.NotNull(mappingModelBuilderAction));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Build the mappings and post these using the <see cref="IWireMockAdminApi"/> to the WireMock.Net server.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cancellationToken">The optional CancellationToken.</param>
|
||||||
|
/// <returns><see cref="StatusModel"/></returns>
|
||||||
|
public Task<StatusModel> BuildAndPostAsync(CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
var modelMappings = new List<MappingModel>();
|
||||||
|
|
||||||
|
foreach (var mappingModelBuilderAction in _mappingModelBuilderActions)
|
||||||
|
{
|
||||||
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
|
var mappingModelBuilder = new MappingModelBuilder();
|
||||||
|
mappingModelBuilderAction(mappingModelBuilder);
|
||||||
|
|
||||||
|
modelMappings.Add(mappingModelBuilder.Build());
|
||||||
|
}
|
||||||
|
|
||||||
|
return _api.PostMappingsAsync(modelMappings, cancellationToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
using System.Text;
|
||||||
|
using JsonConverter.Abstractions;
|
||||||
|
using JsonConverter.Newtonsoft.Json;
|
||||||
|
using WireMock.Admin.Mappings;
|
||||||
|
|
||||||
|
namespace WireMock.Client.Extensions;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ResponseModelBuilder
|
||||||
|
/// </summary>
|
||||||
|
public static class ResponseModelBuilderExtensions
|
||||||
|
{
|
||||||
|
private static readonly Encoding Utf8NoBom = new UTF8Encoding(false);
|
||||||
|
private static readonly IJsonConverter JsonConverter = new NewtonsoftJsonConverter();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// WithBodyAsJson
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="builder">The ResponseModelBuilder.</param>
|
||||||
|
/// <param name="body">The body.</param>
|
||||||
|
/// <param name="encoding">The body encoding.</param>
|
||||||
|
/// <param name="indented">Define whether child objects to be indented.</param>
|
||||||
|
public static ResponseModelBuilder WithBodyAsJson(this ResponseModelBuilder builder, object body, Encoding? encoding = null, bool? indented = null)
|
||||||
|
{
|
||||||
|
return builder.WithBodyAsBytes(() =>
|
||||||
|
{
|
||||||
|
var options = new JsonConverterOptions
|
||||||
|
{
|
||||||
|
WriteIndented = indented == true
|
||||||
|
};
|
||||||
|
var jsonBody = JsonConverter.Serialize(body, options);
|
||||||
|
return (encoding ?? Utf8NoBom).GetBytes(jsonBody);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// WithBodyAsJson
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="builder">The ResponseModelBuilder.</param>
|
||||||
|
/// <param name="body">The body.</param>
|
||||||
|
/// <param name="indented">Define whether child objects to be indented.</param>
|
||||||
|
public static ResponseModelBuilder WithBodyAsJson(this ResponseModelBuilder builder, object body, bool indented)
|
||||||
|
{
|
||||||
|
return builder.WithBodyAsJson(body, null, indented);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
using WireMock.Client.Builders;
|
||||||
|
|
||||||
|
namespace WireMock.Client.Extensions;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Some extensions for <see cref="IWireMockAdminApi"/>.
|
||||||
|
/// </summary>
|
||||||
|
public static class WireMockAdminApiExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Get a new <see cref="AdminApiMappingBuilder"/> for the <see cref="IWireMockAdminApi"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="api">See <see cref="IWireMockAdminApi"/>.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static AdminApiMappingBuilder GetMappingBuilder(this IWireMockAdminApi api)
|
||||||
|
{
|
||||||
|
return new AdminApiMappingBuilder(api);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,250 +1,283 @@
|
|||||||
using RestEase;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using RestEase;
|
||||||
using WireMock.Admin.Mappings;
|
using WireMock.Admin.Mappings;
|
||||||
using WireMock.Admin.Requests;
|
using WireMock.Admin.Requests;
|
||||||
using WireMock.Admin.Scenarios;
|
using WireMock.Admin.Scenarios;
|
||||||
using WireMock.Admin.Settings;
|
using WireMock.Admin.Settings;
|
||||||
using WireMock.Types;
|
using WireMock.Types;
|
||||||
|
|
||||||
namespace WireMock.Client
|
namespace WireMock.Client;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The RestEase interface which defines all admin commands.
|
||||||
|
/// </summary>
|
||||||
|
[BasePath("__admin")]
|
||||||
|
public interface IWireMockAdminApi
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The RestEase interface which defines all admin commands.
|
/// Authentication header
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[BasePath("__admin")]
|
[Header("Authorization")]
|
||||||
public interface IWireMockAdminApi
|
AuthenticationHeaderValue Authorization { get; set; }
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Authentication header
|
|
||||||
/// </summary>
|
|
||||||
[Header("Authorization")]
|
|
||||||
AuthenticationHeaderValue Authorization { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the settings.
|
/// Get the settings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>SettingsModel</returns>
|
/// <returns>SettingsModel</returns>
|
||||||
[Get("settings")]
|
[Get("settings")]
|
||||||
Task<SettingsModel> GetSettingsAsync();
|
Task<SettingsModel> GetSettingsAsync();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Update the settings.
|
/// Update the settings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="settings">SettingsModel</param>
|
/// <param name="settings">SettingsModel</param>
|
||||||
[Put("settings")]
|
/// <param name="cancellationToken">The optional cancellationToken.</param>
|
||||||
[Header("Content-Type", "application/json")]
|
[Put("settings")]
|
||||||
Task<StatusModel> PutSettingsAsync([Body] SettingsModel settings);
|
[Header("Content-Type", "application/json")]
|
||||||
|
Task<StatusModel> PutSettingsAsync([Body] SettingsModel settings, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Update the settings
|
/// Update the settings
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="settings">SettingsModel</param>
|
/// <param name="settings">SettingsModel</param>
|
||||||
[Post("settings")]
|
/// <param name="cancellationToken">The optional cancellationToken.</param>
|
||||||
[Header("Content-Type", "application/json")]
|
[Post("settings")]
|
||||||
Task<StatusModel> PostSettingsAsync([Body] SettingsModel settings);
|
[Header("Content-Type", "application/json")]
|
||||||
|
Task<StatusModel> PostSettingsAsync([Body] SettingsModel settings, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the mappings.
|
/// Get the mappings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>MappingModels</returns>
|
/// <returns>MappingModels</returns>
|
||||||
[Get("mappings")]
|
/// <param name="cancellationToken">The optional cancellationToken.</param>
|
||||||
Task<IList<MappingModel>> GetMappingsAsync();
|
[Get("mappings")]
|
||||||
|
Task<IList<MappingModel>> GetMappingsAsync(CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the C# code from all mappings
|
/// Get the C# code from all mappings
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>C# code</returns>
|
/// <returns>C# code</returns>
|
||||||
[Get("mappings/code")]
|
/// <param name="mappingConverterType">The <see cref="MappingConverterType"/>, default is Server.</param>
|
||||||
Task<string> GetMappingsCodeAsync([Query] MappingConverterType mappingConverterType = MappingConverterType.Server);
|
/// <param name="cancellationToken">The optional cancellationToken.</param>
|
||||||
|
[Get("mappings/code")]
|
||||||
/// <summary>
|
Task<string> GetMappingsCodeAsync([Query] MappingConverterType mappingConverterType = MappingConverterType.Server, CancellationToken cancellationToken = default);
|
||||||
/// Add a new mapping.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="mapping">MappingModel</param>
|
|
||||||
[Post("mappings")]
|
|
||||||
[Header("Content-Type", "application/json")]
|
|
||||||
Task<StatusModel> PostMappingAsync([Body] MappingModel mapping);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add new mappings.
|
/// Add a new mapping.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="mappings">MappingModels</param>
|
/// <param name="mapping">MappingModel</param>
|
||||||
[Post("mappings")]
|
/// <param name="cancellationToken">The optional cancellationToken.</param>
|
||||||
[Header("Content-Type", "application/json")]
|
[Post("mappings")]
|
||||||
Task<StatusModel> PostMappingsAsync([Body] IList<MappingModel> mappings);
|
[Header("Content-Type", "application/json")]
|
||||||
|
Task<StatusModel> PostMappingAsync([Body] MappingModel mapping, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Delete all mappings.
|
/// Add new mappings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Delete("mappings")]
|
/// <param name="mappings">MappingModels</param>
|
||||||
Task<StatusModel> DeleteMappingsAsync();
|
/// <param name="cancellationToken">The optional cancellationToken.</param>
|
||||||
|
[Post("mappings")]
|
||||||
|
[Header("Content-Type", "application/json")]
|
||||||
|
Task<StatusModel> PostMappingsAsync([Body] IList<MappingModel> mappings, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Delete mappings according to GUIDs
|
/// Delete all mappings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="mappings">MappingModels</param>
|
/// <param name="cancellationToken">The optional cancellationToken.</param>
|
||||||
[Delete("mappings")]
|
[Delete("mappings")]
|
||||||
[Header("Content-Type", "application/json")]
|
Task<StatusModel> DeleteMappingsAsync(CancellationToken cancellationToken = default);
|
||||||
Task<StatusModel> DeleteMappingsAsync([Body] IList<MappingModel> mappings);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Delete (reset) all mappings.
|
/// Delete mappings according to GUIDs
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="reloadStaticMappings">A value indicating whether to reload the static mappings after the reset.</param>
|
/// <param name="mappings">MappingModels</param>
|
||||||
[Post("mappings/reset")]
|
/// <param name="cancellationToken">The optional cancellationToken.</param>
|
||||||
Task<StatusModel> ResetMappingsAsync(bool? reloadStaticMappings = false);
|
[Delete("mappings")]
|
||||||
|
[Header("Content-Type", "application/json")]
|
||||||
|
Task<StatusModel> DeleteMappingsAsync([Body] IList<MappingModel> mappings, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get a mapping based on the guid
|
/// Delete (reset) all mappings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="guid">The Guid</param>
|
/// <param name="reloadStaticMappings">A value indicating whether to reload the static mappings after the reset.</param>
|
||||||
/// <returns>MappingModel</returns>
|
/// <param name="cancellationToken">The optional cancellationToken.</param>
|
||||||
[Get("mappings/{guid}")]
|
[Post("mappings/reset")]
|
||||||
Task<MappingModel> GetMappingAsync([Path] Guid guid);
|
Task<StatusModel> ResetMappingsAsync(bool? reloadStaticMappings = false, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the C# code from a mapping based on the guid
|
/// Get a mapping based on the guid
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="guid">The Guid</param>
|
/// <param name="guid">The Guid</param>
|
||||||
/// <param name="mappingConverterType">The optional mappingConverterType (can be Server or Builder)</param>
|
/// <returns>MappingModel</returns>
|
||||||
/// <returns>C# code</returns>
|
/// <param name="cancellationToken">The optional cancellationToken.</param>
|
||||||
[Get("mappings/code/{guid}")]
|
[Get("mappings/{guid}")]
|
||||||
Task<string> GetMappingCodeAsync([Path] Guid guid, [Query] MappingConverterType mappingConverterType = MappingConverterType.Server);
|
Task<MappingModel> GetMappingAsync([Path] Guid guid, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Update a mapping based on the guid
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="guid">The Guid</param>
|
|
||||||
/// <param name="mapping">MappingModel</param>
|
|
||||||
[Put("mappings/{guid}")]
|
|
||||||
[Header("Content-Type", "application/json")]
|
|
||||||
Task<StatusModel> PutMappingAsync([Path] Guid guid, [Body] MappingModel mapping);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Delete a mapping based on the guid
|
/// Get the C# code from a mapping based on the guid
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="guid">The Guid</param>
|
/// <param name="guid">The Guid</param>
|
||||||
[Delete("mappings/{guid}")]
|
/// <param name="mappingConverterType">The optional mappingConverterType (can be Server or Builder)</param>
|
||||||
Task<StatusModel> DeleteMappingAsync([Path] Guid guid);
|
/// <returns>C# code</returns>
|
||||||
|
/// <param name="cancellationToken">The optional cancellationToken.</param>
|
||||||
|
[Get("mappings/code/{guid}")]
|
||||||
|
Task<string> GetMappingCodeAsync([Path] Guid guid, [Query] MappingConverterType mappingConverterType = MappingConverterType.Server, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Save the mappings
|
/// Update a mapping based on the guid
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Post("mappings/save")]
|
/// <param name="guid">The Guid</param>
|
||||||
Task<StatusModel> SaveMappingAsync();
|
/// <param name="mapping">MappingModel</param>
|
||||||
|
/// <param name="cancellationToken">The optional cancellationToken.</param>
|
||||||
|
[Put("mappings/{guid}")]
|
||||||
|
[Header("Content-Type", "application/json")]
|
||||||
|
Task<StatusModel> PutMappingAsync([Path] Guid guid, [Body] MappingModel mapping, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the requests.
|
/// Delete a mapping based on the guid
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>LogRequestModels</returns>
|
/// <param name="guid">The Guid</param>
|
||||||
[Get("requests")]
|
/// <param name="cancellationToken">The optional cancellationToken.</param>
|
||||||
Task<IList<LogEntryModel>> GetRequestsAsync();
|
[Delete("mappings/{guid}")]
|
||||||
|
Task<StatusModel> DeleteMappingAsync([Path] Guid guid, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Delete all requests.
|
/// Save the mappings
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Delete("requests")]
|
/// <param name="cancellationToken">The optional cancellationToken.</param>
|
||||||
Task<StatusModel> DeleteRequestsAsync();
|
[Post("mappings/save")]
|
||||||
|
Task<StatusModel> SaveMappingAsync(CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Delete (reset) all requests.
|
/// Get the requests.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Post("requests/reset")]
|
/// <returns>LogRequestModels</returns>
|
||||||
Task<StatusModel> ResetRequestsAsync();
|
/// <param name="cancellationToken">The optional cancellationToken.</param>
|
||||||
|
[Get("requests")]
|
||||||
|
Task<IList<LogEntryModel>> GetRequestsAsync(CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get a request based on the guid
|
/// Delete all requests.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="guid">The Guid</param>
|
/// <param name="cancellationToken">The optional cancellationToken.</param>
|
||||||
/// <returns>MappingModel</returns>
|
[Delete("requests")]
|
||||||
[Get("requests/{guid}")]
|
Task<StatusModel> DeleteRequestsAsync(CancellationToken cancellationToken = default);
|
||||||
Task<LogEntryModel> GetRequestAsync([Path] Guid guid);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Delete a request based on the guid
|
/// Delete (reset) all requests.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="guid">The Guid</param>
|
/// <param name="cancellationToken">The optional cancellationToken.</param>
|
||||||
[Delete("requests/{guid}")]
|
[Post("requests/reset")]
|
||||||
Task<StatusModel> DeleteRequestAsync([Path] Guid guid);
|
Task<StatusModel> ResetRequestsAsync(CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Find a request based on the criteria
|
/// Get a request based on the guid
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="model">The RequestModel</param>
|
/// <param name="guid">The Guid</param>
|
||||||
[Post("requests/find")]
|
/// <returns>MappingModel</returns>
|
||||||
[Header("Content-Type", "application/json")]
|
/// <param name="cancellationToken">The optional cancellationToken.</param>
|
||||||
Task<IList<LogEntryModel>> FindRequestsAsync([Body] RequestModel model);
|
[Get("requests/{guid}")]
|
||||||
|
Task<LogEntryModel> GetRequestAsync([Path] Guid guid, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get all scenarios
|
/// Delete a request based on the guid
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Get("scenarios")]
|
/// <param name="guid">The Guid</param>
|
||||||
Task<IList<ScenarioStateModel>> GetScenariosAsync();
|
/// <param name="cancellationToken">The optional cancellationToken.</param>
|
||||||
|
[Delete("requests/{guid}")]
|
||||||
|
Task<StatusModel> DeleteRequestAsync([Path] Guid guid, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Delete (reset) all scenarios
|
/// Find a request based on the criteria
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Delete("scenarios")]
|
/// <param name="model">The RequestModel</param>
|
||||||
Task<StatusModel> DeleteScenariosAsync();
|
/// <param name="cancellationToken">The optional cancellationToken.</param>
|
||||||
|
[Post("requests/find")]
|
||||||
|
[Header("Content-Type", "application/json")]
|
||||||
|
Task<IList<LogEntryModel>> FindRequestsAsync([Body] RequestModel model, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Delete (reset) all scenarios
|
/// Get all scenarios
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Post("scenarios")]
|
/// <param name="cancellationToken">The optional cancellationToken.</param>
|
||||||
Task<StatusModel> ResetScenariosAsync();
|
[Get("scenarios")]
|
||||||
|
Task<IList<ScenarioStateModel>> GetScenariosAsync(CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Delete (reset) a specific scenario
|
/// Delete (reset) all scenarios
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Delete("scenarios/{name}")]
|
/// <param name="cancellationToken">The optional cancellationToken.</param>
|
||||||
[AllowAnyStatusCode]
|
[Delete("scenarios")]
|
||||||
Task<StatusModel> DeleteScenarioAsync([Path] string name);
|
Task<StatusModel> DeleteScenariosAsync(CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Delete (reset) all scenarios
|
/// Delete (reset) all scenarios
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Post("scenarios/{name}/reset")]
|
/// <param name="cancellationToken">The optional cancellationToken.</param>
|
||||||
[AllowAnyStatusCode]
|
[Post("scenarios")]
|
||||||
Task<StatusModel> ResetScenarioAsync([Path] string name);
|
Task<StatusModel> ResetScenariosAsync(CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a new File
|
/// Delete (reset) a specific scenario
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filename">The filename</param>
|
/// <param name="name">Scenario name.</param>
|
||||||
/// <param name="body">The body</param>
|
/// <param name="cancellationToken">The optional cancellationToken.</param>
|
||||||
[Post("files/{filename}")]
|
[Delete("scenarios/{name}")]
|
||||||
Task<StatusModel> PostFileAsync([Path] string filename, [Body] string body);
|
[AllowAnyStatusCode]
|
||||||
|
Task<StatusModel> DeleteScenarioAsync([Path] string name, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Update an existing File
|
/// Delete (reset) all scenarios
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filename">The filename</param>
|
/// <param name="name">Scenario name.</param>
|
||||||
/// <param name="body">The body</param>
|
/// <param name="cancellationToken">The optional cancellationToken.</param>
|
||||||
[Put("files/{filename}")]
|
[Post("scenarios/{name}/reset")]
|
||||||
Task<StatusModel> PutFileAsync([Path] string filename, [Body] string body);
|
[AllowAnyStatusCode]
|
||||||
|
Task<StatusModel> ResetScenarioAsync([Path] string name, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the content of an existing File
|
/// Create a new File
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filename">The filename</param>
|
/// <param name="filename">The filename</param>
|
||||||
[Get("files/{filename}")]
|
/// <param name="body">The body</param>
|
||||||
Task<string> GetFileAsync([Path] string filename);
|
/// <param name="cancellationToken">The optional cancellationToken.</param>
|
||||||
|
[Post("files/{filename}")]
|
||||||
|
Task<StatusModel> PostFileAsync([Path] string filename, [Body] string body, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Delete an existing File
|
/// Update an existing File
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filename">The filename</param>
|
/// <param name="filename">The filename</param>
|
||||||
[Delete("files/{filename}")]
|
/// <param name="body">The body</param>
|
||||||
Task<StatusModel> DeleteFileAsync([Path] string filename);
|
/// <param name="cancellationToken">The optional cancellationToken.</param>
|
||||||
|
[Put("files/{filename}")]
|
||||||
|
Task<StatusModel> PutFileAsync([Path] string filename, [Body] string body, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Check if a file exists
|
/// Get the content of an existing File
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filename">The filename</param>
|
/// <param name="filename">The filename</param>
|
||||||
[Head("files/{filename}")]
|
/// <param name="cancellationToken">The optional cancellationToken.</param>
|
||||||
Task FileExistsAsync([Path] string filename);
|
[Get("files/{filename}")]
|
||||||
}
|
Task<string> GetFileAsync([Path] string filename, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Delete an existing File
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filename">The filename</param>
|
||||||
|
/// <param name="cancellationToken">The optional cancellationToken.</param>
|
||||||
|
[Delete("files/{filename}")]
|
||||||
|
Task<StatusModel> DeleteFileAsync([Path] string filename, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check if a file exists
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filename">The filename</param>
|
||||||
|
/// <param name="cancellationToken">The optional cancellationToken.</param>
|
||||||
|
[Head("files/{filename}")]
|
||||||
|
Task FileExistsAsync([Path] string filename, CancellationToken cancellationToken = default);
|
||||||
}
|
}
|
||||||
@@ -30,8 +30,10 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="JsonConverter.Newtonsoft.Json" Version="0.3.0" />
|
||||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
|
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
|
||||||
<PackageReference Include="RestEase" Version="1.5.7" />
|
<PackageReference Include="RestEase" Version="1.5.7" />
|
||||||
|
<PackageReference Include="Stef.Validation" Version="0.1.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public interface IBodyResponseBuilder : IFaultResponseBuilder
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="body">The body.</param>
|
/// <param name="body">The body.</param>
|
||||||
/// <param name="encoding">The body encoding.</param>
|
/// <param name="encoding">The body encoding.</param>
|
||||||
/// <param name="indented">Use JSON indented.</param>
|
/// <param name="indented">Define whether child objects to be indented according to the Newtonsoft.Json.JsonTextWriter.Indentation and Newtonsoft.Json.JsonTextWriter.IndentChar settings.</param>
|
||||||
/// <returns>A <see cref="IResponseBuilder"/>.</returns>
|
/// <returns>A <see cref="IResponseBuilder"/>.</returns>
|
||||||
IResponseBuilder WithBodyAsJson(object body, Encoding? encoding = null, bool? indented = null);
|
IResponseBuilder WithBodyAsJson(object body, Encoding? encoding = null, bool? indented = null);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user