mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-06-06 15:02:47 +02:00
Initial support for converting the mappings to a Pact(flow) json file (#748)
* WithDescription * WithConsumer / WithProvider * x * . * . * . * . * fix * pact * nullable * ficx * . * fix
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=guidb/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=guidb/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Heyenrath/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Heyenrath/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Jmes/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Jmes/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Pacticipant/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Raml/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Raml/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=randomizer/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=randomizer/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Scriban/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Scriban/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
|||||||
@@ -69,6 +69,12 @@ namespace WireMock.Net.ConsoleApplication
|
|||||||
File.WriteAllBytes(AdjustPath(path), bytes);
|
File.WriteAllBytes(AdjustPath(path), bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void WriteFile(string folder, string filename, byte[] bytes)
|
||||||
|
{
|
||||||
|
File.WriteAllBytes(Path.Combine(folder, filename), bytes);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IFileSystemHandler.DeleteFile"/>
|
/// <inheritdoc cref="IFileSystemHandler.DeleteFile"/>
|
||||||
public void DeleteFile(string path)
|
public void DeleteFile(string path)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -89,6 +89,8 @@ namespace WireMock.Net.ConsoleApplication
|
|||||||
server
|
server
|
||||||
.Given(Request.Create().WithPath(p => p.Contains("x")).UsingGet())
|
.Given(Request.Create().WithPath(p => p.Contains("x")).UsingGet())
|
||||||
.AtPriority(4)
|
.AtPriority(4)
|
||||||
|
.WithTitle("t")
|
||||||
|
.WithDescription("d")
|
||||||
.RespondWith(Response.Create()
|
.RespondWith(Response.Create()
|
||||||
.WithStatusCode(200)
|
.WithStatusCode(200)
|
||||||
.WithHeader("Content-Type", "application/json")
|
.WithHeader("Content-Type", "application/json")
|
||||||
|
|||||||
@@ -1,31 +1,30 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace WireMock.Admin.Mappings
|
namespace WireMock.Admin.Mappings;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Cookie Model
|
||||||
|
/// </summary>
|
||||||
|
[FluentBuilder.AutoGenerateBuilder]
|
||||||
|
public class CookieModel
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Cookie Model
|
/// Gets or sets the name.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[FluentBuilder.AutoGenerateBuilder]
|
public string Name { get; set; } = null!;
|
||||||
public class CookieModel
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the name.
|
|
||||||
/// </summary>
|
|
||||||
public string Name { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the matchers.
|
/// Gets or sets the matchers.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IList<MatcherModel> Matchers { get; set; }
|
public IList<MatcherModel>? Matchers { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the ignore case.
|
/// Gets or sets the ignore case.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool? IgnoreCase { get; set; }
|
public bool? IgnoreCase { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reject on match.
|
/// Reject on match.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool? RejectOnMatch { get; set; }
|
public bool? RejectOnMatch { get; set; }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace WireMock.Admin.Mappings
|
namespace WireMock.Admin.Mappings
|
||||||
{
|
{
|
||||||
@@ -11,12 +11,12 @@ namespace WireMock.Admin.Mappings
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the name.
|
/// Gets or sets the name.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Name { get; set; }
|
public string Name { get; set; } = null!;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the matchers.
|
/// Gets or sets the matchers.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IList<MatcherModel> Matchers { get; set; }
|
public IList<MatcherModel>? Matchers { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the ignore case.
|
/// Gets or sets the ignore case.
|
||||||
|
|||||||
@@ -24,6 +24,11 @@ namespace WireMock.Admin.Mappings
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string Title { get; set; }
|
public string Title { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The description.
|
||||||
|
/// </summary>
|
||||||
|
public string Description { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The priority. (A low value means higher priority.)
|
/// The priority. (A low value means higher priority.)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,24 +1,23 @@
|
|||||||
namespace WireMock.Admin.Mappings
|
namespace WireMock.Admin.Mappings;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Param Model
|
||||||
|
/// </summary>
|
||||||
|
[FluentBuilder.AutoGenerateBuilder]
|
||||||
|
public class ParamModel
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Param Model
|
/// Gets or sets the name.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[FluentBuilder.AutoGenerateBuilder]
|
public string Name { get; set; } = null!;
|
||||||
public class ParamModel
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the name.
|
|
||||||
/// </summary>
|
|
||||||
public string Name { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines if the key should be matched using case-ignore.
|
/// Defines if the key should be matched using case-ignore.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool? IgnoreCase { get; set; }
|
public bool? IgnoreCase { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the matchers.
|
/// Gets or sets the matchers.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public MatcherModel[] Matchers { get; set; }
|
public MatcherModel[]? Matchers { get; set; }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,51 +1,50 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace WireMock.Admin.Mappings
|
namespace WireMock.Admin.Mappings;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// RequestModel
|
||||||
|
/// </summary>
|
||||||
|
[FluentBuilder.AutoGenerateBuilder]
|
||||||
|
public class RequestModel
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// RequestModel
|
/// Gets or sets the ClientIP. (Can be a string or a ClientIPModel)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[FluentBuilder.AutoGenerateBuilder]
|
public object? ClientIP { get; set; }
|
||||||
public class RequestModel
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the ClientIP. (Can be a string or a ClientIPModel)
|
|
||||||
/// </summary>
|
|
||||||
public object ClientIP { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the Path. (Can be a string or a PathModel)
|
/// Gets or sets the Path. (Can be a string or a PathModel)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public object Path { get; set; }
|
public object? Path { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the Url. (Can be a string or a UrlModel)
|
/// Gets or sets the Url. (Can be a string or a UrlModel)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public object Url { get; set; }
|
public object? Url { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The methods
|
/// The methods
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string[] Methods { get; set; }
|
public string[]? Methods { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the Headers.
|
/// Gets or sets the Headers.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IList<HeaderModel> Headers { get; set; }
|
public IList<HeaderModel>? Headers { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the Cookies.
|
/// Gets or sets the Cookies.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IList<CookieModel> Cookies { get; set; }
|
public IList<CookieModel>? Cookies { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the Params.
|
/// Gets or sets the Params.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IList<ParamModel> Params { get; set; }
|
public IList<ParamModel>? Params { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the body.
|
/// Gets or sets the body.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public BodyModel Body { get; set; }
|
public BodyModel? Body { get; set; }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -11,22 +11,22 @@ namespace WireMock.Admin.Mappings
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the HTTP status.
|
/// Gets or sets the HTTP status.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public object StatusCode { get; set; }
|
public object? StatusCode { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the body destination (SameAsSource, String or Bytes).
|
/// Gets or sets the body destination (SameAsSource, String or Bytes).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string BodyDestination { get; set; }
|
public string? BodyDestination { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the body.
|
/// Gets or sets the body.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Body { get; set; }
|
public string? Body { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the body (as JSON object).
|
/// Gets or sets the body (as JSON object).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public object BodyAsJson { get; set; }
|
public object? BodyAsJson { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a value indicating whether child objects to be indented according to the Newtonsoft.Json.JsonTextWriter.Indentation and Newtonsoft.Json.JsonTextWriter.IndentChar settings.
|
/// Gets or sets a value indicating whether child objects to be indented according to the Newtonsoft.Json.JsonTextWriter.Indentation and Newtonsoft.Json.JsonTextWriter.IndentChar settings.
|
||||||
@@ -36,12 +36,12 @@ namespace WireMock.Admin.Mappings
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the body (as bytearray).
|
/// Gets or sets the body (as bytearray).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public byte[] BodyAsBytes { get; set; }
|
public byte[]? BodyAsBytes { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the body as a file.
|
/// Gets or sets the body as a file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string BodyAsFile { get; set; }
|
public string? BodyAsFile { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Is the body as file cached?
|
/// Is the body as file cached?
|
||||||
@@ -51,7 +51,7 @@ namespace WireMock.Admin.Mappings
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the body encoding.
|
/// Gets or sets the body encoding.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public EncodingModel BodyEncoding { get; set; }
|
public EncodingModel? BodyEncoding { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Use ResponseMessage Transformer.
|
/// Use ResponseMessage Transformer.
|
||||||
@@ -61,7 +61,7 @@ namespace WireMock.Admin.Mappings
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the type of the transformer.
|
/// Gets the type of the transformer.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string TransformerType { get; set; }
|
public string? TransformerType { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Use the Handlebars transformer for the content from the referenced BodyAsFile.
|
/// Use the Handlebars transformer for the content from the referenced BodyAsFile.
|
||||||
@@ -71,17 +71,17 @@ namespace WireMock.Admin.Mappings
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The ReplaceNodeOptions to use when transforming a JSON node.
|
/// The ReplaceNodeOptions to use when transforming a JSON node.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string TransformerReplaceNodeOptions { get; set; }
|
public string? TransformerReplaceNodeOptions { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the headers.
|
/// Gets or sets the headers.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IDictionary<string, object> Headers { get; set; }
|
public IDictionary<string, object>? Headers { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the Headers (Raw).
|
/// Gets or sets the Headers (Raw).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string HeadersRaw { get; set; }
|
public string? HeadersRaw { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the delay in milliseconds.
|
/// Gets or sets the delay in milliseconds.
|
||||||
@@ -101,21 +101,21 @@ namespace WireMock.Admin.Mappings
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the Proxy URL.
|
/// Gets or sets the Proxy URL.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string ProxyUrl { get; set; }
|
public string? ProxyUrl { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The client X509Certificate2 Thumbprint or SubjectName to use.
|
/// The client X509Certificate2 Thumbprint or SubjectName to use.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string X509Certificate2ThumbprintOrSubjectName { get; set; }
|
public string? X509Certificate2ThumbprintOrSubjectName { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the fault.
|
/// Gets or sets the fault.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public FaultModel Fault { get; set; }
|
public FaultModel? Fault { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the WebProxy settings.
|
/// Gets or sets the WebProxy settings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public WebProxyModel WebProxy { get; set; }
|
public WebProxyModel? WebProxy { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,56 +1,54 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace WireMock.Admin.Requests
|
namespace WireMock.Admin.Requests;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Request Log Model
|
||||||
|
/// </summary>
|
||||||
|
public class LogEntryModel
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Request Log Model
|
/// The unique identifier.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[FluentBuilder.AutoGenerateBuilder]
|
public Guid Guid { get; set; }
|
||||||
public class LogEntryModel
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The unique identifier.
|
|
||||||
/// </summary>
|
|
||||||
public Guid Guid { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The request.
|
/// The request.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public LogRequestModel Request { get; set; }
|
public LogRequestModel Request { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The response.
|
/// The response.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public LogResponseModel Response { get; set; }
|
public LogResponseModel Response { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The mapping unique identifier.
|
/// The mapping unique identifier.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Guid? MappingGuid { get; set; }
|
public Guid? MappingGuid { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The mapping unique title.
|
/// The mapping unique title.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string MappingTitle { get; set; }
|
public string MappingTitle { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The request match result.
|
/// The request match result.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public LogRequestMatchModel RequestMatchResult { get; set; }
|
public LogRequestMatchModel RequestMatchResult { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The partial mapping unique identifier.
|
/// The partial mapping unique identifier.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Guid? PartialMappingGuid { get; set; }
|
public Guid? PartialMappingGuid { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The partial mapping unique title.
|
/// The partial mapping unique title.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string PartialMappingTitle { get; set; }
|
public string PartialMappingTitle { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The partial request match result.
|
/// The partial request match result.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public LogRequestMatchModel PartialRequestMatchResult { get; set; }
|
public LogRequestMatchModel PartialRequestMatchResult { get; set; }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,51 +1,49 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace WireMock.Admin.Requests
|
namespace WireMock.Admin.Requests;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// LogRequestMatchModel
|
||||||
|
/// </summary>
|
||||||
|
public class LogRequestMatchModel
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// LogRequestMatchModel
|
/// Gets or sets the match-score.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[FluentBuilder.AutoGenerateBuilder]
|
/// <value>
|
||||||
public class LogRequestMatchModel
|
/// The match-score.
|
||||||
{
|
/// </value>
|
||||||
/// <summary>
|
public double TotalScore { get; set; }
|
||||||
/// Gets or sets the match-score.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>
|
|
||||||
/// The match-score.
|
|
||||||
/// </value>
|
|
||||||
public double TotalScore { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the total number of matches.
|
/// Gets or sets the total number of matches.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// The total number of matches.
|
/// The total number of matches.
|
||||||
/// </value>
|
/// </value>
|
||||||
public int TotalNumber { get; set; }
|
public int TotalNumber { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a value indicating whether this instance is perfect match.
|
/// Gets or sets a value indicating whether this instance is perfect match.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// <c>true</c> if this instance is perfect match; otherwise, <c>false</c>.
|
/// <c>true</c> if this instance is perfect match; otherwise, <c>false</c>.
|
||||||
/// </value>
|
/// </value>
|
||||||
public bool IsPerfectMatch { get; set; }
|
public bool IsPerfectMatch { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the match percentage.
|
/// Gets the match percentage.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// The match percentage.
|
/// The match percentage.
|
||||||
/// </value>
|
/// </value>
|
||||||
public double AverageTotalScore { get; set; }
|
public double AverageTotalScore { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the match details.
|
/// Gets the match details.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// The match details.
|
/// The match details.
|
||||||
/// </value>
|
/// </value>
|
||||||
public IList<object> MatchDetails { get; set; }
|
public IList<object> MatchDetails { get; set; }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,109 +1,107 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using WireMock.Admin.Mappings;
|
using WireMock.Admin.Mappings;
|
||||||
using WireMock.Types;
|
using WireMock.Types;
|
||||||
|
|
||||||
namespace WireMock.Admin.Requests
|
namespace WireMock.Admin.Requests;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// RequestMessage Model
|
||||||
|
/// </summary>
|
||||||
|
public class LogRequestModel
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// RequestMessage Model
|
/// The Client IP Address.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[FluentBuilder.AutoGenerateBuilder]
|
public string ClientIP { get; set; }
|
||||||
public class LogRequestModel
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The Client IP Address.
|
|
||||||
/// </summary>
|
|
||||||
public string ClientIP { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The DateTime.
|
/// The DateTime.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTime DateTime { get; set; }
|
public DateTime DateTime { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The Path.
|
/// The Path.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Path { get; set; }
|
public string Path { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The Absolute Path.
|
/// The Absolute Path.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string AbsolutePath { get; set; }
|
public string AbsolutePath { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the url (relative).
|
/// Gets the url (relative).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Url { get; set; }
|
public string Url { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The absolute URL.
|
/// The absolute URL.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string AbsoluteUrl { get; set; }
|
public string AbsoluteUrl { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The ProxyUrl (if a proxy is used).
|
/// The ProxyUrl (if a proxy is used).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string ProxyUrl { get; set; }
|
public string? ProxyUrl { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The query.
|
/// The query.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IDictionary<string, WireMockList<string>> Query { get; set; }
|
public IDictionary<string, WireMockList<string>>? Query { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The method.
|
/// The method.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Method { get; set; }
|
public string Method { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The Headers.
|
/// The Headers.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IDictionary<string, WireMockList<string>> Headers { get; set; }
|
public IDictionary<string, WireMockList<string>>? Headers { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The Cookies.
|
/// The Cookies.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IDictionary<string, string> Cookies { get; set; }
|
public IDictionary<string, string>? Cookies { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The body (as string).
|
/// The body (as string).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Body { get; set; }
|
public string? Body { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The body (as JSON object).
|
/// The body (as JSON object).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public object BodyAsJson { get; set; }
|
public object? BodyAsJson { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The body (as bytearray).
|
/// The body (as bytearray).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public byte[] BodyAsBytes { get; set; }
|
public byte[]? BodyAsBytes { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The body encoding.
|
/// The body encoding.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public EncodingModel BodyEncoding { get; set; }
|
public EncodingModel? BodyEncoding { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The DetectedBodyType, valid values are:
|
/// The DetectedBodyType, valid values are:
|
||||||
///
|
///
|
||||||
/// - None
|
/// - None
|
||||||
/// - String
|
/// - String
|
||||||
/// - Json
|
/// - Json
|
||||||
/// - Bytes
|
/// - Bytes
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string DetectedBodyType { get; set; }
|
public string? DetectedBodyType { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The DetectedBodyTypeFromContentType, valid values are:
|
/// The DetectedBodyTypeFromContentType, valid values are:
|
||||||
///
|
///
|
||||||
/// - None
|
/// - None
|
||||||
/// - String
|
/// - String
|
||||||
/// - Json
|
/// - Json
|
||||||
/// - Bytes
|
/// - Bytes
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string DetectedBodyTypeFromContentType { get; set; }
|
public string? DetectedBodyTypeFromContentType { get; set; }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,83 +1,81 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using WireMock.Admin.Mappings;
|
using WireMock.Admin.Mappings;
|
||||||
using WireMock.Types;
|
using WireMock.Types;
|
||||||
|
|
||||||
namespace WireMock.Admin.Requests
|
namespace WireMock.Admin.Requests;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Response MessageModel
|
||||||
|
/// </summary>
|
||||||
|
public class LogResponseModel
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Response MessageModel
|
/// Gets or sets the status code.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[FluentBuilder.AutoGenerateBuilder]
|
public object? StatusCode { get; set; }
|
||||||
public class LogResponseModel
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the status code.
|
|
||||||
/// </summary>
|
|
||||||
public object StatusCode { get; set; } = 200;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the headers.
|
/// Gets the headers.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IDictionary<string, WireMockList<string>> Headers { get; set; }
|
public IDictionary<string, WireMockList<string>>? Headers { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the body destination (SameAsSource, String or Bytes).
|
/// Gets or sets the body destination (SameAsSource, String or Bytes).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string BodyDestination { get; set; }
|
public string? BodyDestination { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The body (as string).
|
/// The body (as string).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Body { get; set; }
|
public string? Body { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The body (as JSON object).
|
/// The body (as JSON object).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public object BodyAsJson { get; set; }
|
public object? BodyAsJson { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The body (as bytearray).
|
/// The body (as bytearray).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public byte[] BodyAsBytes { get; set; }
|
public byte[]? BodyAsBytes { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the body as file.
|
/// Gets or sets the body as file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string BodyAsFile { get; set; }
|
public string? BodyAsFile { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Is the body as file cached?
|
/// Is the body as file cached?
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool? BodyAsFileIsCached { get; set; }
|
public bool? BodyAsFileIsCached { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the original body.
|
/// Gets or sets the original body.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string BodyOriginal { get; set; }
|
public string? BodyOriginal { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the body.
|
/// Gets or sets the body.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public EncodingModel BodyEncoding { get; set; }
|
public EncodingModel? BodyEncoding { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The detected body type (detection based on body content).
|
/// The detected body type (detection based on body content).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public BodyType DetectedBodyType { get; set; }
|
public BodyType? DetectedBodyType { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The detected body type (detection based on Content-Type).
|
/// The detected body type (detection based on Content-Type).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public BodyType DetectedBodyTypeFromContentType { get; set; }
|
public BodyType? DetectedBodyTypeFromContentType { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The FaultType.
|
/// The FaultType.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string FaultType { get; set; }
|
public string? FaultType { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the Fault percentage.
|
/// Gets or sets the Fault percentage.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double? FaultPercentage { get; set; }
|
public double? FaultPercentage { get; set; }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace WireMock.Admin.Scenarios
|
namespace WireMock.Admin.Scenarios
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ScenarioStateModel
|
/// ScenarioStateModel
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the NextState.
|
/// Gets or sets the NextState.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string NextState { get; set; }
|
public string? NextState { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a value indicating whether this <see cref="ScenarioStateModel"/> is started.
|
/// Gets or sets a value indicating whether this <see cref="ScenarioStateModel"/> is started.
|
||||||
|
|||||||
@@ -1,59 +1,58 @@
|
|||||||
using JetBrains.Annotations;
|
namespace WireMock.Admin.Settings
|
||||||
|
|
||||||
namespace WireMock.Admin.Settings;
|
|
||||||
|
|
||||||
[FluentBuilder.AutoGenerateBuilder]
|
|
||||||
public class ProxyAndRecordSettingsModel
|
|
||||||
{
|
{
|
||||||
/// <summary>
|
[FluentBuilder.AutoGenerateBuilder]
|
||||||
/// The clientCertificate thumbprint or subject name fragment to use.
|
public class ProxyAndRecordSettingsModel
|
||||||
/// Example thumbprint : "D2DBF135A8D06ACCD0E1FAD9BFB28678DF7A9818". Example subject name: "www.google.com""
|
{
|
||||||
/// </summary>
|
/// <summary>
|
||||||
public string ClientX509Certificate2ThumbprintOrSubjectName { get; set; }
|
/// The clientCertificate thumbprint or subject name fragment to use.
|
||||||
|
/// Example thumbprint : "D2DBF135A8D06ACCD0E1FAD9BFB28678DF7A9818". Example subject name: "www.google.com""
|
||||||
|
/// </summary>
|
||||||
|
public string ClientX509Certificate2ThumbprintOrSubjectName { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines the WebProxySettings.
|
/// Defines the WebProxySettings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public WebProxySettingsModel WebProxySettings { get; set; }
|
public WebProxySettingsModel WebProxySettings { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Proxy requests should follow redirection (30x).
|
/// Proxy requests should follow redirection (30x).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool? AllowAutoRedirect { get; set; }
|
public bool? AllowAutoRedirect { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The URL to proxy.
|
/// The URL to proxy.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Url { get; set; }
|
public string Url { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Save the mapping for each request/response to the internal Mappings.
|
/// Save the mapping for each request/response to the internal Mappings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool SaveMapping { get; set; }
|
public bool SaveMapping { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Save the mapping for each request/response also to a file. (Note that SaveMapping must also be set to true.)
|
/// Save the mapping for each request/response also to a file. (Note that SaveMapping must also be set to true.)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool SaveMappingToFile { get; set; }
|
public bool SaveMappingToFile { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Only save request/response to the internal Mappings if the status code is included in this pattern. (Note that SaveMapping must also be set to true.)
|
/// Only save request/response to the internal Mappings if the status code is included in this pattern. (Note that SaveMapping must also be set to true.)
|
||||||
/// The pattern can contain a single value like "200", but also ranges like "2xx", "100,300,600" or "100-299,6xx" are supported.
|
/// The pattern can contain a single value like "200", but also ranges like "2xx", "100,300,600" or "100-299,6xx" are supported.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string SaveMappingForStatusCodePattern { get; set; } = "*";
|
public string SaveMappingForStatusCodePattern { get; set; } = "*";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines a list from headers which will be excluded from the saved mappings.
|
/// Defines a list from headers which will be excluded from the saved mappings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string[] ExcludedHeaders { get; set; }
|
public string[] ExcludedHeaders { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines a list of cookies which will be excluded from the saved mappings.
|
/// Defines a list of cookies which will be excluded from the saved mappings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string[] ExcludedCookies { get; set; }
|
public string[] ExcludedCookies { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Prefer the Proxy Mapping over the saved Mapping (in case SaveMapping is set to <c>true</c>).
|
/// Prefer the Proxy Mapping over the saved Mapping (in case SaveMapping is set to <c>true</c>).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
// public bool PreferProxyMapping { get; set; }
|
// public bool PreferProxyMapping { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using JetBrains.Annotations;
|
|
||||||
using WireMock.Handlers;
|
using WireMock.Handlers;
|
||||||
|
|
||||||
namespace WireMock.Admin.Settings
|
namespace WireMock.Admin.Settings
|
||||||
@@ -73,11 +72,11 @@ namespace WireMock.Admin.Settings
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Policies to use when using CORS. By default CORS is disabled. [Optional]
|
/// Policies to use when using CORS. By default CORS is disabled. [Optional]
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string CorsPolicyOptions { get; set; }
|
public string? CorsPolicyOptions { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The proxy and record settings.
|
/// The proxy and record settings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ProxyAndRecordSettingsModel ProxyAndRecordSettings { get; set; }
|
public ProxyAndRecordSettingsModel? ProxyAndRecordSettings { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,11 +14,11 @@ namespace WireMock.Admin.Settings
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The user name associated with the credentials.
|
/// The user name associated with the credentials.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string UserName { get; set; }
|
public string? UserName { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The password for the user name associated with the credentials.
|
/// The password for the user name associated with the credentials.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Password { get; set; }
|
public string? Password { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,7 @@ using System.Collections.Generic;
|
|||||||
namespace WireMock.Handlers
|
namespace WireMock.Handlers
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handler to interact with the file system to handle folders and read and write static mapping files.
|
/// Handler to interact with the file system to handle folders and read and write (static mapping) files.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IFileSystemHandler
|
public interface IFileSystemHandler
|
||||||
{
|
{
|
||||||
@@ -83,6 +83,14 @@ namespace WireMock.Handlers
|
|||||||
/// <param name="bytes">The bytes.</param>
|
/// <param name="bytes">The bytes.</param>
|
||||||
void WriteFile([NotNull] string filename, [NotNull] byte[] bytes);
|
void WriteFile([NotNull] string filename, [NotNull] byte[] bytes);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Write a file.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folder">The folder.</param>
|
||||||
|
/// <param name="filename">The filename.</param>
|
||||||
|
/// <param name="bytes">The bytes.</param>
|
||||||
|
void WriteFile([NotNull] string folder, [NotNull] string filename, [NotNull] byte[] bytes);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Read a file as bytes.
|
/// Read a file as bytes.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using WireMock.Types;
|
using WireMock.Types;
|
||||||
using WireMock.Util;
|
using WireMock.Util;
|
||||||
@@ -28,7 +28,7 @@ namespace WireMock
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The ProxyUrl (if a proxy is used).
|
/// The ProxyUrl (if a proxy is used).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
string ProxyUrl { get; }
|
string ProxyUrl { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the DateTime.
|
/// Gets the DateTime.
|
||||||
@@ -83,7 +83,7 @@ namespace WireMock
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The body.
|
/// The body.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
IBodyData BodyData { get; }
|
IBodyData? BodyData { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The original body as string. Convenience getter for Handlebars.
|
/// The original body as string. Convenience getter for Handlebars.
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using WireMock.Admin.Requests;
|
using WireMock.Admin.Requests;
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ namespace WireMock.Logging
|
|||||||
/// <param name="args">The arguments.</param>
|
/// <param name="args">The arguments.</param>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
[StringFormatMethod("formatString")]
|
[StringFormatMethod("formatString")]
|
||||||
void Debug([NotNull] string formatString, [NotNull] params object[] args);
|
void Debug(string formatString, params object[] args);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes the message at the Info level using the specified parameters.
|
/// Writes the message at the Info level using the specified parameters.
|
||||||
@@ -26,7 +26,7 @@ namespace WireMock.Logging
|
|||||||
/// <param name="args">The arguments.</param>
|
/// <param name="args">The arguments.</param>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
[StringFormatMethod("formatString")]
|
[StringFormatMethod("formatString")]
|
||||||
void Info([NotNull] string formatString, [NotNull] params object[] args);
|
void Info(string formatString, params object[] args);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes the message at the Warning level using the specified parameters.
|
/// Writes the message at the Warning level using the specified parameters.
|
||||||
@@ -35,7 +35,7 @@ namespace WireMock.Logging
|
|||||||
/// <param name="args">The arguments.</param>
|
/// <param name="args">The arguments.</param>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
[StringFormatMethod("formatString")]
|
[StringFormatMethod("formatString")]
|
||||||
void Warn([NotNull] string formatString, [NotNull] params object[] args);
|
void Warn(string formatString, params object[] args);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes the message at the Error level using the specified parameters.
|
/// Writes the message at the Error level using the specified parameters.
|
||||||
@@ -44,7 +44,7 @@ namespace WireMock.Logging
|
|||||||
/// <param name="args">The arguments.</param>
|
/// <param name="args">The arguments.</param>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
[StringFormatMethod("formatString")]
|
[StringFormatMethod("formatString")]
|
||||||
void Error([NotNull] string formatString, [NotNull] params object[] args);
|
void Error(string formatString, params object[] args);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes the message at the Error level using the specified exception.
|
/// Writes the message at the Error level using the specified exception.
|
||||||
@@ -53,7 +53,7 @@ namespace WireMock.Logging
|
|||||||
/// <param name="exception">The exception.</param>
|
/// <param name="exception">The exception.</param>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
[StringFormatMethod("formatString")]
|
[StringFormatMethod("formatString")]
|
||||||
void Error([NotNull] string formatString, [NotNull] Exception exception);
|
void Error(string formatString, Exception exception);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes the LogEntryModel (LogRequestModel, LogResponseModel and more).
|
/// Writes the LogEntryModel (LogRequestModel, LogResponseModel and more).
|
||||||
@@ -61,6 +61,6 @@ namespace WireMock.Logging
|
|||||||
/// <param name="logEntryModel">The Request Log Model.</param>
|
/// <param name="logEntryModel">The Request Log Model.</param>
|
||||||
/// <param name="isAdminRequest">Defines if this request is an admin request.</param>
|
/// <param name="isAdminRequest">Defines if this request is an admin request.</param>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
void DebugRequestResponse([NotNull] LogEntryModel logEntryModel, bool isAdminRequest);
|
void DebugRequestResponse(LogEntryModel logEntryModel, bool isAdminRequest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace WireMock.Matchers.Request
|
namespace WireMock.Matchers.Request
|
||||||
@@ -44,5 +44,13 @@ namespace WireMock.Matchers.Request
|
|||||||
/// The match-score.
|
/// The match-score.
|
||||||
/// </value>
|
/// </value>
|
||||||
double TotalScore { get; }
|
double TotalScore { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds the score.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="matcherType">The matcher Type.</param>
|
||||||
|
/// <param name="score">The score.</param>
|
||||||
|
/// <returns>The score.</returns>
|
||||||
|
double AddScore(Type matcherType, double score);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
|
|
||||||
namespace WireMock.Matchers.Request
|
namespace WireMock.Matchers.Request
|
||||||
{
|
{
|
||||||
@@ -15,6 +15,6 @@ namespace WireMock.Matchers.Request
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// A value between 0.0 - 1.0 of the similarity.
|
/// A value between 0.0 - 1.0 of the similarity.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
double GetMatchingScore([NotNull] IRequestMessage requestMessage, [NotNull] RequestMatchResult requestMatchResult);
|
double GetMatchingScore([NotNull] IRequestMessage requestMessage, [NotNull] IRequestMatchResult requestMatchResult);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,61 +1,62 @@
|
|||||||
using System.Text;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Text;
|
||||||
|
using JetBrains.Annotations;
|
||||||
using WireMock.Types;
|
using WireMock.Types;
|
||||||
|
|
||||||
namespace WireMock.Util
|
namespace WireMock.Util;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// IBodyData
|
||||||
|
/// </summary>
|
||||||
|
public interface IBodyData
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// IBodyData
|
/// The body (as bytearray).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IBodyData
|
byte[] BodyAsBytes { get; set; }
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The body (as bytearray).
|
|
||||||
/// </summary>
|
|
||||||
byte[] BodyAsBytes { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the body as a file.
|
/// Gets or sets the body as a file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
string BodyAsFile { get; set; }
|
string BodyAsFile { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Is the body as file cached?
|
/// Is the body as file cached?
|
||||||
/// </summary>
|
/// </summary>
|
||||||
bool? BodyAsFileIsCached { get; set; }
|
bool? BodyAsFileIsCached { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The body (as JSON object).
|
/// The body (as JSON object).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
object BodyAsJson { get; set; }
|
object? BodyAsJson { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a value indicating whether child objects to be indented according to the Newtonsoft.Json.JsonTextWriter.Indentation and Newtonsoft.Json.JsonTextWriter.IndentChar settings.
|
/// Gets or sets a value indicating whether child objects to be indented according to the Newtonsoft.Json.JsonTextWriter.Indentation and Newtonsoft.Json.JsonTextWriter.IndentChar settings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
bool? BodyAsJsonIndented { get; set; }
|
bool? BodyAsJsonIndented { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The body as string, this is defined when BodyAsString or BodyAsJson are not null.
|
/// The body as string, this is defined when BodyAsString or BodyAsJson are not null.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
string BodyAsString { get; set; }
|
string BodyAsString { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The detected body type (detection based on body content).
|
/// The detected body type (detection based on body content).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
BodyType DetectedBodyType { get; set; }
|
BodyType? DetectedBodyType { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The detected body type (detection based on Content-Type).
|
/// The detected body type (detection based on Content-Type).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
BodyType DetectedBodyTypeFromContentType { get; set; }
|
BodyType? DetectedBodyTypeFromContentType { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The detected compression.
|
/// The detected compression.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
string DetectedCompression { get; set; }
|
string? DetectedCompression { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The body encoding.
|
/// The body encoding.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Encoding Encoding { get; set; }
|
Encoding? Encoding { get; set; }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,7 @@ using System.Collections.Specialized;
|
|||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using WireMock.Admin.Mappings;
|
using WireMock.Admin.Mappings;
|
||||||
using WireMock.Logging;
|
using WireMock.Logging;
|
||||||
|
using WireMock.Matchers.Request;
|
||||||
|
|
||||||
namespace WireMock.Server
|
namespace WireMock.Server
|
||||||
{
|
{
|
||||||
@@ -51,7 +52,17 @@ namespace WireMock.Server
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the first url.
|
/// Gets the first url.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
string Url { get; }
|
string? Url { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the consumer.
|
||||||
|
/// </summary>
|
||||||
|
string? Consumer { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the provider.
|
||||||
|
/// </summary>
|
||||||
|
string? Provider { get; }
|
||||||
|
|
||||||
//ConcurrentDictionary<string, ScenarioState> Scenarios { get; }
|
//ConcurrentDictionary<string, ScenarioState> Scenarios { get; }
|
||||||
|
|
||||||
@@ -94,7 +105,7 @@ namespace WireMock.Server
|
|||||||
|
|
||||||
//IEnumerable<LogEntry> FindLogEntries([NotNull] params IRequestMatcher[] matchers);
|
//IEnumerable<LogEntry> FindLogEntries([NotNull] params IRequestMatcher[] matchers);
|
||||||
|
|
||||||
//IRespondWithAProvider Given(IRequestMatcher requestMatcher, bool saveToFile = false);
|
// IRespondWithAProvider Given(IRequestMatcher requestMatcher, bool saveToFile = false);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reads a static mapping file and adds or updates a single mapping.
|
/// Reads a static mapping file and adds or updates a single mapping.
|
||||||
@@ -102,7 +113,7 @@ namespace WireMock.Server
|
|||||||
/// Calling this method manually forces WireMock.Net to read and apply the specified static mapping file.
|
/// Calling this method manually forces WireMock.Net to read and apply the specified static mapping file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path">The path to the static mapping file.</param>
|
/// <param name="path">The path to the static mapping file.</param>
|
||||||
bool ReadStaticMappingAndAddOrUpdate([NotNull] string path);
|
bool ReadStaticMappingAndAddOrUpdate(string path);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reads the static mappings from a folder.
|
/// Reads the static mappings from a folder.
|
||||||
@@ -111,7 +122,7 @@ namespace WireMock.Server
|
|||||||
/// Calling this method manually forces WireMock.Net to read and apply all static mapping files in the specified folder.
|
/// Calling this method manually forces WireMock.Net to read and apply all static mapping files in the specified folder.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="folder">The optional folder. If not defined, use {CurrentFolder}/__admin/mappings</param>
|
/// <param name="folder">The optional folder. If not defined, use {CurrentFolder}/__admin/mappings</param>
|
||||||
void ReadStaticMappings([CanBeNull] string folder = null);
|
void ReadStaticMappings(string? folder = null);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Removes the authentication.
|
/// Removes the authentication.
|
||||||
@@ -142,33 +153,33 @@ namespace WireMock.Server
|
|||||||
/// Saves the static mappings.
|
/// Saves the static mappings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="folder">The optional folder. If not defined, use {CurrentFolder}/__admin/mappings</param>
|
/// <param name="folder">The optional folder. If not defined, use {CurrentFolder}/__admin/mappings</param>
|
||||||
void SaveStaticMappings([CanBeNull] string folder = null);
|
void SaveStaticMappings(string? folder = null);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the basic authentication.
|
/// Sets the basic authentication.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="tenant">The Tenant.</param>
|
/// <param name="tenant">The Tenant.</param>
|
||||||
/// <param name="audience">The Audience or Resource.</param>
|
/// <param name="audience">The Audience or Resource.</param>
|
||||||
void SetAzureADAuthentication([NotNull] string tenant, [NotNull] string audience);
|
void SetAzureADAuthentication(string tenant, string audience);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the basic authentication.
|
/// Sets the basic authentication.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="username">The username.</param>
|
/// <param name="username">The username.</param>
|
||||||
/// <param name="password">The password.</param>
|
/// <param name="password">The password.</param>
|
||||||
void SetBasicAuthentication([NotNull] string username, [NotNull] string password);
|
void SetBasicAuthentication(string username, string password);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the maximum RequestLog count.
|
/// Sets the maximum RequestLog count.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="maxRequestLogCount">The maximum RequestLog count.</param>
|
/// <param name="maxRequestLogCount">The maximum RequestLog count.</param>
|
||||||
void SetMaxRequestLogCount([CanBeNull] int? maxRequestLogCount);
|
void SetMaxRequestLogCount(int? maxRequestLogCount);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets RequestLog expiration in hours.
|
/// Sets RequestLog expiration in hours.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="requestLogExpirationDuration">The RequestLog expiration in hours.</param>
|
/// <param name="requestLogExpirationDuration">The RequestLog expiration in hours.</param>
|
||||||
void SetRequestLogExpirationDuration([CanBeNull] int? requestLogExpirationDuration);
|
void SetRequestLogExpirationDuration(int? requestLogExpirationDuration);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Stop this server.
|
/// Stop this server.
|
||||||
@@ -179,7 +190,7 @@ namespace WireMock.Server
|
|||||||
/// Watches the static mappings for changes.
|
/// Watches the static mappings for changes.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="folder">The optional folder. If not defined, use {CurrentFolder}/__admin/mappings</param>
|
/// <param name="folder">The optional folder. If not defined, use {CurrentFolder}/__admin/mappings</param>
|
||||||
void WatchStaticMappings([CanBeNull] string folder = null);
|
void WatchStaticMappings(string? folder = null);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Register the mappings (via <see cref="MappingModel"/>).
|
/// Register the mappings (via <see cref="MappingModel"/>).
|
||||||
|
|||||||
@@ -1,36 +1,36 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Description>An OpenApi (swagger) parser to generate MappingModel or mapping.json file.</Description>
|
<Description>An OpenApi (swagger) parser to generate MappingModel or mapping.json file.</Description>
|
||||||
<TargetFrameworks>net46;netstandard2.0;netstandard2.1</TargetFrameworks>
|
<TargetFrameworks>net46;netstandard2.0;netstandard2.1</TargetFrameworks>
|
||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
<PackageTags>wiremock;openapi;OAS;converter;parser;openapiparser</PackageTags>
|
<PackageTags>wiremock;openapi;OAS;converter;parser;openapiparser</PackageTags>
|
||||||
<ProjectGuid>{D3804228-91F4-4502-9595-39584E5AADAD}</ProjectGuid>
|
<ProjectGuid>{D3804228-91F4-4502-9595-39584E5AADAD}</ProjectGuid>
|
||||||
<PublishRepositoryUrl>true</PublishRepositoryUrl>
|
<PublishRepositoryUrl>true</PublishRepositoryUrl>
|
||||||
<CodeAnalysisRuleSet>../WireMock.Net/WireMock.Net.ruleset</CodeAnalysisRuleSet>
|
<CodeAnalysisRuleSet>../WireMock.Net/WireMock.Net.ruleset</CodeAnalysisRuleSet>
|
||||||
<SignAssembly>true</SignAssembly>
|
<SignAssembly>true</SignAssembly>
|
||||||
<AssemblyOriginatorKeyFile>../WireMock.Net/WireMock.Net.snk</AssemblyOriginatorKeyFile>
|
<AssemblyOriginatorKeyFile>../WireMock.Net/WireMock.Net.snk</AssemblyOriginatorKeyFile>
|
||||||
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
|
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
|
||||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||||
<LangVersion>8.0</LangVersion>
|
<LangVersion>8.0</LangVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
|
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
|
||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||||
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.2.3" />
|
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.2.3" />
|
||||||
<PackageReference Include="RamlToOpenApiConverter" Version="0.6.1" />
|
<PackageReference Include="RamlToOpenApiConverter" Version="0.6.1" />
|
||||||
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" PrivateAssets="All" />
|
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" PrivateAssets="All" />
|
||||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
|
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
|
||||||
<PackageReference Include="RandomDataGenerator.Net" Version="1.0.14" />
|
<PackageReference Include="RandomDataGenerator.Net" Version="1.0.14" />
|
||||||
<PackageReference Include="Stef.Validation" Version="0.1.0" />
|
<PackageReference Include="Stef.Validation" Version="0.1.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\WireMock.Net.Abstractions\WireMock.Net.Abstractions.csproj" />
|
<ProjectReference Include="..\WireMock.Net.Abstractions\WireMock.Net.Abstractions.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
@@ -106,7 +106,7 @@ namespace WireMock.Handlers
|
|||||||
return File.Exists(AdjustPathForMappingFolder(filename));
|
return File.Exists(AdjustPathForMappingFolder(filename));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IFileSystemHandler.WriteFile(string, byte[])"/>
|
/// <inheritdoc />
|
||||||
public virtual void WriteFile(string filename, byte[] bytes)
|
public virtual void WriteFile(string filename, byte[] bytes)
|
||||||
{
|
{
|
||||||
Guard.NotNullOrEmpty(filename, nameof(filename));
|
Guard.NotNullOrEmpty(filename, nameof(filename));
|
||||||
@@ -115,6 +115,16 @@ namespace WireMock.Handlers
|
|||||||
File.WriteAllBytes(AdjustPathForMappingFolder(filename), bytes);
|
File.WriteAllBytes(AdjustPathForMappingFolder(filename), bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public virtual void WriteFile(string folder, string filename, byte[] bytes)
|
||||||
|
{
|
||||||
|
Guard.NotNullOrEmpty(folder);
|
||||||
|
Guard.NotNullOrEmpty(filename);
|
||||||
|
Guard.NotNull(bytes);
|
||||||
|
|
||||||
|
File.WriteAllBytes(PathUtils.Combine(folder, filename), bytes);
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IFileSystemHandler.DeleteFile"/>
|
/// <inheritdoc cref="IFileSystemHandler.DeleteFile"/>
|
||||||
public virtual void DeleteFile(string filename)
|
public virtual void DeleteFile(string filename)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
@@ -12,7 +12,7 @@ namespace WireMock.Http
|
|||||||
{
|
{
|
||||||
internal static class HttpRequestMessageHelper
|
internal static class HttpRequestMessageHelper
|
||||||
{
|
{
|
||||||
internal static HttpRequestMessage Create([NotNull] RequestMessage requestMessage, [NotNull] string url)
|
internal static HttpRequestMessage Create([NotNull] IRequestMessage requestMessage, [NotNull] string url)
|
||||||
{
|
{
|
||||||
Guard.NotNull(requestMessage, nameof(requestMessage));
|
Guard.NotNull(requestMessage, nameof(requestMessage));
|
||||||
Guard.NotNullOrEmpty(url, nameof(url));
|
Guard.NotNullOrEmpty(url, nameof(url));
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ namespace WireMock.Http
|
|||||||
_settings = settings ?? throw new ArgumentNullException(nameof(settings));
|
_settings = settings ?? throw new ArgumentNullException(nameof(settings));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<HttpResponseMessage> SendAsync([NotNull] HttpClient client, [NotNull] IWebhookRequest request, [NotNull] RequestMessage originalRequestMessage, [NotNull] ResponseMessage originalResponseMessage)
|
public Task<HttpResponseMessage> SendAsync([NotNull] HttpClient client, [NotNull] IWebhookRequest request, [NotNull] IRequestMessage originalRequestMessage, [NotNull] IResponseMessage originalResponseMessage)
|
||||||
{
|
{
|
||||||
Guard.NotNull(client, nameof(client));
|
Guard.NotNull(client, nameof(client));
|
||||||
Guard.NotNull(request, nameof(request));
|
Guard.NotNull(request, nameof(request));
|
||||||
|
|||||||
@@ -28,6 +28,11 @@ namespace WireMock
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
string Title { get; }
|
string Title { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the description.
|
||||||
|
/// </summary>
|
||||||
|
string Description { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The full filename path for this mapping (only defined for static mappings).
|
/// The full filename path for this mapping (only defined for static mappings).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -117,7 +122,7 @@ namespace WireMock
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="requestMessage">The request message.</param>
|
/// <param name="requestMessage">The request message.</param>
|
||||||
/// <returns>The <see cref="ResponseMessage"/> including a new (optional) <see cref="IMapping"/>.</returns>
|
/// <returns>The <see cref="ResponseMessage"/> including a new (optional) <see cref="IMapping"/>.</returns>
|
||||||
Task<(ResponseMessage Message, IMapping Mapping)> ProvideResponseAsync(RequestMessage requestMessage);
|
Task<(IResponseMessage Message, IMapping Mapping)> ProvideResponseAsync(IRequestMessage requestMessage);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the RequestMatchResult based on the RequestMessage.
|
/// Gets the RequestMatchResult based on the RequestMessage.
|
||||||
@@ -125,6 +130,6 @@ namespace WireMock
|
|||||||
/// <param name="requestMessage">The request message.</param>
|
/// <param name="requestMessage">The request message.</param>
|
||||||
/// <param name="nextState">The Next State.</param>
|
/// <param name="nextState">The Next State.</param>
|
||||||
/// <returns>The <see cref="IRequestMatchResult"/>.</returns>
|
/// <returns>The <see cref="IRequestMatchResult"/>.</returns>
|
||||||
RequestMatchResult GetRequestMatchResult(RequestMessage requestMessage, [CanBeNull] string nextState);
|
IRequestMatchResult GetRequestMatchResult(IRequestMessage requestMessage, [CanBeNull] string nextState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+19
-13
@@ -19,6 +19,9 @@ namespace WireMock
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string Title { get; }
|
public string Title { get; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public string Description { get; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string Path { get; set; }
|
public string Path { get; set; }
|
||||||
|
|
||||||
@@ -69,6 +72,7 @@ namespace WireMock
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="guid">The unique identifier.</param>
|
/// <param name="guid">The unique identifier.</param>
|
||||||
/// <param name="title">The unique title (can be null).</param>
|
/// <param name="title">The unique title (can be null).</param>
|
||||||
|
/// <param name="description">The description (can be null).</param>
|
||||||
/// <param name="path">The full file path from this mapping title (can be null).</param>
|
/// <param name="path">The full file path from this mapping title (can be null).</param>
|
||||||
/// <param name="settings">The WireMockServerSettings.</param>
|
/// <param name="settings">The WireMockServerSettings.</param>
|
||||||
/// <param name="requestMatcher">The request matcher.</param>
|
/// <param name="requestMatcher">The request matcher.</param>
|
||||||
@@ -82,21 +86,23 @@ namespace WireMock
|
|||||||
/// <param name="timeSettings">The TimeSettings. [Optional]</param>
|
/// <param name="timeSettings">The TimeSettings. [Optional]</param>
|
||||||
public Mapping(
|
public Mapping(
|
||||||
Guid guid,
|
Guid guid,
|
||||||
[CanBeNull] string title,
|
string? title,
|
||||||
[CanBeNull] string path,
|
string? description,
|
||||||
[NotNull] WireMockServerSettings settings,
|
string? path,
|
||||||
[NotNull] IRequestMatcher requestMatcher,
|
WireMockServerSettings settings,
|
||||||
[NotNull] IResponseProvider provider,
|
IRequestMatcher requestMatcher,
|
||||||
|
IResponseProvider provider,
|
||||||
int priority,
|
int priority,
|
||||||
[CanBeNull] string scenario,
|
string? scenario,
|
||||||
[CanBeNull] string executionConditionState,
|
string? executionConditionState,
|
||||||
[CanBeNull] string nextState,
|
string? nextState,
|
||||||
[CanBeNull] int? stateTimes,
|
int? stateTimes,
|
||||||
[CanBeNull] IWebhook[] webhooks,
|
IWebhook[]? webhooks,
|
||||||
[CanBeNull] ITimeSettings timeSettings)
|
ITimeSettings? timeSettings)
|
||||||
{
|
{
|
||||||
Guid = guid;
|
Guid = guid;
|
||||||
Title = title;
|
Title = title;
|
||||||
|
Description = description;
|
||||||
Path = path;
|
Path = path;
|
||||||
Settings = settings;
|
Settings = settings;
|
||||||
RequestMatcher = requestMatcher;
|
RequestMatcher = requestMatcher;
|
||||||
@@ -111,13 +117,13 @@ namespace WireMock
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IMapping.ProvideResponseAsync" />
|
/// <inheritdoc cref="IMapping.ProvideResponseAsync" />
|
||||||
public Task<(ResponseMessage Message, IMapping Mapping)> ProvideResponseAsync(RequestMessage requestMessage)
|
public Task<(IResponseMessage Message, IMapping Mapping)> ProvideResponseAsync(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
return Provider.ProvideResponseAsync(requestMessage, Settings);
|
return Provider.ProvideResponseAsync(requestMessage, Settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IMapping.GetRequestMatchResult" />
|
/// <inheritdoc cref="IMapping.GetRequestMatchResult" />
|
||||||
public RequestMatchResult GetRequestMatchResult(RequestMessage requestMessage, string nextState)
|
public IRequestMatchResult GetRequestMatchResult(IRequestMessage requestMessage, string nextState)
|
||||||
{
|
{
|
||||||
var result = new RequestMatchResult();
|
var result = new RequestMatchResult();
|
||||||
|
|
||||||
|
|||||||
@@ -114,8 +114,8 @@ namespace WireMock.Matchers.Request
|
|||||||
Matchers = matchers;
|
Matchers = matchers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <see cref="IRequestMatcher.GetMatchingScore"/>
|
/// <inheritdoc />
|
||||||
public double GetMatchingScore(IRequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
public double GetMatchingScore(IRequestMessage requestMessage, IRequestMatchResult requestMatchResult)
|
||||||
{
|
{
|
||||||
double score = CalculateMatchScore(requestMessage);
|
double score = CalculateMatchScore(requestMessage);
|
||||||
return requestMatchResult.AddScore(GetType(), score);
|
return requestMatchResult.AddScore(GetType(), score);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
@@ -50,8 +50,8 @@ namespace WireMock.Matchers.Request
|
|||||||
Funcs = funcs;
|
Funcs = funcs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
/// <inheritdoc />
|
||||||
public double GetMatchingScore(IRequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
public double GetMatchingScore(IRequestMessage requestMessage, IRequestMatchResult requestMatchResult)
|
||||||
{
|
{
|
||||||
double score = IsMatch(requestMessage);
|
double score = IsMatch(requestMessage);
|
||||||
return requestMatchResult.AddScore(GetType(), score);
|
return requestMatchResult.AddScore(GetType(), score);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Stef.Validation;
|
using Stef.Validation;
|
||||||
@@ -33,8 +33,8 @@ namespace WireMock.Matchers.Request
|
|||||||
RequestMatchers = requestMatchers;
|
RequestMatchers = requestMatchers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
/// <inheritdoc />
|
||||||
public double GetMatchingScore(IRequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
public double GetMatchingScore(IRequestMessage requestMessage, IRequestMatchResult requestMatchResult)
|
||||||
{
|
{
|
||||||
if (!RequestMatchers.Any())
|
if (!RequestMatchers.Any())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
@@ -90,8 +90,8 @@ namespace WireMock.Matchers.Request
|
|||||||
Funcs = funcs;
|
Funcs = funcs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
/// <inheritdoc />
|
||||||
public double GetMatchingScore(IRequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
public double GetMatchingScore(IRequestMessage requestMessage, IRequestMatchResult requestMatchResult)
|
||||||
{
|
{
|
||||||
double score = IsMatch(requestMessage);
|
double score = IsMatch(requestMessage);
|
||||||
return requestMatchResult.AddScore(GetType(), score);
|
return requestMatchResult.AddScore(GetType(), score);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -91,8 +91,8 @@ namespace WireMock.Matchers.Request
|
|||||||
Funcs = funcs;
|
Funcs = funcs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
/// <inheritdoc />
|
||||||
public double GetMatchingScore(IRequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
public double GetMatchingScore(IRequestMessage requestMessage, IRequestMatchResult requestMatchResult)
|
||||||
{
|
{
|
||||||
double score = IsMatch(requestMessage);
|
double score = IsMatch(requestMessage);
|
||||||
return requestMatchResult.AddScore(GetType(), score);
|
return requestMatchResult.AddScore(GetType(), score);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Stef.Validation;
|
using Stef.Validation;
|
||||||
@@ -30,8 +30,8 @@ namespace WireMock.Matchers.Request
|
|||||||
Methods = methods;
|
Methods = methods;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
/// <inheritdoc />
|
||||||
public double GetMatchingScore(IRequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
public double GetMatchingScore(IRequestMessage requestMessage, IRequestMatchResult requestMatchResult)
|
||||||
{
|
{
|
||||||
double score = MatchBehaviourHelper.Convert(_matchBehaviour, IsMatch(requestMessage));
|
double score = MatchBehaviourHelper.Convert(_matchBehaviour, IsMatch(requestMessage));
|
||||||
return requestMatchResult.AddScore(GetType(), score);
|
return requestMatchResult.AddScore(GetType(), score);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -83,8 +83,8 @@ namespace WireMock.Matchers.Request
|
|||||||
Funcs = funcs;
|
Funcs = funcs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
/// <inheritdoc />
|
||||||
public double GetMatchingScore(IRequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
public double GetMatchingScore(IRequestMessage requestMessage, IRequestMatchResult requestMatchResult)
|
||||||
{
|
{
|
||||||
double score = MatchBehaviourHelper.Convert(_matchBehaviour, IsMatch(requestMessage));
|
double score = MatchBehaviourHelper.Convert(_matchBehaviour, IsMatch(requestMessage));
|
||||||
return requestMatchResult.AddScore(GetType(), score);
|
return requestMatchResult.AddScore(GetType(), score);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
@@ -53,7 +53,7 @@ namespace WireMock.Matchers.Request
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
||||||
public double GetMatchingScore(IRequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
public double GetMatchingScore(IRequestMessage requestMessage, IRequestMatchResult requestMatchResult)
|
||||||
{
|
{
|
||||||
double score = IsMatch(requestMessage);
|
double score = IsMatch(requestMessage);
|
||||||
return requestMatchResult.AddScore(GetType(), score);
|
return requestMatchResult.AddScore(GetType(), score);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
|
|
||||||
namespace WireMock.Matchers.Request
|
namespace WireMock.Matchers.Request
|
||||||
{
|
{
|
||||||
@@ -32,7 +32,7 @@ namespace WireMock.Matchers.Request
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public double GetMatchingScore(IRequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
public double GetMatchingScore(IRequestMessage requestMessage, IRequestMatchResult requestMatchResult)
|
||||||
{
|
{
|
||||||
double score = IsMatch();
|
double score = IsMatch();
|
||||||
return requestMatchResult.AddScore(GetType(), score);
|
return requestMatchResult.AddScore(GetType(), score);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
@@ -50,8 +50,8 @@ namespace WireMock.Matchers.Request
|
|||||||
Funcs = funcs;
|
Funcs = funcs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
/// <inheritdoc />
|
||||||
public double GetMatchingScore(IRequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
public double GetMatchingScore(IRequestMessage requestMessage, IRequestMatchResult requestMatchResult)
|
||||||
{
|
{
|
||||||
double score = IsMatch(requestMessage);
|
double score = IsMatch(requestMessage);
|
||||||
return requestMatchResult.AddScore(GetType(), score);
|
return requestMatchResult.AddScore(GetType(), score);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using WireMock.Types;
|
using WireMock.Types;
|
||||||
|
|
||||||
namespace WireMock.Util
|
namespace WireMock.Util
|
||||||
@@ -9,33 +9,33 @@ namespace WireMock.Util
|
|||||||
public class BodyData : IBodyData
|
public class BodyData : IBodyData
|
||||||
{
|
{
|
||||||
/// <inheritdoc cref="IBodyData.Encoding" />
|
/// <inheritdoc cref="IBodyData.Encoding" />
|
||||||
public Encoding Encoding { get; set; }
|
public Encoding? Encoding { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc cref="IBodyData.BodyAsBytes" />
|
/// <inheritdoc cref="IBodyData.BodyAsBytes" />
|
||||||
public string BodyAsString { get; set; }
|
public string? BodyAsString { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc cref="IBodyData.BodyAsJson" />
|
/// <inheritdoc cref="IBodyData.BodyAsJson" />
|
||||||
public object BodyAsJson { get; set; }
|
public object? BodyAsJson { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc cref="IBodyData.BodyAsBytes" />
|
/// <inheritdoc cref="IBodyData.BodyAsBytes" />
|
||||||
public byte[] BodyAsBytes { get; set; }
|
public byte[]? BodyAsBytes { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc cref="IBodyData.BodyAsJsonIndented" />
|
/// <inheritdoc cref="IBodyData.BodyAsJsonIndented" />
|
||||||
public bool? BodyAsJsonIndented { get; set; }
|
public bool? BodyAsJsonIndented { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc cref="IBodyData.BodyAsFile" />
|
/// <inheritdoc cref="IBodyData.BodyAsFile" />
|
||||||
public string BodyAsFile { get; set; }
|
public string? BodyAsFile { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc cref="IBodyData.BodyAsFileIsCached" />
|
/// <inheritdoc cref="IBodyData.BodyAsFileIsCached" />
|
||||||
public bool? BodyAsFileIsCached { get; set; }
|
public bool? BodyAsFileIsCached { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc cref="IBodyData.DetectedBodyType" />
|
/// <inheritdoc cref="IBodyData.DetectedBodyType" />
|
||||||
public BodyType DetectedBodyType { get; set; }
|
public BodyType? DetectedBodyType { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc cref="IBodyData.DetectedBodyTypeFromContentType" />
|
/// <inheritdoc cref="IBodyData.DetectedBodyTypeFromContentType" />
|
||||||
public BodyType DetectedBodyTypeFromContentType { get; set; }
|
public BodyType? DetectedBodyTypeFromContentType { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc cref="IRequestMessage.DetectedCompression" />
|
/// <inheritdoc cref="IRequestMessage.DetectedCompression" />
|
||||||
public string DetectedCompression { get; set; }
|
public string? DetectedCompression { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,6 @@ using WireMock.Handlers;
|
|||||||
using WireMock.Logging;
|
using WireMock.Logging;
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using WireMock.Util;
|
using WireMock.Util;
|
||||||
using JetBrains.Annotations;
|
|
||||||
using WireMock.Types;
|
using WireMock.Types;
|
||||||
#if !USE_ASPNETCORE
|
#if !USE_ASPNETCORE
|
||||||
using Owin;
|
using Owin;
|
||||||
@@ -21,7 +20,7 @@ namespace WireMock.Owin
|
|||||||
|
|
||||||
TimeSpan? RequestProcessingDelay { get; set; }
|
TimeSpan? RequestProcessingDelay { get; set; }
|
||||||
|
|
||||||
IStringMatcher AuthenticationMatcher { get; set; }
|
IStringMatcher? AuthenticationMatcher { get; set; }
|
||||||
|
|
||||||
bool? AllowPartialMapping { get; set; }
|
bool? AllowPartialMapping { get; set; }
|
||||||
|
|
||||||
@@ -35,17 +34,17 @@ namespace WireMock.Owin
|
|||||||
|
|
||||||
int? MaxRequestLogCount { get; set; }
|
int? MaxRequestLogCount { get; set; }
|
||||||
|
|
||||||
Action<IAppBuilder> PreWireMockMiddlewareInit { get; set; }
|
Action<IAppBuilder>? PreWireMockMiddlewareInit { get; set; }
|
||||||
|
|
||||||
Action<IAppBuilder> PostWireMockMiddlewareInit { get; set; }
|
Action<IAppBuilder>? PostWireMockMiddlewareInit { get; set; }
|
||||||
|
|
||||||
#if USE_ASPNETCORE
|
#if USE_ASPNETCORE
|
||||||
Action<IServiceCollection> AdditionalServiceRegistration { get; set; }
|
Action<IServiceCollection>? AdditionalServiceRegistration { get; set; }
|
||||||
|
|
||||||
CorsPolicyOptions? CorsPolicyOptions { get; set; }
|
CorsPolicyOptions? CorsPolicyOptions { get; set; }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
IFileSystemHandler FileSystemHandler { get; set; }
|
IFileSystemHandler? FileSystemHandler { get; set; }
|
||||||
|
|
||||||
bool? AllowBodyForAllHttpMethods { get; set; }
|
bool? AllowBodyForAllHttpMethods { get; set; }
|
||||||
|
|
||||||
@@ -57,15 +56,15 @@ namespace WireMock.Owin
|
|||||||
|
|
||||||
bool? HandleRequestsSynchronously { get; set; }
|
bool? HandleRequestsSynchronously { get; set; }
|
||||||
|
|
||||||
string X509StoreName { get; set; }
|
string? X509StoreName { get; set; }
|
||||||
|
|
||||||
string X509StoreLocation { get; set; }
|
string? X509StoreLocation { get; set; }
|
||||||
|
|
||||||
string X509ThumbprintOrSubjectName { get; set; }
|
string? X509ThumbprintOrSubjectName { get; set; }
|
||||||
|
|
||||||
string X509CertificateFilePath { get; set; }
|
string? X509CertificateFilePath { get; set; }
|
||||||
|
|
||||||
string X509CertificatePassword { get; set; }
|
string? X509CertificatePassword { get; set; }
|
||||||
|
|
||||||
bool CustomCertificateDefined { get; }
|
bool CustomCertificateDefined { get; }
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
#if !USE_ASPNETCORE
|
#if !USE_ASPNETCORE
|
||||||
using IResponse = Microsoft.Owin.IOwinResponse;
|
using IResponse = Microsoft.Owin.IOwinResponse;
|
||||||
#else
|
#else
|
||||||
@@ -17,6 +17,6 @@ namespace WireMock.Owin.Mappers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="responseMessage">The ResponseMessage</param>
|
/// <param name="responseMessage">The ResponseMessage</param>
|
||||||
/// <param name="response">The OwinResponse/HttpResponse</param>
|
/// <param name="response">The OwinResponse/HttpResponse</param>
|
||||||
Task MapAsync(ResponseMessage responseMessage, IResponse response);
|
Task MapAsync(IResponseMessage responseMessage, IResponse response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -53,7 +53,7 @@ namespace WireMock.Owin.Mappers
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IOwinResponseMapper.MapAsync"/>
|
/// <inheritdoc cref="IOwinResponseMapper.MapAsync"/>
|
||||||
public async Task MapAsync(ResponseMessage responseMessage, IResponse response)
|
public async Task MapAsync(IResponseMessage responseMessage, IResponse response)
|
||||||
{
|
{
|
||||||
if (responseMessage == null)
|
if (responseMessage == null)
|
||||||
{
|
{
|
||||||
@@ -117,12 +117,12 @@ namespace WireMock.Owin.Mappers
|
|||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsFault(ResponseMessage responseMessage)
|
private bool IsFault(IResponseMessage responseMessage)
|
||||||
{
|
{
|
||||||
return responseMessage.FaultPercentage == null || _randomizerDouble.Generate() <= responseMessage.FaultPercentage;
|
return responseMessage.FaultPercentage == null || _randomizerDouble.Generate() <= responseMessage.FaultPercentage;
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] GetNormalBody(ResponseMessage responseMessage)
|
private byte[] GetNormalBody(IResponseMessage responseMessage)
|
||||||
{
|
{
|
||||||
byte[] bytes = null;
|
byte[] bytes = null;
|
||||||
switch (responseMessage.BodyData?.DetectedBodyType)
|
switch (responseMessage.BodyData?.DetectedBodyType)
|
||||||
@@ -151,7 +151,7 @@ namespace WireMock.Owin.Mappers
|
|||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SetResponseHeaders(ResponseMessage responseMessage, IResponse response)
|
private static void SetResponseHeaders(IResponseMessage responseMessage, IResponse response)
|
||||||
{
|
{
|
||||||
// Force setting the Date header (#577)
|
// Force setting the Date header (#577)
|
||||||
AppendResponseHeader(
|
AppendResponseHeader(
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using WireMock.Matchers.Request;
|
using WireMock.Matchers.Request;
|
||||||
|
|
||||||
namespace WireMock.Owin
|
namespace WireMock.Owin
|
||||||
{
|
{
|
||||||
@@ -6,6 +6,6 @@ namespace WireMock.Owin
|
|||||||
{
|
{
|
||||||
public IMapping Mapping { get; set; }
|
public IMapping Mapping { get; set; }
|
||||||
|
|
||||||
public RequestMatchResult RequestMatchResult { get; set; }
|
public IRequestMatchResult RequestMatchResult { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -72,7 +72,7 @@ namespace WireMock.Owin
|
|||||||
var request = await _requestMapper.MapAsync(ctx.Request, _options).ConfigureAwait(false);
|
var request = await _requestMapper.MapAsync(ctx.Request, _options).ConfigureAwait(false);
|
||||||
|
|
||||||
var logRequest = false;
|
var logRequest = false;
|
||||||
ResponseMessage response = null;
|
IResponseMessage response = null;
|
||||||
(MappingMatcherResult Match, MappingMatcherResult Partial) result = (null, null);
|
(MappingMatcherResult Match, MappingMatcherResult Partial) result = (null, null);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -192,7 +192,7 @@ namespace WireMock.Owin
|
|||||||
await CompletedTask.ConfigureAwait(false);
|
await CompletedTask.ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task SendToWebhooksAsync(IMapping mapping, RequestMessage request, ResponseMessage response)
|
private async Task SendToWebhooksAsync(IMapping mapping, IRequestMessage request, IResponseMessage response)
|
||||||
{
|
{
|
||||||
for (int index = 0; index < mapping.Webhooks.Length; index++)
|
for (int index = 0; index < mapping.Webhooks.Length; index++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
namespace WireMock.Pact.Models.V2
|
||||||
|
{
|
||||||
|
public class Interaction
|
||||||
|
{
|
||||||
|
public string Description { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string ProviderState { get; set; }
|
||||||
|
|
||||||
|
public Request Request { get; set; } = new Request();
|
||||||
|
|
||||||
|
public Response Response { get; set; } = new Response();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
namespace WireMock.Pact.Models.V2
|
||||||
|
{
|
||||||
|
public class MatchingRule
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// type or regex
|
||||||
|
/// </summary>
|
||||||
|
public string Match { get; set; } = "type";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Used for Match = "type"
|
||||||
|
/// </summary>
|
||||||
|
public string Min { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Used for Match = "type"
|
||||||
|
/// </summary>
|
||||||
|
public string Max { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Used for Match = "regex"
|
||||||
|
/// </summary>
|
||||||
|
public string Regex { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
namespace WireMock.Pact.Models.V2
|
||||||
|
{
|
||||||
|
public class Metadata
|
||||||
|
{
|
||||||
|
public string PactSpecificationVersion { get; set; }
|
||||||
|
|
||||||
|
public PactSpecification PactSpecification { get; set; } = new PactSpecification();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace WireMock.Pact.Models.V2
|
||||||
|
{
|
||||||
|
public class Pact
|
||||||
|
{
|
||||||
|
public Pacticipant Consumer { get; set; }
|
||||||
|
|
||||||
|
public List<Interaction> Interactions { get; set; } = new List<Interaction>();
|
||||||
|
|
||||||
|
public Metadata Metadata { get; set; }
|
||||||
|
|
||||||
|
public Pacticipant Provider { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
namespace WireMock.Pact.Models.V2
|
||||||
|
{
|
||||||
|
public class PactRust
|
||||||
|
{
|
||||||
|
public string Ffi { get; set; }
|
||||||
|
|
||||||
|
public string Mockserver { get; set; }
|
||||||
|
|
||||||
|
public string Models { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace WireMock.Pact.Models.V2
|
||||||
|
{
|
||||||
|
public class PactSpecification
|
||||||
|
{
|
||||||
|
public string Version { get; set; } = "2.0";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace WireMock.Pact.Models.V2
|
||||||
|
{
|
||||||
|
public class Pacticipant
|
||||||
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace WireMock.Pact.Models.V2
|
||||||
|
{
|
||||||
|
public class ProviderState
|
||||||
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
public IDictionary<string, string> Params { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace WireMock.Pact.Models.V2;
|
||||||
|
|
||||||
|
public class Request
|
||||||
|
{
|
||||||
|
public IDictionary<string, string>? Headers { get; set; }
|
||||||
|
|
||||||
|
public string Method { get; set; } = "GET";
|
||||||
|
|
||||||
|
public string? Path { get; set; } = "/";
|
||||||
|
|
||||||
|
public string? Query { get; set; }
|
||||||
|
|
||||||
|
public object? Body { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace WireMock.Pact.Models.V2;
|
||||||
|
|
||||||
|
public class Response
|
||||||
|
{
|
||||||
|
public object? Body { get; set; }
|
||||||
|
|
||||||
|
public IDictionary<string, string>? Headers { get; set; }
|
||||||
|
|
||||||
|
public int Status { get; set; } = 200;
|
||||||
|
}
|
||||||
@@ -0,0 +1,206 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema",
|
||||||
|
"definitions": {
|
||||||
|
"headers": {
|
||||||
|
"additionalProperties": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"type": "object"
|
||||||
|
},
|
||||||
|
"interaction": {
|
||||||
|
"additionalProperties": false,
|
||||||
|
"properties": {
|
||||||
|
"description": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"providerState": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"request": {
|
||||||
|
"$ref": "#/definitions/request"
|
||||||
|
},
|
||||||
|
"response": {
|
||||||
|
"$ref": "#/definitions/response"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"description",
|
||||||
|
"request",
|
||||||
|
"response"
|
||||||
|
],
|
||||||
|
"type": "object"
|
||||||
|
},
|
||||||
|
"interactions": {
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/interaction"
|
||||||
|
},
|
||||||
|
"type": "array"
|
||||||
|
},
|
||||||
|
"matchingRules": {
|
||||||
|
"additionalProperties": false,
|
||||||
|
"patternProperties": {
|
||||||
|
"^\\$.*$": {
|
||||||
|
"oneOf": [
|
||||||
|
{
|
||||||
|
"additionalProperties": false,
|
||||||
|
"properties": {
|
||||||
|
"match": {
|
||||||
|
"enum": [ "type" ],
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"max": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"min": {
|
||||||
|
"type": "number"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [ "match" ],
|
||||||
|
"type": "object"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"additionalProperties": false,
|
||||||
|
"properties": {
|
||||||
|
"match": {
|
||||||
|
"enum": [ "regex" ],
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"regex": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"match",
|
||||||
|
"regex"
|
||||||
|
],
|
||||||
|
"type": "object"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"type": "object"
|
||||||
|
},
|
||||||
|
"metadata": {
|
||||||
|
"properties": {
|
||||||
|
"pactSpecification": {
|
||||||
|
"additionalProperties": false,
|
||||||
|
"properties": {
|
||||||
|
"version": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [ "version" ],
|
||||||
|
"type": "object"
|
||||||
|
},
|
||||||
|
"pactSpecificationVersion": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"pact-specification": {
|
||||||
|
"additionalProperties": false,
|
||||||
|
"properties": {
|
||||||
|
"version": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [ "version" ],
|
||||||
|
"type": "object"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"type": "object"
|
||||||
|
},
|
||||||
|
"pacticipant": {
|
||||||
|
"properties": {
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [ "name" ],
|
||||||
|
"type": "object"
|
||||||
|
},
|
||||||
|
"request": {
|
||||||
|
"additionalProperties": false,
|
||||||
|
"properties": {
|
||||||
|
"body": {},
|
||||||
|
"headers": {
|
||||||
|
"$ref": "#/definitions/headers"
|
||||||
|
},
|
||||||
|
"matchingRules": {
|
||||||
|
"$ref": "#/definitions/matchingRules"
|
||||||
|
},
|
||||||
|
"method": {
|
||||||
|
"enum": [
|
||||||
|
"connect",
|
||||||
|
"CONNECT",
|
||||||
|
"delete",
|
||||||
|
"DELETE",
|
||||||
|
"get",
|
||||||
|
"GET",
|
||||||
|
"head",
|
||||||
|
"HEAD",
|
||||||
|
"options",
|
||||||
|
"OPTIONS",
|
||||||
|
"post",
|
||||||
|
"POST",
|
||||||
|
"put",
|
||||||
|
"PUT",
|
||||||
|
"trace",
|
||||||
|
"TRACE"
|
||||||
|
],
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"path": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"query": {
|
||||||
|
"pattern": "^$|^[^=&]+=[^=&]+&?$|^[^=&]+=[^=&]+(&[^=&]+=[^=&]+)*&?$",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"method",
|
||||||
|
"path"
|
||||||
|
],
|
||||||
|
"type": "object"
|
||||||
|
},
|
||||||
|
"response": {
|
||||||
|
"additionalProperties": false,
|
||||||
|
"properties": {
|
||||||
|
"body": {},
|
||||||
|
"headers": {
|
||||||
|
"$ref": "#/definitions/headers"
|
||||||
|
},
|
||||||
|
"matchingRules": {
|
||||||
|
"$ref": "#/definitions/matchingRules"
|
||||||
|
},
|
||||||
|
"status": {
|
||||||
|
"maximum": 599,
|
||||||
|
"minimum": 100,
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [ "status" ],
|
||||||
|
"type": "object"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"description": "Schema for a Pact file",
|
||||||
|
"properties": {
|
||||||
|
"consumer": {
|
||||||
|
"$ref": "#/definitions/pacticipant"
|
||||||
|
},
|
||||||
|
"interactions": {
|
||||||
|
"$ref": "#/definitions/interactions"
|
||||||
|
},
|
||||||
|
"metadata": {
|
||||||
|
"$ref": "#/definitions/metadata"
|
||||||
|
},
|
||||||
|
"provider": {
|
||||||
|
"$ref": "#/definitions/pacticipant"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"consumer",
|
||||||
|
"interactions",
|
||||||
|
"provider"
|
||||||
|
],
|
||||||
|
"type": "object"
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
[assembly: InternalsVisibleTo("WireMock.Net.Matchers.CSharpCode, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e138ec44d93acac565953052636eb8d5e7e9f27ddb030590055cd1a0ab2069a5623f1f77ca907d78e0b37066ca0f6d63da7eecc3fcb65b76aa8ebeccf7ebe1d11264b8404cd9b1cbbf2c83f566e033b3e54129f6ef28daffff776ba7aebbc53c0d635ebad8f45f78eb3f7e0459023c218f003416e080f96a1a3c5ffeb56bee9e")]
|
[assembly: InternalsVisibleTo("WireMock.Net.Matchers.CSharpCode, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e138ec44d93acac565953052636eb8d5e7e9f27ddb030590055cd1a0ab2069a5623f1f77ca907d78e0b37066ca0f6d63da7eecc3fcb65b76aa8ebeccf7ebe1d11264b8404cd9b1cbbf2c83f566e033b3e54129f6ef28daffff776ba7aebbc53c0d635ebad8f45f78eb3f7e0459023c218f003416e080f96a1a3c5ffeb56bee9e")]
|
||||||
[assembly: InternalsVisibleTo("WireMock.Net.StandAlone, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e138ec44d93acac565953052636eb8d5e7e9f27ddb030590055cd1a0ab2069a5623f1f77ca907d78e0b37066ca0f6d63da7eecc3fcb65b76aa8ebeccf7ebe1d11264b8404cd9b1cbbf2c83f566e033b3e54129f6ef28daffff776ba7aebbc53c0d635ebad8f45f78eb3f7e0459023c218f003416e080f96a1a3c5ffeb56bee9e")]
|
[assembly: InternalsVisibleTo("WireMock.Net.StandAlone, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e138ec44d93acac565953052636eb8d5e7e9f27ddb030590055cd1a0ab2069a5623f1f77ca907d78e0b37066ca0f6d63da7eecc3fcb65b76aa8ebeccf7ebe1d11264b8404cd9b1cbbf2c83f566e033b3e54129f6ef28daffff776ba7aebbc53c0d635ebad8f45f78eb3f7e0459023c218f003416e080f96a1a3c5ffeb56bee9e")]
|
||||||
[assembly: InternalsVisibleTo("WireMock.Net.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e138ec44d93acac565953052636eb8d5e7e9f27ddb030590055cd1a0ab2069a5623f1f77ca907d78e0b37066ca0f6d63da7eecc3fcb65b76aa8ebeccf7ebe1d11264b8404cd9b1cbbf2c83f566e033b3e54129f6ef28daffff776ba7aebbc53c0d635ebad8f45f78eb3f7e0459023c218f003416e080f96a1a3c5ffeb56bee9e")]
|
[assembly: InternalsVisibleTo("WireMock.Net.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e138ec44d93acac565953052636eb8d5e7e9f27ddb030590055cd1a0ab2069a5623f1f77ca907d78e0b37066ca0f6d63da7eecc3fcb65b76aa8ebeccf7ebe1d11264b8404cd9b1cbbf2c83f566e033b3e54129f6ef28daffff776ba7aebbc53c0d635ebad8f45f78eb3f7e0459023c218f003416e080f96a1a3c5ffeb56bee9e")]
|
||||||
|
|
||||||
// Needed for Moq in the UnitTest project
|
// Needed for Moq in the UnitTest project
|
||||||
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
|
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
|
||||||
@@ -24,10 +24,10 @@ namespace WireMock.Proxy
|
|||||||
_settings = Guard.NotNull(settings, nameof(settings));
|
_settings = Guard.NotNull(settings, nameof(settings));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<(ResponseMessage Message, IMapping Mapping)> SendAsync(
|
public async Task<(IResponseMessage Message, IMapping Mapping)> SendAsync(
|
||||||
[NotNull] ProxyAndRecordSettings proxyAndRecordSettings,
|
[NotNull] ProxyAndRecordSettings proxyAndRecordSettings,
|
||||||
[NotNull] HttpClient client,
|
[NotNull] HttpClient client,
|
||||||
[NotNull] RequestMessage requestMessage,
|
[NotNull] IRequestMessage requestMessage,
|
||||||
[NotNull] string url)
|
[NotNull] string url)
|
||||||
{
|
{
|
||||||
Guard.NotNull(client, nameof(client));
|
Guard.NotNull(client, nameof(client));
|
||||||
@@ -59,7 +59,7 @@ namespace WireMock.Proxy
|
|||||||
return (responseMessage, mapping);
|
return (responseMessage, mapping);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IMapping ToMapping(ProxyAndRecordSettings proxyAndRecordSettings, RequestMessage requestMessage, ResponseMessage responseMessage)
|
private IMapping ToMapping(ProxyAndRecordSettings proxyAndRecordSettings, IRequestMessage requestMessage, ResponseMessage responseMessage)
|
||||||
{
|
{
|
||||||
string[] excludedHeaders = proxyAndRecordSettings.ExcludedHeaders ?? new string[] { };
|
string[] excludedHeaders = proxyAndRecordSettings.ExcludedHeaders ?? new string[] { };
|
||||||
string[] excludedCookies = proxyAndRecordSettings.ExcludedCookies ?? new string[] { };
|
string[] excludedCookies = proxyAndRecordSettings.ExcludedCookies ?? new string[] { };
|
||||||
@@ -104,7 +104,7 @@ namespace WireMock.Proxy
|
|||||||
|
|
||||||
var response = Response.Create(responseMessage);
|
var response = Response.Create(responseMessage);
|
||||||
|
|
||||||
return new Mapping(Guid.NewGuid(), string.Empty, null, _settings, request, response, 0, null, null, null, null, null, null);
|
return new Mapping(Guid.NewGuid(), string.Empty, string.Empty, null, _settings, request, response, 0, null, null, null, null, null, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
using JetBrains.Annotations;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -17,7 +16,7 @@ namespace WireMock.ResponseBuilders
|
|||||||
/// <param name="destination">The Body Destination format (SameAsSource, String or Bytes).</param>
|
/// <param name="destination">The Body Destination format (SameAsSource, String or Bytes).</param>
|
||||||
/// <param name="encoding">The body encoding.</param>
|
/// <param name="encoding">The body encoding.</param>
|
||||||
/// <returns>A <see cref="IResponseBuilder"/>.</returns>
|
/// <returns>A <see cref="IResponseBuilder"/>.</returns>
|
||||||
IResponseBuilder WithBody([NotNull] string body, [CanBeNull] string destination = BodyDestinationFormat.SameAsSource, [CanBeNull] Encoding encoding = null);
|
IResponseBuilder WithBody(string body, string? destination = BodyDestinationFormat.SameAsSource, Encoding? encoding = null);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// WithBody : Create a ... response based on a callback function.
|
/// WithBody : Create a ... response based on a callback function.
|
||||||
@@ -26,7 +25,7 @@ namespace WireMock.ResponseBuilders
|
|||||||
/// <param name="destination">The Body Destination format (SameAsSource, String or Bytes).</param>
|
/// <param name="destination">The Body Destination format (SameAsSource, String or Bytes).</param>
|
||||||
/// <param name="encoding">The body encoding.</param>
|
/// <param name="encoding">The body encoding.</param>
|
||||||
/// <returns>A <see cref="IResponseBuilder"/>.</returns>
|
/// <returns>A <see cref="IResponseBuilder"/>.</returns>
|
||||||
IResponseBuilder WithBody([NotNull] Func<RequestMessage, string> bodyFactory, [CanBeNull] string destination = BodyDestinationFormat.SameAsSource, [CanBeNull] Encoding encoding = null);
|
IResponseBuilder WithBody(Func<IRequestMessage, string> bodyFactory, string? destination = BodyDestinationFormat.SameAsSource, Encoding? encoding = null);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// WithBody : Create a ... response based on a callback function.
|
/// WithBody : Create a ... response based on a callback function.
|
||||||
@@ -35,7 +34,7 @@ namespace WireMock.ResponseBuilders
|
|||||||
/// <param name="destination">The Body Destination format (SameAsSource, String or Bytes).</param>
|
/// <param name="destination">The Body Destination format (SameAsSource, String or Bytes).</param>
|
||||||
/// <param name="encoding">The body encoding.</param>
|
/// <param name="encoding">The body encoding.</param>
|
||||||
/// <returns>A <see cref="IResponseBuilder"/>.</returns>
|
/// <returns>A <see cref="IResponseBuilder"/>.</returns>
|
||||||
IResponseBuilder WithBody([NotNull] Func<RequestMessage, Task<string>> bodyFactory, [CanBeNull] string destination = BodyDestinationFormat.SameAsSource, [CanBeNull] Encoding encoding = null);
|
IResponseBuilder WithBody(Func<IRequestMessage, Task<string>> bodyFactory, string? destination = BodyDestinationFormat.SameAsSource, Encoding? encoding = null);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// WithBody : Create a ... response based on a bytearray.
|
/// WithBody : Create a ... response based on a bytearray.
|
||||||
@@ -44,7 +43,7 @@ namespace WireMock.ResponseBuilders
|
|||||||
/// <param name="destination">The Body Destination format (SameAsSource, String or Bytes).</param>
|
/// <param name="destination">The Body Destination format (SameAsSource, String or Bytes).</param>
|
||||||
/// <param name="encoding">The body encoding.</param>
|
/// <param name="encoding">The body encoding.</param>
|
||||||
/// <returns>A <see cref="IResponseBuilder"/>.</returns>
|
/// <returns>A <see cref="IResponseBuilder"/>.</returns>
|
||||||
IResponseBuilder WithBody([NotNull] byte[] body, [CanBeNull] string destination = BodyDestinationFormat.SameAsSource, [CanBeNull] Encoding encoding = null);
|
IResponseBuilder WithBody(byte[] body, string? destination = BodyDestinationFormat.SameAsSource, Encoding? encoding = null);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// WithBody : Create a string response based on a object (which will be converted to a JSON string).
|
/// WithBody : Create a string response based on a object (which will be converted to a JSON string).
|
||||||
@@ -53,7 +52,7 @@ namespace WireMock.ResponseBuilders
|
|||||||
/// <param name="encoding">The body encoding.</param>
|
/// <param name="encoding">The body encoding.</param>
|
||||||
/// <param name="indented">Use JSON indented.</param>
|
/// <param name="indented">Use JSON indented.</param>
|
||||||
/// <returns>A <see cref="IResponseBuilder"/>.</returns>
|
/// <returns>A <see cref="IResponseBuilder"/>.</returns>
|
||||||
IResponseBuilder WithBodyAsJson([NotNull] object body, [CanBeNull] Encoding encoding = null, bool? indented = null);
|
IResponseBuilder WithBodyAsJson(object body, Encoding? encoding = null, bool? indented = null);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// WithBody : Create a string response based on a object (which will be converted to a JSON string).
|
/// WithBody : Create a string response based on a object (which will be converted to a JSON string).
|
||||||
@@ -61,7 +60,7 @@ namespace WireMock.ResponseBuilders
|
|||||||
/// <param name="body">The body.</param>
|
/// <param name="body">The body.</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>
|
/// <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([NotNull] object body, bool indented);
|
IResponseBuilder WithBodyAsJson(object body, bool indented);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// WithBodyFromFile : Create a ... response based on a File.
|
/// WithBodyFromFile : Create a ... response based on a File.
|
||||||
@@ -69,6 +68,6 @@ namespace WireMock.ResponseBuilders
|
|||||||
/// <param name="filename">The filename.</param>
|
/// <param name="filename">The filename.</param>
|
||||||
/// <param name="cache">Defines if this file is cached in memory or retrieved from disk every time the response is created.</param>
|
/// <param name="cache">Defines if this file is cached in memory or retrieved from disk every time the response is created.</param>
|
||||||
/// <returns>A <see cref="IResponseBuilder"/>.</returns>
|
/// <returns>A <see cref="IResponseBuilder"/>.</returns>
|
||||||
IResponseBuilder WithBodyFromFile([NotNull] string filename, bool cache = true);
|
IResponseBuilder WithBodyFromFile(string filename, bool cache = true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using WireMock.ResponseProviders;
|
using WireMock.ResponseProviders;
|
||||||
@@ -15,13 +15,13 @@ namespace WireMock.ResponseBuilders
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The <see cref="IResponseBuilder"/>.</returns>
|
/// <returns>The <see cref="IResponseBuilder"/>.</returns>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
IResponseBuilder WithCallback([NotNull] Func<RequestMessage, ResponseMessage> callbackHandler);
|
IResponseBuilder WithCallback([NotNull] Func<IRequestMessage, ResponseMessage> callbackHandler);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The async callback builder
|
/// The async callback builder
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The <see cref="IResponseBuilder"/>.</returns>
|
/// <returns>The <see cref="IResponseBuilder"/>.</returns>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
IResponseBuilder WithCallback([NotNull] Func<RequestMessage, Task<ResponseMessage>> callbackHandler);
|
IResponseBuilder WithCallback([NotNull] Func<IRequestMessage, Task<ResponseMessage>> callbackHandler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Stef.Validation;
|
using Stef.Validation;
|
||||||
|
|
||||||
@@ -9,35 +9,35 @@ namespace WireMock.ResponseBuilders
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// A delegate to execute to generate the response.
|
/// A delegate to execute to generate the response.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Func<RequestMessage, ResponseMessage> Callback { get; private set; }
|
public Func<IRequestMessage, ResponseMessage> Callback { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A delegate to execute to generate the response async.
|
/// A delegate to execute to generate the response async.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Func<RequestMessage, Task<ResponseMessage>> CallbackAsync { get; private set; }
|
public Func<IRequestMessage, Task<ResponseMessage>> CallbackAsync { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines if the method WithCallback(...) is used.
|
/// Defines if the method WithCallback(...) is used.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool WithCallbackUsed { get; private set; }
|
public bool WithCallbackUsed { get; private set; }
|
||||||
|
|
||||||
/// <inheritdoc cref="ICallbackResponseBuilder.WithCallback(Func{RequestMessage, ResponseMessage})"/>
|
/// <inheritdoc />
|
||||||
public IResponseBuilder WithCallback(Func<RequestMessage, ResponseMessage> callbackHandler)
|
public IResponseBuilder WithCallback(Func<IRequestMessage, ResponseMessage> callbackHandler)
|
||||||
{
|
{
|
||||||
Guard.NotNull(callbackHandler, nameof(callbackHandler));
|
Guard.NotNull(callbackHandler, nameof(callbackHandler));
|
||||||
|
|
||||||
return WithCallbackInternal(true, callbackHandler);
|
return WithCallbackInternal(true, callbackHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="ICallbackResponseBuilder.WithCallback(Func{RequestMessage, Task{ResponseMessage}})"/>
|
/// <inheritdoc />
|
||||||
public IResponseBuilder WithCallback(Func<RequestMessage, Task<ResponseMessage>> callbackHandler)
|
public IResponseBuilder WithCallback(Func<IRequestMessage, Task<ResponseMessage>> callbackHandler)
|
||||||
{
|
{
|
||||||
Guard.NotNull(callbackHandler, nameof(callbackHandler));
|
Guard.NotNull(callbackHandler, nameof(callbackHandler));
|
||||||
|
|
||||||
return WithCallbackInternal(true, callbackHandler);
|
return WithCallbackInternal(true, callbackHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IResponseBuilder WithCallbackInternal(bool withCallbackUsed, Func<RequestMessage, ResponseMessage> callbackHandler)
|
private IResponseBuilder WithCallbackInternal(bool withCallbackUsed, Func<IRequestMessage, ResponseMessage> callbackHandler)
|
||||||
{
|
{
|
||||||
Guard.NotNull(callbackHandler, nameof(callbackHandler));
|
Guard.NotNull(callbackHandler, nameof(callbackHandler));
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ namespace WireMock.ResponseBuilders
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IResponseBuilder WithCallbackInternal(bool withCallbackUsed, Func<RequestMessage, Task<ResponseMessage>> callbackHandler)
|
private IResponseBuilder WithCallbackInternal(bool withCallbackUsed, Func<IRequestMessage, Task<ResponseMessage>> callbackHandler)
|
||||||
{
|
{
|
||||||
Guard.NotNull(callbackHandler, nameof(callbackHandler));
|
Guard.NotNull(callbackHandler, nameof(callbackHandler));
|
||||||
|
|
||||||
|
|||||||
@@ -195,8 +195,8 @@ namespace WireMock.ResponseBuilders
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IBodyResponseBuilder.WithBody(Func{RequestMessage, string}, string, Encoding)"/>
|
/// <inheritdoc />
|
||||||
public IResponseBuilder WithBody(Func<RequestMessage, string> bodyFactory, string destination = BodyDestinationFormat.SameAsSource, Encoding encoding = null)
|
public IResponseBuilder WithBody(Func<IRequestMessage, string> bodyFactory, string destination = BodyDestinationFormat.SameAsSource, Encoding encoding = null)
|
||||||
{
|
{
|
||||||
Guard.NotNull(bodyFactory, nameof(bodyFactory));
|
Guard.NotNull(bodyFactory, nameof(bodyFactory));
|
||||||
|
|
||||||
@@ -211,8 +211,8 @@ namespace WireMock.ResponseBuilders
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IBodyResponseBuilder.WithBody(Func{RequestMessage, Task{string}}, string, Encoding)"/>
|
/// <inheritdoc />
|
||||||
public IResponseBuilder WithBody(Func<RequestMessage, Task<string>> bodyFactory, string destination = BodyDestinationFormat.SameAsSource, Encoding encoding = null)
|
public IResponseBuilder WithBody(Func<IRequestMessage, Task<string>> bodyFactory, string destination = BodyDestinationFormat.SameAsSource, Encoding encoding = null)
|
||||||
{
|
{
|
||||||
Guard.NotNull(bodyFactory, nameof(bodyFactory));
|
Guard.NotNull(bodyFactory, nameof(bodyFactory));
|
||||||
|
|
||||||
@@ -383,8 +383,8 @@ namespace WireMock.ResponseBuilders
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IResponseProvider.ProvideResponseAsync(RequestMessage, WireMockServerSettings)"/>
|
/// <inheritdoc />
|
||||||
public async Task<(ResponseMessage Message, IMapping Mapping)> ProvideResponseAsync(RequestMessage requestMessage, WireMockServerSettings settings)
|
public async Task<(IResponseMessage Message, IMapping Mapping)> ProvideResponseAsync(IRequestMessage requestMessage, WireMockServerSettings settings)
|
||||||
{
|
{
|
||||||
Guard.NotNull(requestMessage, nameof(requestMessage));
|
Guard.NotNull(requestMessage, nameof(requestMessage));
|
||||||
Guard.NotNull(settings, nameof(settings));
|
Guard.NotNull(settings, nameof(settings));
|
||||||
|
|||||||
@@ -6,14 +6,14 @@ namespace WireMock.ResponseProviders
|
|||||||
{
|
{
|
||||||
internal class DynamicAsyncResponseProvider : IResponseProvider
|
internal class DynamicAsyncResponseProvider : IResponseProvider
|
||||||
{
|
{
|
||||||
private readonly Func<RequestMessage, Task<ResponseMessage>> _responseMessageFunc;
|
private readonly Func<IRequestMessage, Task<IResponseMessage>> _responseMessageFunc;
|
||||||
|
|
||||||
public DynamicAsyncResponseProvider(Func<RequestMessage, Task<ResponseMessage>> responseMessageFunc)
|
public DynamicAsyncResponseProvider(Func<IRequestMessage, Task<IResponseMessage>> responseMessageFunc)
|
||||||
{
|
{
|
||||||
_responseMessageFunc = responseMessageFunc;
|
_responseMessageFunc = responseMessageFunc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<(ResponseMessage Message, IMapping Mapping)> ProvideResponseAsync(RequestMessage requestMessage, WireMockServerSettings settings)
|
public async Task<(IResponseMessage Message, IMapping Mapping)> ProvideResponseAsync(IRequestMessage requestMessage, WireMockServerSettings settings)
|
||||||
{
|
{
|
||||||
return (await _responseMessageFunc(requestMessage).ConfigureAwait(false), null);
|
return (await _responseMessageFunc(requestMessage).ConfigureAwait(false), null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,16 +6,16 @@ namespace WireMock.ResponseProviders
|
|||||||
{
|
{
|
||||||
internal class DynamicResponseProvider : IResponseProvider
|
internal class DynamicResponseProvider : IResponseProvider
|
||||||
{
|
{
|
||||||
private readonly Func<RequestMessage, ResponseMessage> _responseMessageFunc;
|
private readonly Func<IRequestMessage, IResponseMessage> _responseMessageFunc;
|
||||||
|
|
||||||
public DynamicResponseProvider(Func<RequestMessage, ResponseMessage> responseMessageFunc)
|
public DynamicResponseProvider(Func<IRequestMessage, IResponseMessage> responseMessageFunc)
|
||||||
{
|
{
|
||||||
_responseMessageFunc = responseMessageFunc;
|
_responseMessageFunc = responseMessageFunc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<(ResponseMessage Message, IMapping Mapping)> ProvideResponseAsync(RequestMessage requestMessage, WireMockServerSettings settings)
|
public Task<(IResponseMessage Message, IMapping Mapping)> ProvideResponseAsync(IRequestMessage requestMessage, WireMockServerSettings settings)
|
||||||
{
|
{
|
||||||
(ResponseMessage responseMessage, IMapping mapping) result = (_responseMessageFunc(requestMessage), null);
|
(IResponseMessage responseMessage, IMapping mapping) result = (_responseMessageFunc(requestMessage), null);
|
||||||
return Task.FromResult(result);
|
return Task.FromResult(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// This source file is based on mock4net by Alexandre Victoor which is licensed under the Apache 2.0 License.
|
// This source file is based on mock4net by Alexandre Victoor which is licensed under the Apache 2.0 License.
|
||||||
// For more details see 'mock4net/LICENSE.txt' and 'mock4net/readme.md' in this project root.
|
// For more details see 'mock4net/LICENSE.txt' and 'mock4net/readme.md' in this project root.
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
@@ -17,6 +17,6 @@ namespace WireMock.ResponseProviders
|
|||||||
/// <param name="requestMessage">The request.</param>
|
/// <param name="requestMessage">The request.</param>
|
||||||
/// <param name="settings">The WireMockServerSettings.</param>
|
/// <param name="settings">The WireMockServerSettings.</param>
|
||||||
/// <returns>The <see cref="ResponseMessage"/> including a new (optional) <see cref="IMapping"/>.</returns>
|
/// <returns>The <see cref="ResponseMessage"/> including a new (optional) <see cref="IMapping"/>.</returns>
|
||||||
Task<(ResponseMessage Message, IMapping Mapping)> ProvideResponseAsync([NotNull] RequestMessage requestMessage, [NotNull] WireMockServerSettings settings);
|
Task<(IResponseMessage Message, IMapping Mapping)> ProvideResponseAsync([NotNull] IRequestMessage requestMessage, [NotNull] WireMockServerSettings settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,16 +6,16 @@ namespace WireMock.ResponseProviders
|
|||||||
{
|
{
|
||||||
internal class ProxyAsyncResponseProvider : IResponseProvider
|
internal class ProxyAsyncResponseProvider : IResponseProvider
|
||||||
{
|
{
|
||||||
private readonly Func<RequestMessage, WireMockServerSettings, Task<ResponseMessage>> _responseMessageFunc;
|
private readonly Func<IRequestMessage, WireMockServerSettings, Task<IResponseMessage>> _responseMessageFunc;
|
||||||
private readonly WireMockServerSettings _settings;
|
private readonly WireMockServerSettings _settings;
|
||||||
|
|
||||||
public ProxyAsyncResponseProvider(Func<RequestMessage, WireMockServerSettings, Task<ResponseMessage>> responseMessageFunc, WireMockServerSettings settings)
|
public ProxyAsyncResponseProvider(Func<IRequestMessage, WireMockServerSettings, Task<IResponseMessage>> responseMessageFunc, WireMockServerSettings settings)
|
||||||
{
|
{
|
||||||
_responseMessageFunc = responseMessageFunc;
|
_responseMessageFunc = responseMessageFunc;
|
||||||
_settings = settings;
|
_settings = settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<(ResponseMessage Message, IMapping Mapping)> ProvideResponseAsync(RequestMessage requestMessage, WireMockServerSettings settings)
|
public async Task<(IResponseMessage Message, IMapping Mapping)> ProvideResponseAsync(IRequestMessage requestMessage, WireMockServerSettings settings)
|
||||||
{
|
{
|
||||||
return (await _responseMessageFunc(requestMessage, _settings).ConfigureAwait(false), null);
|
return (await _responseMessageFunc(requestMessage, _settings).ConfigureAwait(false), null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,5 +20,11 @@ namespace WireMock.Serialization
|
|||||||
{
|
{
|
||||||
DateParseHandling = DateParseHandling.None
|
DateParseHandling = DateParseHandling.None
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public static readonly JsonSerializerSettings JsonSerializerSettingsPact = new JsonSerializerSettings
|
||||||
|
{
|
||||||
|
Formatting = Formatting.Indented,
|
||||||
|
NullValueHandling = NullValueHandling.Ignore
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using WireMock.Admin.Mappings;
|
using WireMock.Admin.Mappings;
|
||||||
using WireMock.Admin.Requests;
|
using WireMock.Admin.Requests;
|
||||||
using WireMock.Logging;
|
using WireMock.Logging;
|
||||||
@@ -29,8 +29,8 @@ namespace WireMock.Serialization
|
|||||||
|
|
||||||
if (logEntry.RequestMessage.BodyData != null)
|
if (logEntry.RequestMessage.BodyData != null)
|
||||||
{
|
{
|
||||||
logRequestModel.DetectedBodyType = logEntry.RequestMessage.BodyData.DetectedBodyType.ToString();
|
logRequestModel.DetectedBodyType = logEntry.RequestMessage.BodyData.DetectedBodyType?.ToString();
|
||||||
logRequestModel.DetectedBodyTypeFromContentType = logEntry.RequestMessage.BodyData.DetectedBodyTypeFromContentType.ToString();
|
logRequestModel.DetectedBodyTypeFromContentType = logEntry.RequestMessage.BodyData.DetectedBodyTypeFromContentType?.ToString();
|
||||||
|
|
||||||
switch (logEntry.RequestMessage.BodyData.DetectedBodyType)
|
switch (logEntry.RequestMessage.BodyData.DetectedBodyType)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ namespace WireMock.Serialization
|
|||||||
Guid = mapping.Guid,
|
Guid = mapping.Guid,
|
||||||
TimeSettings = TimeSettingsMapper.Map(mapping.TimeSettings),
|
TimeSettings = TimeSettingsMapper.Map(mapping.TimeSettings),
|
||||||
Title = mapping.Title,
|
Title = mapping.Title,
|
||||||
|
Description = mapping.Description,
|
||||||
Priority = mapping.Priority != 0 ? mapping.Priority : (int?)null,
|
Priority = mapping.Priority != 0 ? mapping.Priority : (int?)null,
|
||||||
Scenario = mapping.Scenario,
|
Scenario = mapping.Scenario,
|
||||||
WhenStateIs = mapping.ExecutionConditionState,
|
WhenStateIs = mapping.ExecutionConditionState,
|
||||||
|
|||||||
@@ -1,51 +1,49 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using JetBrains.Annotations;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using WireMock.Settings;
|
|
||||||
using Stef.Validation;
|
using Stef.Validation;
|
||||||
|
using WireMock.Settings;
|
||||||
|
|
||||||
namespace WireMock.Serialization
|
namespace WireMock.Serialization;
|
||||||
|
|
||||||
|
internal class MappingToFileSaver
|
||||||
{
|
{
|
||||||
internal class MappingToFileSaver
|
private readonly WireMockServerSettings _settings;
|
||||||
|
private readonly MappingConverter _mappingConverter;
|
||||||
|
|
||||||
|
public MappingToFileSaver(WireMockServerSettings settings, MappingConverter mappingConverter)
|
||||||
{
|
{
|
||||||
private readonly WireMockServerSettings _settings;
|
Guard.NotNull(settings);
|
||||||
private readonly MappingConverter _mappingConverter;
|
Guard.NotNull(mappingConverter);
|
||||||
|
|
||||||
public MappingToFileSaver(WireMockServerSettings settings, MappingConverter mappingConverter)
|
_settings = settings;
|
||||||
|
_mappingConverter = mappingConverter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SaveMappingToFile(IMapping mapping, string? folder = null)
|
||||||
|
{
|
||||||
|
if (folder == null)
|
||||||
{
|
{
|
||||||
Guard.NotNull(settings);
|
folder = _settings.FileSystemHandler.GetMappingFolder();
|
||||||
Guard.NotNull(mappingConverter);
|
|
||||||
|
|
||||||
_settings = settings;
|
|
||||||
_mappingConverter = mappingConverter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveMappingToFile(IMapping mapping, [CanBeNull] string folder = null)
|
if (!_settings.FileSystemHandler.FolderExists(folder))
|
||||||
{
|
{
|
||||||
if (folder == null)
|
_settings.FileSystemHandler.CreateFolder(folder);
|
||||||
{
|
|
||||||
folder = _settings.FileSystemHandler.GetMappingFolder();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_settings.FileSystemHandler.FolderExists(folder))
|
|
||||||
{
|
|
||||||
_settings.FileSystemHandler.CreateFolder(folder);
|
|
||||||
}
|
|
||||||
|
|
||||||
var model = _mappingConverter.ToMappingModel(mapping);
|
|
||||||
string filename = (!string.IsNullOrEmpty(mapping.Title) ? SanitizeFileName(mapping.Title) : mapping.Guid.ToString()) + ".json";
|
|
||||||
|
|
||||||
string path = Path.Combine(folder, filename);
|
|
||||||
|
|
||||||
_settings.Logger.Info("Saving Mapping file {0}", filename);
|
|
||||||
|
|
||||||
_settings.FileSystemHandler.WriteMappingFile(path, JsonConvert.SerializeObject(model, JsonSerializationConstants.JsonSerializerSettingsDefault));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string SanitizeFileName(string name, char replaceChar = '_')
|
var model = _mappingConverter.ToMappingModel(mapping);
|
||||||
{
|
string filename = (!string.IsNullOrEmpty(mapping.Title) ? SanitizeFileName(mapping.Title) : mapping.Guid.ToString()) + ".json";
|
||||||
return Path.GetInvalidFileNameChars().Aggregate(name, (current, c) => current.Replace(c, replaceChar));
|
|
||||||
}
|
string path = Path.Combine(folder, filename);
|
||||||
|
|
||||||
|
_settings.Logger.Info("Saving Mapping file {0}", filename);
|
||||||
|
|
||||||
|
_settings.FileSystemHandler.WriteMappingFile(path, JsonConvert.SerializeObject(model, JsonSerializationConstants.JsonSerializerSettingsDefault));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string SanitizeFileName(string name, char replaceChar = '_')
|
||||||
|
{
|
||||||
|
return Path.GetInvalidFileNameChars().Aggregate(name, (current, c) => current.Replace(c, replaceChar));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -38,6 +38,13 @@ namespace WireMock.Server
|
|||||||
/// <returns>The <see cref="IRespondWithAProvider"/>.</returns>
|
/// <returns>The <see cref="IRespondWithAProvider"/>.</returns>
|
||||||
IRespondWithAProvider WithTitle(string title);
|
IRespondWithAProvider WithTitle(string title);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Define a description for this mapping.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="description">The description.</param>
|
||||||
|
/// <returns>The <see cref="IRespondWithAProvider"/>.</returns>
|
||||||
|
IRespondWithAProvider WithDescription(string description);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Define the full filepath for this mapping.
|
/// Define the full filepath for this mapping.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ namespace WireMock.Server
|
|||||||
{
|
{
|
||||||
private int _priority;
|
private int _priority;
|
||||||
private string _title;
|
private string _title;
|
||||||
|
private string _description;
|
||||||
private string _path;
|
private string _path;
|
||||||
private string _executionConditionState;
|
private string _executionConditionState;
|
||||||
private string _nextState;
|
private string _nextState;
|
||||||
@@ -58,16 +59,16 @@ namespace WireMock.Server
|
|||||||
/// <param name="provider">The provider.</param>
|
/// <param name="provider">The provider.</param>
|
||||||
public void RespondWith(IResponseProvider provider)
|
public void RespondWith(IResponseProvider provider)
|
||||||
{
|
{
|
||||||
_registrationCallback(new Mapping(Guid, _title, _path, _settings, _requestMatcher, provider, _priority, _scenario, _executionConditionState, _nextState, _timesInSameState, Webhooks, TimeSettings), _saveToFile);
|
_registrationCallback(new Mapping(Guid, _title, _description, _path, _settings, _requestMatcher, provider, _priority, _scenario, _executionConditionState, _nextState, _timesInSameState, Webhooks, TimeSettings), _saveToFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <see cref="IRespondWithAProvider.WithGuid(string)"/>
|
/// <inheritdoc />
|
||||||
public IRespondWithAProvider WithGuid(string guid)
|
public IRespondWithAProvider WithGuid(string guid)
|
||||||
{
|
{
|
||||||
return WithGuid(Guid.Parse(guid));
|
return WithGuid(Guid.Parse(guid));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <see cref="IRespondWithAProvider.WithGuid(Guid)"/>
|
/// <inheritdoc />
|
||||||
public IRespondWithAProvider WithGuid(Guid guid)
|
public IRespondWithAProvider WithGuid(Guid guid)
|
||||||
{
|
{
|
||||||
Guid = guid;
|
Guid = guid;
|
||||||
@@ -75,7 +76,7 @@ namespace WireMock.Server
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <see cref="IRespondWithAProvider.WithTitle"/>
|
/// <inheritdoc />
|
||||||
public IRespondWithAProvider WithTitle(string title)
|
public IRespondWithAProvider WithTitle(string title)
|
||||||
{
|
{
|
||||||
_title = title;
|
_title = title;
|
||||||
@@ -83,6 +84,14 @@ namespace WireMock.Server
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public IRespondWithAProvider WithDescription(string description)
|
||||||
|
{
|
||||||
|
_description = description;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/// <see cref="IRespondWithAProvider.WithPath"/>
|
/// <see cref="IRespondWithAProvider.WithPath"/>
|
||||||
public IRespondWithAProvider WithPath(string path)
|
public IRespondWithAProvider WithPath(string path)
|
||||||
{
|
{
|
||||||
@@ -91,7 +100,7 @@ namespace WireMock.Server
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <see cref="IRespondWithAProvider.AtPriority"/>
|
/// <inheritdoc />
|
||||||
public IRespondWithAProvider AtPriority(int priority)
|
public IRespondWithAProvider AtPriority(int priority)
|
||||||
{
|
{
|
||||||
_priority = priority;
|
_priority = priority;
|
||||||
@@ -99,7 +108,7 @@ namespace WireMock.Server
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <see cref="IRespondWithAProvider.InScenario(string)"/>
|
/// <inheritdoc />
|
||||||
public IRespondWithAProvider InScenario(string scenario)
|
public IRespondWithAProvider InScenario(string scenario)
|
||||||
{
|
{
|
||||||
_scenario = scenario;
|
_scenario = scenario;
|
||||||
@@ -107,13 +116,13 @@ namespace WireMock.Server
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <see cref="IRespondWithAProvider.InScenario(int)"/>
|
/// <inheritdoc />
|
||||||
public IRespondWithAProvider InScenario(int scenario)
|
public IRespondWithAProvider InScenario(int scenario)
|
||||||
{
|
{
|
||||||
return InScenario(scenario.ToString());
|
return InScenario(scenario.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <see cref="IRespondWithAProvider.WhenStateIs(string)"/>
|
/// <inheritdoc />
|
||||||
public IRespondWithAProvider WhenStateIs(string state)
|
public IRespondWithAProvider WhenStateIs(string state)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(_scenario))
|
if (string.IsNullOrEmpty(_scenario))
|
||||||
@@ -126,13 +135,13 @@ namespace WireMock.Server
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <see cref="IRespondWithAProvider.WhenStateIs(int)"/>
|
/// <inheritdoc />
|
||||||
public IRespondWithAProvider WhenStateIs(int state)
|
public IRespondWithAProvider WhenStateIs(int state)
|
||||||
{
|
{
|
||||||
return WhenStateIs(state.ToString());
|
return WhenStateIs(state.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <see cref="IRespondWithAProvider.WillSetStateTo(string, int?)"/>
|
/// <inheritdoc />
|
||||||
public IRespondWithAProvider WillSetStateTo(string state, int? times = 1)
|
public IRespondWithAProvider WillSetStateTo(string state, int? times = 1)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(_scenario))
|
if (string.IsNullOrEmpty(_scenario))
|
||||||
@@ -146,7 +155,7 @@ namespace WireMock.Server
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <see cref="IRespondWithAProvider.WillSetStateTo(int, int?)"/>
|
/// <inheritdoc />
|
||||||
public IRespondWithAProvider WillSetStateTo(int state, int? times = 1)
|
public IRespondWithAProvider WillSetStateTo(int state, int? times = 1)
|
||||||
{
|
{
|
||||||
return WillSetStateTo(state.ToString(), times);
|
return WillSetStateTo(state.ToString(), times);
|
||||||
@@ -162,7 +171,7 @@ namespace WireMock.Server
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <see cref="IRespondWithAProvider.WithWebhook(IWebhook[])"/>
|
/// <inheritdoc />
|
||||||
public IRespondWithAProvider WithWebhook(params IWebhook[] webhooks)
|
public IRespondWithAProvider WithWebhook(params IWebhook[] webhooks)
|
||||||
{
|
{
|
||||||
Guard.HasNoNulls(webhooks, nameof(webhooks));
|
Guard.HasNoNulls(webhooks, nameof(webhooks));
|
||||||
@@ -172,7 +181,7 @@ namespace WireMock.Server
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <see cref="IRespondWithAProvider.WithWebhook(string, string, IDictionary{string, WireMockList{string}}, string, bool, TransformerType)"/>
|
/// <inheritdoc />
|
||||||
public IRespondWithAProvider WithWebhook(
|
public IRespondWithAProvider WithWebhook(
|
||||||
[NotNull] string url,
|
[NotNull] string url,
|
||||||
[CanBeNull] string method = "post",
|
[CanBeNull] string method = "post",
|
||||||
@@ -196,7 +205,7 @@ namespace WireMock.Server
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <see cref="IRespondWithAProvider.WithWebhook(string, string, IDictionary{string, WireMockList{string}}, object, bool, TransformerType)"/>
|
/// <inheritdoc />
|
||||||
public IRespondWithAProvider WithWebhook(
|
public IRespondWithAProvider WithWebhook(
|
||||||
[NotNull] string url,
|
[NotNull] string url,
|
||||||
[CanBeNull] string method = "post",
|
[CanBeNull] string method = "post",
|
||||||
|
|||||||
@@ -44,12 +44,12 @@ public partial class WireMockServer
|
|||||||
private const string AdminScenarios = "/__admin/scenarios";
|
private const string AdminScenarios = "/__admin/scenarios";
|
||||||
private const string QueryParamReloadStaticMappings = "reloadStaticMappings";
|
private const string QueryParamReloadStaticMappings = "reloadStaticMappings";
|
||||||
|
|
||||||
private readonly Guid _proxyMappingGuid = new Guid("e59914fd-782e-428e-91c1-4810ffb86567");
|
private readonly Guid _proxyMappingGuid = new("e59914fd-782e-428e-91c1-4810ffb86567");
|
||||||
private readonly RegexMatcher _adminRequestContentTypeJson = new ContentTypeMatcher(ContentTypeJson, true);
|
private readonly RegexMatcher _adminRequestContentTypeJson = new ContentTypeMatcher(ContentTypeJson, true);
|
||||||
private readonly RegexMatcher _adminMappingsGuidPathMatcher = new RegexMatcher(@"^\/__admin\/mappings\/([0-9A-Fa-f]{8}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{12})$");
|
private readonly RegexMatcher _adminMappingsGuidPathMatcher = new(@"^\/__admin\/mappings\/([0-9A-Fa-f]{8}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{12})$");
|
||||||
private readonly RegexMatcher _adminRequestsGuidPathMatcher = new RegexMatcher(@"^\/__admin\/requests\/([0-9A-Fa-f]{8}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{12})$");
|
private readonly RegexMatcher _adminRequestsGuidPathMatcher = new(@"^\/__admin\/requests\/([0-9A-Fa-f]{8}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{12})$");
|
||||||
|
|
||||||
private EnhancedFileSystemWatcher _enhancedFileSystemWatcher;
|
private EnhancedFileSystemWatcher? _enhancedFileSystemWatcher;
|
||||||
|
|
||||||
#region InitAdmin
|
#region InitAdmin
|
||||||
private void InitAdmin()
|
private void InitAdmin()
|
||||||
@@ -108,7 +108,7 @@ public partial class WireMockServer
|
|||||||
#region StaticMappings
|
#region StaticMappings
|
||||||
/// <inheritdoc cref="IWireMockServer.SaveStaticMappings" />
|
/// <inheritdoc cref="IWireMockServer.SaveStaticMappings" />
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public void SaveStaticMappings([CanBeNull] string folder = null)
|
public void SaveStaticMappings(string? folder = null)
|
||||||
{
|
{
|
||||||
foreach (var mapping in Mappings.Where(m => !m.IsAdminInterface))
|
foreach (var mapping in Mappings.Where(m => !m.IsAdminInterface))
|
||||||
{
|
{
|
||||||
@@ -118,7 +118,7 @@ public partial class WireMockServer
|
|||||||
|
|
||||||
/// <inheritdoc cref="IWireMockServer.ReadStaticMappings" />
|
/// <inheritdoc cref="IWireMockServer.ReadStaticMappings" />
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public void ReadStaticMappings([CanBeNull] string folder = null)
|
public void ReadStaticMappings(string? folder = null)
|
||||||
{
|
{
|
||||||
if (folder == null)
|
if (folder == null)
|
||||||
{
|
{
|
||||||
@@ -207,8 +207,7 @@ public partial class WireMockServer
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Proxy and Record
|
#region Proxy and Record
|
||||||
[CanBeNull]
|
private HttpClient? _httpClientForProxy;
|
||||||
private HttpClient _httpClientForProxy;
|
|
||||||
|
|
||||||
private void InitProxyAndRecord(WireMockServerSettings settings)
|
private void InitProxyAndRecord(WireMockServerSettings settings)
|
||||||
{
|
{
|
||||||
@@ -230,7 +229,7 @@ public partial class WireMockServer
|
|||||||
proxyRespondProvider.RespondWith(new ProxyAsyncResponseProvider(ProxyAndRecordAsync, settings));
|
proxyRespondProvider.RespondWith(new ProxyAsyncResponseProvider(ProxyAndRecordAsync, settings));
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<ResponseMessage> ProxyAndRecordAsync(RequestMessage requestMessage, WireMockServerSettings settings)
|
private async Task<IResponseMessage> ProxyAndRecordAsync(IRequestMessage requestMessage, WireMockServerSettings settings)
|
||||||
{
|
{
|
||||||
var requestUri = new Uri(requestMessage.Url);
|
var requestUri = new Uri(requestMessage.Url);
|
||||||
var proxyUri = new Uri(settings.ProxyAndRecordSettings.Url);
|
var proxyUri = new Uri(settings.ProxyAndRecordSettings.Url);
|
||||||
@@ -263,7 +262,7 @@ public partial class WireMockServer
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Settings
|
#region Settings
|
||||||
private ResponseMessage SettingsGet(RequestMessage requestMessage)
|
private IResponseMessage SettingsGet(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
var model = new SettingsModel
|
var model = new SettingsModel
|
||||||
{
|
{
|
||||||
@@ -290,7 +289,7 @@ public partial class WireMockServer
|
|||||||
return ToJson(model);
|
return ToJson(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ResponseMessage SettingsUpdate(RequestMessage requestMessage)
|
private IResponseMessage SettingsUpdate(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
var settings = DeserializeObject<SettingsModel>(requestMessage);
|
var settings = DeserializeObject<SettingsModel>(requestMessage);
|
||||||
|
|
||||||
@@ -335,7 +334,7 @@ public partial class WireMockServer
|
|||||||
#endregion Settings
|
#endregion Settings
|
||||||
|
|
||||||
#region Mapping/{guid}
|
#region Mapping/{guid}
|
||||||
private ResponseMessage MappingGet(RequestMessage requestMessage)
|
private IResponseMessage MappingGet(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
Guid guid = ParseGuidFromRequestMessage(requestMessage);
|
Guid guid = ParseGuidFromRequestMessage(requestMessage);
|
||||||
var mapping = Mappings.FirstOrDefault(m => !m.IsAdminInterface && m.Guid == guid);
|
var mapping = Mappings.FirstOrDefault(m => !m.IsAdminInterface && m.Guid == guid);
|
||||||
@@ -351,7 +350,7 @@ public partial class WireMockServer
|
|||||||
return ToJson(model);
|
return ToJson(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ResponseMessage MappingPut(RequestMessage requestMessage)
|
private IResponseMessage MappingPut(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
Guid guid = ParseGuidFromRequestMessage(requestMessage);
|
Guid guid = ParseGuidFromRequestMessage(requestMessage);
|
||||||
|
|
||||||
@@ -361,7 +360,7 @@ public partial class WireMockServer
|
|||||||
return ResponseMessageBuilder.Create("Mapping added or updated", 200, guidFromPut);
|
return ResponseMessageBuilder.Create("Mapping added or updated", 200, guidFromPut);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ResponseMessage MappingDelete(RequestMessage requestMessage)
|
private IResponseMessage MappingDelete(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
Guid guid = ParseGuidFromRequestMessage(requestMessage);
|
Guid guid = ParseGuidFromRequestMessage(requestMessage);
|
||||||
|
|
||||||
@@ -373,14 +372,14 @@ public partial class WireMockServer
|
|||||||
return ResponseMessageBuilder.Create("Mapping not found", 404);
|
return ResponseMessageBuilder.Create("Mapping not found", 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Guid ParseGuidFromRequestMessage(RequestMessage requestMessage)
|
private Guid ParseGuidFromRequestMessage(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
return Guid.Parse(requestMessage.Path.Substring(AdminMappings.Length + 1));
|
return Guid.Parse(requestMessage.Path.Substring(AdminMappings.Length + 1));
|
||||||
}
|
}
|
||||||
#endregion Mapping/{guid}
|
#endregion Mapping/{guid}
|
||||||
|
|
||||||
#region Mappings
|
#region Mappings
|
||||||
private ResponseMessage MappingsSave(RequestMessage requestMessage)
|
private IResponseMessage MappingsSave(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
SaveStaticMappings();
|
SaveStaticMappings();
|
||||||
|
|
||||||
@@ -392,12 +391,12 @@ public partial class WireMockServer
|
|||||||
return Mappings.Where(m => !m.IsAdminInterface).Select(_mappingConverter.ToMappingModel);
|
return Mappings.Where(m => !m.IsAdminInterface).Select(_mappingConverter.ToMappingModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ResponseMessage MappingsGet(RequestMessage requestMessage)
|
private IResponseMessage MappingsGet(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
return ToJson(ToMappingModels());
|
return ToJson(ToMappingModels());
|
||||||
}
|
}
|
||||||
|
|
||||||
private ResponseMessage MappingsPost(RequestMessage requestMessage)
|
private IResponseMessage MappingsPost(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -427,7 +426,7 @@ public partial class WireMockServer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Guid? ConvertMappingAndRegisterAsRespondProvider(MappingModel mappingModel, Guid? guid = null, string path = null)
|
private Guid? ConvertMappingAndRegisterAsRespondProvider(MappingModel mappingModel, Guid? guid = null, string? path = null)
|
||||||
{
|
{
|
||||||
Guard.NotNull(mappingModel, nameof(mappingModel));
|
Guard.NotNull(mappingModel, nameof(mappingModel));
|
||||||
Guard.NotNull(mappingModel.Request, nameof(mappingModel.Request));
|
Guard.NotNull(mappingModel.Request, nameof(mappingModel.Request));
|
||||||
@@ -494,7 +493,7 @@ public partial class WireMockServer
|
|||||||
return respondProvider.Guid;
|
return respondProvider.Guid;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ResponseMessage MappingsDelete(RequestMessage requestMessage)
|
private IResponseMessage MappingsDelete(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(requestMessage.Body))
|
if (!string.IsNullOrEmpty(requestMessage.Body))
|
||||||
{
|
{
|
||||||
@@ -519,7 +518,7 @@ public partial class WireMockServer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<Guid> MappingsDeleteMappingFromBody(RequestMessage requestMessage)
|
private IEnumerable<Guid> MappingsDeleteMappingFromBody(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
var deletedGuids = new List<Guid>();
|
var deletedGuids = new List<Guid>();
|
||||||
|
|
||||||
@@ -555,7 +554,7 @@ public partial class WireMockServer
|
|||||||
return deletedGuids;
|
return deletedGuids;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ResponseMessage MappingsReset(RequestMessage requestMessage)
|
private IResponseMessage MappingsReset(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
ResetMappings();
|
ResetMappings();
|
||||||
|
|
||||||
@@ -575,7 +574,7 @@ public partial class WireMockServer
|
|||||||
#endregion Mappings
|
#endregion Mappings
|
||||||
|
|
||||||
#region Request/{guid}
|
#region Request/{guid}
|
||||||
private ResponseMessage RequestGet(RequestMessage requestMessage)
|
private IResponseMessage RequestGet(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
Guid guid = ParseGuidFromRequestMessage(requestMessage);
|
Guid guid = ParseGuidFromRequestMessage(requestMessage);
|
||||||
var entry = LogEntries.FirstOrDefault(r => !r.RequestMessage.Path.StartsWith("/__admin/") && r.Guid == guid);
|
var entry = LogEntries.FirstOrDefault(r => !r.RequestMessage.Path.StartsWith("/__admin/") && r.Guid == guid);
|
||||||
@@ -591,7 +590,7 @@ public partial class WireMockServer
|
|||||||
return ToJson(model);
|
return ToJson(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ResponseMessage RequestDelete(RequestMessage requestMessage)
|
private IResponseMessage RequestDelete(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
Guid guid = ParseGuidFromRequestMessage(requestMessage);
|
Guid guid = ParseGuidFromRequestMessage(requestMessage);
|
||||||
|
|
||||||
@@ -605,7 +604,7 @@ public partial class WireMockServer
|
|||||||
#endregion Request/{guid}
|
#endregion Request/{guid}
|
||||||
|
|
||||||
#region Requests
|
#region Requests
|
||||||
private ResponseMessage RequestsGet(RequestMessage requestMessage)
|
private IResponseMessage RequestsGet(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
var result = LogEntries
|
var result = LogEntries
|
||||||
.Where(r => !r.RequestMessage.Path.StartsWith("/__admin/"))
|
.Where(r => !r.RequestMessage.Path.StartsWith("/__admin/"))
|
||||||
@@ -614,7 +613,7 @@ public partial class WireMockServer
|
|||||||
return ToJson(result);
|
return ToJson(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ResponseMessage RequestsDelete(RequestMessage requestMessage)
|
private IResponseMessage RequestsDelete(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
ResetLogEntries();
|
ResetLogEntries();
|
||||||
|
|
||||||
@@ -623,7 +622,7 @@ public partial class WireMockServer
|
|||||||
#endregion Requests
|
#endregion Requests
|
||||||
|
|
||||||
#region Requests/find
|
#region Requests/find
|
||||||
private ResponseMessage RequestsFind(RequestMessage requestMessage)
|
private IResponseMessage RequestsFind(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
var requestModel = DeserializeObject<RequestModel>(requestMessage);
|
var requestModel = DeserializeObject<RequestModel>(requestMessage);
|
||||||
|
|
||||||
@@ -646,7 +645,7 @@ public partial class WireMockServer
|
|||||||
#endregion Requests/find
|
#endregion Requests/find
|
||||||
|
|
||||||
#region Scenarios
|
#region Scenarios
|
||||||
private ResponseMessage ScenariosGet(RequestMessage requestMessage)
|
private IResponseMessage ScenariosGet(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
var scenariosStates = Scenarios.Values.Select(s => new ScenarioStateModel
|
var scenariosStates = Scenarios.Values.Select(s => new ScenarioStateModel
|
||||||
{
|
{
|
||||||
@@ -660,7 +659,7 @@ public partial class WireMockServer
|
|||||||
return ToJson(scenariosStates, true);
|
return ToJson(scenariosStates, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ResponseMessage ScenariosReset(RequestMessage requestMessage)
|
private IResponseMessage ScenariosReset(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
ResetScenarios();
|
ResetScenarios();
|
||||||
|
|
||||||
@@ -668,7 +667,29 @@ public partial class WireMockServer
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private IRequestBuilder InitRequestBuilder(RequestModel requestModel, bool pathOrUrlRequired)
|
/// <summary>
|
||||||
|
/// This stores details about the consumer of the interaction.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="consumer">the consumer</param>
|
||||||
|
[PublicAPI]
|
||||||
|
public WireMockServer WithConsumer(string consumer)
|
||||||
|
{
|
||||||
|
Consumer = consumer;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This stores details about the provider of the interaction.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="provider">the provider</param>
|
||||||
|
[PublicAPI]
|
||||||
|
public WireMockServer WithProvider(string provider)
|
||||||
|
{
|
||||||
|
Provider = provider;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private IRequestBuilder? InitRequestBuilder(RequestModel requestModel, bool pathOrUrlRequired)
|
||||||
{
|
{
|
||||||
IRequestBuilder requestBuilder = Request.Create();
|
IRequestBuilder requestBuilder = Request.Create();
|
||||||
|
|
||||||
@@ -743,7 +764,7 @@ public partial class WireMockServer
|
|||||||
headerModel.Name,
|
headerModel.Name,
|
||||||
headerModel.IgnoreCase == true,
|
headerModel.IgnoreCase == true,
|
||||||
headerModel.RejectOnMatch == true ? MatchBehaviour.RejectOnMatch : MatchBehaviour.AcceptOnMatch,
|
headerModel.RejectOnMatch == true ? MatchBehaviour.RejectOnMatch : MatchBehaviour.AcceptOnMatch,
|
||||||
headerModel.Matchers.Select(_matcherMapper.Map).OfType<IStringMatcher>().ToArray()
|
headerModel.Matchers!.Select(_matcherMapper.Map).OfType<IStringMatcher>().ToArray()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -756,16 +777,16 @@ public partial class WireMockServer
|
|||||||
cookieModel.Name,
|
cookieModel.Name,
|
||||||
cookieModel.IgnoreCase == true,
|
cookieModel.IgnoreCase == true,
|
||||||
cookieModel.RejectOnMatch == true ? MatchBehaviour.RejectOnMatch : MatchBehaviour.AcceptOnMatch,
|
cookieModel.RejectOnMatch == true ? MatchBehaviour.RejectOnMatch : MatchBehaviour.AcceptOnMatch,
|
||||||
cookieModel.Matchers.Select(_matcherMapper.Map).OfType<IStringMatcher>().ToArray());
|
cookieModel.Matchers!.Select(_matcherMapper.Map).OfType<IStringMatcher>().ToArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (requestModel.Params != null)
|
if (requestModel.Params != null)
|
||||||
{
|
{
|
||||||
foreach (var paramModel in requestModel.Params.Where(p => p != null && p.Matchers != null))
|
foreach (var paramModel in requestModel.Params.Where(p => p is { Matchers: { } }))
|
||||||
{
|
{
|
||||||
bool ignoreCase = paramModel.IgnoreCase == true;
|
bool ignoreCase = paramModel.IgnoreCase == true;
|
||||||
requestBuilder = requestBuilder.WithParam(paramModel.Name, ignoreCase, paramModel.Matchers.Select(_matcherMapper.Map).OfType<IStringMatcher>().ToArray());
|
requestBuilder = requestBuilder.WithParam(paramModel.Name, ignoreCase, paramModel.Matchers!.Select(_matcherMapper.Map).OfType<IStringMatcher>().ToArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -897,12 +918,12 @@ public partial class WireMockServer
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private Encoding ToEncoding(EncodingModel encodingModel)
|
private Encoding? ToEncoding(EncodingModel? encodingModel)
|
||||||
{
|
{
|
||||||
return encodingModel != null ? Encoding.GetEncoding(encodingModel.CodePage) : null;
|
return encodingModel != null ? Encoding.GetEncoding(encodingModel.CodePage) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private T DeserializeObject<T>(RequestMessage requestMessage)
|
private T? DeserializeObject<T>(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
if (requestMessage?.BodyData?.DetectedBodyType == BodyType.String)
|
if (requestMessage?.BodyData?.DetectedBodyType == BodyType.String)
|
||||||
{
|
{
|
||||||
@@ -917,9 +938,9 @@ public partial class WireMockServer
|
|||||||
return default(T);
|
return default(T);
|
||||||
}
|
}
|
||||||
|
|
||||||
private T[] DeserializeRequestMessageToArray<T>(RequestMessage requestMessage)
|
private T[] DeserializeRequestMessageToArray<T>(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
if (requestMessage?.BodyData?.DetectedBodyType == BodyType.Json)
|
if (requestMessage.BodyData?.DetectedBodyType == BodyType.Json)
|
||||||
{
|
{
|
||||||
var bodyAsJson = requestMessage.BodyData.BodyAsJson;
|
var bodyAsJson = requestMessage.BodyData.BodyAsJson;
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace WireMock.Server
|
|||||||
private static readonly Encoding[] FileBodyIsString = { Encoding.UTF8, Encoding.ASCII };
|
private static readonly Encoding[] FileBodyIsString = { Encoding.UTF8, Encoding.ASCII };
|
||||||
|
|
||||||
#region Files/{filename}
|
#region Files/{filename}
|
||||||
private ResponseMessage FilePost(RequestMessage requestMessage)
|
private IResponseMessage FilePost(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
string filename = GetFileNameFromRequestMessage(requestMessage);
|
string filename = GetFileNameFromRequestMessage(requestMessage);
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ namespace WireMock.Server
|
|||||||
return ResponseMessageBuilder.Create("File created");
|
return ResponseMessageBuilder.Create("File created");
|
||||||
}
|
}
|
||||||
|
|
||||||
private ResponseMessage FilePut(RequestMessage requestMessage)
|
private IResponseMessage FilePut(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
string filename = GetFileNameFromRequestMessage(requestMessage);
|
string filename = GetFileNameFromRequestMessage(requestMessage);
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ namespace WireMock.Server
|
|||||||
return ResponseMessageBuilder.Create("File updated");
|
return ResponseMessageBuilder.Create("File updated");
|
||||||
}
|
}
|
||||||
|
|
||||||
private ResponseMessage FileGet(RequestMessage requestMessage)
|
private IResponseMessage FileGet(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
string filename = GetFileNameFromRequestMessage(requestMessage);
|
string filename = GetFileNameFromRequestMessage(requestMessage);
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ namespace WireMock.Server
|
|||||||
/// Note: Response is returned with no body as a head request doesn't accept a body, only the status code.
|
/// Note: Response is returned with no body as a head request doesn't accept a body, only the status code.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="requestMessage">The request message.</param>
|
/// <param name="requestMessage">The request message.</param>
|
||||||
private ResponseMessage FileHead(RequestMessage requestMessage)
|
private IResponseMessage FileHead(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
string filename = GetFileNameFromRequestMessage(requestMessage);
|
string filename = GetFileNameFromRequestMessage(requestMessage);
|
||||||
|
|
||||||
@@ -92,7 +92,7 @@ namespace WireMock.Server
|
|||||||
return ResponseMessageBuilder.Create(204);
|
return ResponseMessageBuilder.Create(204);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ResponseMessage FileDelete(RequestMessage requestMessage)
|
private IResponseMessage FileDelete(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
string filename = GetFileNameFromRequestMessage(requestMessage);
|
string filename = GetFileNameFromRequestMessage(requestMessage);
|
||||||
|
|
||||||
@@ -106,7 +106,7 @@ namespace WireMock.Server
|
|||||||
return ResponseMessageBuilder.Create("File deleted.");
|
return ResponseMessageBuilder.Create("File deleted.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetFileNameFromRequestMessage(RequestMessage requestMessage)
|
private string GetFileNameFromRequestMessage(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
return Path.GetFileName(requestMessage.Path.Substring(AdminFiles.Length + 1));
|
return Path.GetFileName(requestMessage.Path.Substring(AdminFiles.Length + 1));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ namespace WireMock.Server
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path">The path to the WireMock.org mapping json file.</param>
|
/// <param name="path">The path to the WireMock.org mapping json file.</param>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public void ReadStaticWireMockOrgMappingAndAddOrUpdate([NotNull] string path)
|
public void ReadStaticWireMockOrgMappingAndAddOrUpdate(string path)
|
||||||
{
|
{
|
||||||
Guard.NotNull(path, nameof(path));
|
Guard.NotNull(path, nameof(path));
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ namespace WireMock.Server
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ResponseMessage MappingsPostWireMockOrg(RequestMessage requestMessage)
|
private IResponseMessage MappingsPostWireMockOrg(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,167 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using WireMock.Admin.Mappings;
|
||||||
|
using WireMock.Pact.Models.V2;
|
||||||
|
using WireMock.Util;
|
||||||
|
|
||||||
|
namespace WireMock.Server;
|
||||||
|
|
||||||
|
public partial class WireMockServer
|
||||||
|
{
|
||||||
|
private const string DefaultPath = "/";
|
||||||
|
private const string DefaultMethod = "GET";
|
||||||
|
private const int DefaultStatus = 200;
|
||||||
|
private const string DefaultConsumer = "Default Consumer";
|
||||||
|
private const string DefaultProvider = "Default Provider";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Save the mappings as a Pact Json file V2.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folder">The folder to save the pact file.</param>
|
||||||
|
/// <param name="filename">The filename for the .json file [optional].</param>
|
||||||
|
public void SavePact(string folder, string? filename = null)
|
||||||
|
{
|
||||||
|
var consumer = Consumer ?? DefaultConsumer;
|
||||||
|
var provider = Provider ?? DefaultProvider;
|
||||||
|
|
||||||
|
filename ??= $"{consumer} - {provider}.json";
|
||||||
|
|
||||||
|
var pact = new Pact.Models.V2.Pact
|
||||||
|
{
|
||||||
|
Consumer = new Pacticipant { Name = consumer },
|
||||||
|
Provider = new Pacticipant { Name = provider }
|
||||||
|
};
|
||||||
|
|
||||||
|
foreach (var mapping in MappingModels)
|
||||||
|
{
|
||||||
|
var interaction = new Interaction
|
||||||
|
{
|
||||||
|
Description = mapping.Description,
|
||||||
|
ProviderState = mapping.Title,
|
||||||
|
Request = MapRequest(mapping.Request),
|
||||||
|
Response = MapResponse(mapping.Response)
|
||||||
|
};
|
||||||
|
|
||||||
|
pact.Interactions.Add(interaction);
|
||||||
|
}
|
||||||
|
|
||||||
|
var bytes = JsonUtils.SerializeAsPactFile(pact);
|
||||||
|
_settings.FileSystemHandler.WriteFile(folder, filename, bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Request MapRequest(RequestModel request)
|
||||||
|
{
|
||||||
|
string path;
|
||||||
|
switch (request.Path)
|
||||||
|
{
|
||||||
|
case string pathAsString:
|
||||||
|
path = pathAsString;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PathModel pathModel:
|
||||||
|
path = GetPatternAsStringFromMatchers(pathModel.Matchers, DefaultPath);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
path = DefaultPath;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Request
|
||||||
|
{
|
||||||
|
Method = request.Methods?.FirstOrDefault() ?? DefaultMethod,
|
||||||
|
Path = path,
|
||||||
|
Query = MapQueryParameters(request.Params),
|
||||||
|
Headers = MapRequestHeaders(request.Headers),
|
||||||
|
Body = MapBody(request.Body)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Response MapResponse(ResponseModel? response)
|
||||||
|
{
|
||||||
|
if (response == null)
|
||||||
|
{
|
||||||
|
return new Response();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Response
|
||||||
|
{
|
||||||
|
Status = MapStatusCode(response.StatusCode),
|
||||||
|
Headers = MapResponseHeaders(response.Headers),
|
||||||
|
Body = response.BodyAsJson
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int MapStatusCode(object? statusCode)
|
||||||
|
{
|
||||||
|
if (statusCode is string statusCodeAsString)
|
||||||
|
{
|
||||||
|
return int.TryParse(statusCodeAsString, out var statusCodeAsInt) ? statusCodeAsInt : DefaultStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (statusCode != null)
|
||||||
|
{
|
||||||
|
// Convert to Int32 because Newtonsoft deserializes an 'object' with a number value to a long.
|
||||||
|
return Convert.ToInt32(statusCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
return DefaultStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string? MapQueryParameters(IList<ParamModel>? queryParameters)
|
||||||
|
{
|
||||||
|
if (queryParameters == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var values = queryParameters
|
||||||
|
.Where(qp => qp.Matchers != null && qp.Matchers.Any() && qp.Matchers[0].Pattern is string)
|
||||||
|
.Select(param => $"{Uri.EscapeDataString(param.Name)}={Uri.EscapeDataString((string)param.Matchers![0].Pattern)}");
|
||||||
|
|
||||||
|
return string.Join("&", values);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IDictionary<string, string>? MapRequestHeaders(IList<HeaderModel>? headers)
|
||||||
|
{
|
||||||
|
if (headers == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var validHeaders = headers.Where(h => h.Matchers != null && h.Matchers.Any() && h.Matchers[0].Pattern is string);
|
||||||
|
return validHeaders.ToDictionary(x => x.Name, y => (string)y.Matchers![0].Pattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IDictionary<string, string>? MapResponseHeaders(IDictionary<string, object>? headers)
|
||||||
|
{
|
||||||
|
if (headers == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var validHeaders = headers.Where(h => h.Value is string);
|
||||||
|
return validHeaders.ToDictionary(x => x.Key, y => (string)y.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static object? MapBody(BodyModel? body)
|
||||||
|
{
|
||||||
|
if (body == null || body.Matcher.Name != "JsonMatcher")
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return body.Matcher.Pattern;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string GetPatternAsStringFromMatchers(MatcherModel[]? matchers, string defaultValue)
|
||||||
|
{
|
||||||
|
if (matchers != null && matchers.Any() && matchers[0].Pattern is string patternAsString)
|
||||||
|
{
|
||||||
|
return patternAsString;
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,7 +30,7 @@ public partial class WireMockServer : IWireMockServer
|
|||||||
private const int ServerStartDelayInMs = 100;
|
private const int ServerStartDelayInMs = 100;
|
||||||
|
|
||||||
private readonly WireMockServerSettings _settings;
|
private readonly WireMockServerSettings _settings;
|
||||||
private readonly IOwinSelfHost _httpServer;
|
private readonly IOwinSelfHost? _httpServer;
|
||||||
private readonly IWireMockMiddlewareOptions _options = new WireMockMiddlewareOptions();
|
private readonly IWireMockMiddlewareOptions _options = new WireMockMiddlewareOptions();
|
||||||
private readonly MappingConverter _mappingConverter;
|
private readonly MappingConverter _mappingConverter;
|
||||||
private readonly MatcherMapper _matcherMapper;
|
private readonly MatcherMapper _matcherMapper;
|
||||||
@@ -38,7 +38,7 @@ public partial class WireMockServer : IWireMockServer
|
|||||||
|
|
||||||
/// <inheritdoc cref="IWireMockServer.IsStarted" />
|
/// <inheritdoc cref="IWireMockServer.IsStarted" />
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public bool IsStarted => _httpServer != null && _httpServer.IsStarted;
|
public bool IsStarted => _httpServer is { IsStarted: true };
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
@@ -54,7 +54,15 @@ public partial class WireMockServer : IWireMockServer
|
|||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public string Url => Urls?.FirstOrDefault();
|
public string? Url => Urls?.FirstOrDefault();
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
[PublicAPI]
|
||||||
|
public string? Consumer { get; private set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
[PublicAPI]
|
||||||
|
public string? Provider { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the mappings.
|
/// Gets the mappings.
|
||||||
@@ -100,9 +108,9 @@ public partial class WireMockServer : IWireMockServer
|
|||||||
/// <param name="settings">The WireMockServerSettings.</param>
|
/// <param name="settings">The WireMockServerSettings.</param>
|
||||||
/// <returns>The <see cref="WireMockServer"/>.</returns>
|
/// <returns>The <see cref="WireMockServer"/>.</returns>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static WireMockServer Start([NotNull] WireMockServerSettings settings)
|
public static WireMockServer Start(WireMockServerSettings settings)
|
||||||
{
|
{
|
||||||
Guard.NotNull(settings, nameof(settings));
|
Guard.NotNull(settings);
|
||||||
|
|
||||||
return new WireMockServer(settings);
|
return new WireMockServer(settings);
|
||||||
}
|
}
|
||||||
@@ -114,7 +122,7 @@ public partial class WireMockServer : IWireMockServer
|
|||||||
/// <param name="ssl">The SSL support.</param>
|
/// <param name="ssl">The SSL support.</param>
|
||||||
/// <returns>The <see cref="WireMockServer"/>.</returns>
|
/// <returns>The <see cref="WireMockServer"/>.</returns>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static WireMockServer Start([CanBeNull] int? port = 0, bool ssl = false)
|
public static WireMockServer Start(int? port = 0, bool ssl = false)
|
||||||
{
|
{
|
||||||
return new WireMockServer(new WireMockServerSettings
|
return new WireMockServer(new WireMockServerSettings
|
||||||
{
|
{
|
||||||
@@ -239,7 +247,7 @@ public partial class WireMockServer : IWireMockServer
|
|||||||
|
|
||||||
if (settings.CustomCertificateDefined)
|
if (settings.CustomCertificateDefined)
|
||||||
{
|
{
|
||||||
_options.X509StoreName = settings.CertificateSettings.X509StoreName;
|
_options.X509StoreName = settings.CertificateSettings!.X509StoreName;
|
||||||
_options.X509StoreLocation = settings.CertificateSettings.X509StoreLocation;
|
_options.X509StoreLocation = settings.CertificateSettings.X509StoreLocation;
|
||||||
_options.X509ThumbprintOrSubjectName = settings.CertificateSettings.X509StoreThumbprintOrSubjectName;
|
_options.X509ThumbprintOrSubjectName = settings.CertificateSettings.X509StoreThumbprintOrSubjectName;
|
||||||
_options.X509CertificateFilePath = settings.CertificateSettings.X509CertificateFilePath;
|
_options.X509CertificateFilePath = settings.CertificateSettings.X509CertificateFilePath;
|
||||||
@@ -308,7 +316,7 @@ public partial class WireMockServer : IWireMockServer
|
|||||||
Given(Request.Create().WithPath("/*").UsingAnyMethod())
|
Given(Request.Create().WithPath("/*").UsingAnyMethod())
|
||||||
.WithGuid(Guid.Parse("90008000-0000-4444-a17e-669cd84f1f05"))
|
.WithGuid(Guid.Parse("90008000-0000-4444-a17e-669cd84f1f05"))
|
||||||
.AtPriority(1000)
|
.AtPriority(1000)
|
||||||
.RespondWith(new DynamicResponseProvider(request => ResponseMessageBuilder.Create("No matching mapping found", 404)));
|
.RespondWith(new DynamicResponseProvider(_ => ResponseMessageBuilder.Create("No matching mapping found", 404)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IWireMockServer.Reset" />
|
/// <inheritdoc cref="IWireMockServer.Reset" />
|
||||||
@@ -373,7 +381,7 @@ public partial class WireMockServer : IWireMockServer
|
|||||||
Guard.NotNull(audience, nameof(audience));
|
Guard.NotNull(audience, nameof(audience));
|
||||||
|
|
||||||
#if NETSTANDARD1_3
|
#if NETSTANDARD1_3
|
||||||
throw new NotSupportedException("AzureADAuthentication is not supported for NETStandard 1.3");
|
throw new NotSupportedException("AzureADAuthentication is not supported for NETStandard 1.3");
|
||||||
#else
|
#else
|
||||||
_options.AuthenticationMatcher = new AzureADAuthenticationMatcher(tenant, audience);
|
_options.AuthenticationMatcher = new AzureADAuthenticationMatcher(tenant, audience);
|
||||||
#endif
|
#endif
|
||||||
@@ -381,7 +389,7 @@ public partial class WireMockServer : IWireMockServer
|
|||||||
|
|
||||||
/// <inheritdoc cref="IWireMockServer.SetBasicAuthentication(string, string)" />
|
/// <inheritdoc cref="IWireMockServer.SetBasicAuthentication(string, string)" />
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public void SetBasicAuthentication([NotNull] string username, [NotNull] string password)
|
public void SetBasicAuthentication(string username, string password)
|
||||||
{
|
{
|
||||||
Guard.NotNull(username, nameof(username));
|
Guard.NotNull(username, nameof(username));
|
||||||
Guard.NotNull(password, nameof(password));
|
Guard.NotNull(password, nameof(password));
|
||||||
|
|||||||
@@ -1,24 +1,23 @@
|
|||||||
namespace WireMock.Settings
|
namespace WireMock.Settings;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// HttpClientSettings
|
||||||
|
/// </summary>
|
||||||
|
public class HttpClientSettings
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// HttpClientSettings
|
/// The clientCertificate thumbprint or subject name fragment to use.
|
||||||
|
/// Example thumbprint : "D2DBF135A8D06ACCD0E1FAD9BFB28678DF7A9818". Example subject name: "www.google.com""
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class HttpClientSettings
|
public string? ClientX509Certificate2ThumbprintOrSubjectName { get; set; }
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The clientCertificate thumbprint or subject name fragment to use.
|
|
||||||
/// Example thumbprint : "D2DBF135A8D06ACCD0E1FAD9BFB28678DF7A9818". Example subject name: "www.google.com""
|
|
||||||
/// </summary>
|
|
||||||
public string ClientX509Certificate2ThumbprintOrSubjectName { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines the WebProxySettings.
|
/// Defines the WebProxySettings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public WebProxySettings WebProxySettings { get; set; }
|
public WebProxySettings? WebProxySettings { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Proxy requests should follow redirection (30x).
|
/// Proxy requests should follow redirection (30x).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool? AllowAutoRedirect { get; set; }
|
public bool? AllowAutoRedirect { get; set; }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -15,31 +15,31 @@ namespace WireMock.Settings
|
|||||||
/// X509 StoreName (AddressBook, AuthRoot, CertificateAuthority, My, Root, TrustedPeople or TrustedPublisher)
|
/// X509 StoreName (AddressBook, AuthRoot, CertificateAuthority, My, Root, TrustedPeople or TrustedPublisher)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public string X509StoreName { get; set; }
|
public string? X509StoreName { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// X509 StoreLocation (CurrentUser or LocalMachine)
|
/// X509 StoreLocation (CurrentUser or LocalMachine)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public string X509StoreLocation { get; set; }
|
public string? X509StoreLocation { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// X509 Thumbprint or SubjectName (if not defined, the 'host' is used)
|
/// X509 Thumbprint or SubjectName (if not defined, the 'host' is used)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public string X509StoreThumbprintOrSubjectName { get; set; }
|
public string? X509StoreThumbprintOrSubjectName { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// X509Certificate FilePath
|
/// X509Certificate FilePath
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public string X509CertificateFilePath { get; set; }
|
public string? X509CertificateFilePath { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// X509Certificate Password
|
/// X509Certificate Password
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public string X509CertificatePassword { get; set; }
|
public string? X509CertificatePassword { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// X509StoreName and X509StoreLocation should be defined
|
/// X509StoreName and X509StoreLocation should be defined
|
||||||
|
|||||||
@@ -62,13 +62,13 @@ namespace WireMock.Settings
|
|||||||
/// Gets or sets if the proxy and record settings.
|
/// Gets or sets if the proxy and record settings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public ProxyAndRecordSettings ProxyAndRecordSettings { get; set; }
|
public ProxyAndRecordSettings? ProxyAndRecordSettings { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the urls.
|
/// Gets or sets the urls.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public string[] Urls { get; set; }
|
public string[]? Urls { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// StartTimeout
|
/// StartTimeout
|
||||||
@@ -86,25 +86,25 @@ namespace WireMock.Settings
|
|||||||
/// The username needed for __admin access.
|
/// The username needed for __admin access.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public string AdminUsername { get; set; }
|
public string? AdminUsername { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The password needed for __admin access.
|
/// The password needed for __admin access.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public string AdminPassword { get; set; }
|
public string? AdminPassword { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The AzureAD Tenant needed for __admin access.
|
/// The AzureAD Tenant needed for __admin access.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public string AdminAzureADTenant { get; set; }
|
public string? AdminAzureADTenant { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The AzureAD Audience / Resource for __admin access.
|
/// The AzureAD Audience / Resource for __admin access.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public string AdminAzureADAudience { get; set; }
|
public string? AdminAzureADAudience { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The RequestLog expiration in hours (optional).
|
/// The RequestLog expiration in hours (optional).
|
||||||
@@ -123,14 +123,14 @@ namespace WireMock.Settings
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public Action<object> PreWireMockMiddlewareInit { get; set; }
|
public Action<object>? PreWireMockMiddlewareInit { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Action which is called (with the IAppBuilder or IApplicationBuilder) after the internal WireMockMiddleware is initialized. [Optional]
|
/// Action which is called (with the IAppBuilder or IApplicationBuilder) after the internal WireMockMiddleware is initialized. [Optional]
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public Action<object> PostWireMockMiddlewareInit { get; set; }
|
public Action<object>? PostWireMockMiddlewareInit { get; set; }
|
||||||
|
|
||||||
#if USE_ASPNETCORE
|
#if USE_ASPNETCORE
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -138,7 +138,7 @@ namespace WireMock.Settings
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public Action<IServiceCollection> AdditionalServiceRegistration { get; set; }
|
public Action<IServiceCollection>? AdditionalServiceRegistration { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Policies to use when using CORS. By default CORS is disabled. [Optional]
|
/// Policies to use when using CORS. By default CORS is disabled. [Optional]
|
||||||
@@ -152,21 +152,21 @@ namespace WireMock.Settings
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public IWireMockLogger Logger { get; set; }
|
public IWireMockLogger Logger { get; set; } = null!;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handler to interact with the file system to read and write static mapping files.
|
/// Handler to interact with the file system to read and write static mapping files.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public IFileSystemHandler FileSystemHandler { get; set; }
|
public IFileSystemHandler FileSystemHandler { get; set; } = null!;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Action which can be used to add additional Handlebars registrations. [Optional]
|
/// Action which can be used to add additional Handlebars registrations. [Optional]
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public Action<IHandlebars, IFileSystemHandler> HandlebarsRegistrationCallback { get; set; }
|
public Action<IHandlebars, IFileSystemHandler>? HandlebarsRegistrationCallback { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allow the usage of CSharpCodeMatcher (default is not allowed).
|
/// Allow the usage of CSharpCodeMatcher (default is not allowed).
|
||||||
@@ -220,7 +220,7 @@ namespace WireMock.Settings
|
|||||||
/// X509CertificateFilePath and X509CertificatePassword should be defined
|
/// X509CertificateFilePath and X509CertificatePassword should be defined
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public WireMockCertificateSettings CertificateSettings { get; set; }
|
public WireMockCertificateSettings? CertificateSettings { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines if custom CertificateSettings are defined
|
/// Defines if custom CertificateSettings are defined
|
||||||
@@ -232,7 +232,7 @@ namespace WireMock.Settings
|
|||||||
/// Defines the global IWebhookSettings to use.
|
/// Defines the global IWebhookSettings to use.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public WebhookSettings WebhookSettings { get; set; }
|
public WebhookSettings? WebhookSettings { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Use the <see cref="RegexExtended"/> instead of the default <see cref="Regex"/> (default set to true).
|
/// Use the <see cref="RegexExtended"/> instead of the default <see cref="Regex"/> (default set to true).
|
||||||
@@ -250,6 +250,6 @@ namespace WireMock.Settings
|
|||||||
/// Custom matcher mappings for static mappings
|
/// Custom matcher mappings for static mappings
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[PublicAPI, JsonIgnore]
|
[PublicAPI, JsonIgnore]
|
||||||
public IDictionary<string, Func<MatcherModel, IMatcher>> CustomMatcherMappings { get; set; }
|
public IDictionary<string, Func<MatcherModel, IMatcher>>? CustomMatcherMappings { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,8 +7,8 @@ namespace WireMock.Transformers
|
|||||||
{
|
{
|
||||||
interface ITransformer
|
interface ITransformer
|
||||||
{
|
{
|
||||||
ResponseMessage Transform(RequestMessage requestMessage, ResponseMessage original, bool useTransformerForBodyAsFile, ReplaceNodeOptions options);
|
ResponseMessage Transform(IRequestMessage requestMessage, IResponseMessage original, bool useTransformerForBodyAsFile, ReplaceNodeOptions options);
|
||||||
|
|
||||||
(IBodyData BodyData, IDictionary<string, WireMockList<string>> Headers) Transform(RequestMessage originalRequestMessage, ResponseMessage originalResponseMessage, IBodyData bodyData, IDictionary<string, WireMockList<string>> headers, ReplaceNodeOptions options);
|
(IBodyData BodyData, IDictionary<string, WireMockList<string>> Headers) Transform(IRequestMessage originalRequestMessage, IResponseMessage originalResponseMessage, IBodyData bodyData, IDictionary<string, WireMockList<string>> headers, ReplaceNodeOptions options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,7 @@ namespace WireMock.Transformers
|
|||||||
_factory = factory ?? throw new ArgumentNullException(nameof(factory));
|
_factory = factory ?? throw new ArgumentNullException(nameof(factory));
|
||||||
}
|
}
|
||||||
|
|
||||||
public (IBodyData BodyData, IDictionary<string, WireMockList<string>> Headers) Transform(RequestMessage originalRequestMessage, ResponseMessage originalResponseMessage, IBodyData bodyData, IDictionary<string, WireMockList<string>> headers, ReplaceNodeOptions options)
|
public (IBodyData BodyData, IDictionary<string, WireMockList<string>> Headers) Transform(IRequestMessage originalRequestMessage, IResponseMessage originalResponseMessage, IBodyData bodyData, IDictionary<string, WireMockList<string>> headers, ReplaceNodeOptions options)
|
||||||
{
|
{
|
||||||
var transformerContext = _factory.Create();
|
var transformerContext = _factory.Create();
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ namespace WireMock.Transformers
|
|||||||
return (newBodyData, TransformHeaders(transformerContext, model, headers));
|
return (newBodyData, TransformHeaders(transformerContext, model, headers));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResponseMessage Transform(RequestMessage requestMessage, ResponseMessage original, bool useTransformerForBodyAsFile, ReplaceNodeOptions options)
|
public ResponseMessage Transform(IRequestMessage requestMessage, IResponseMessage original, bool useTransformerForBodyAsFile, ReplaceNodeOptions options)
|
||||||
{
|
{
|
||||||
var transformerContext = _factory.Create();
|
var transformerContext = _factory.Create();
|
||||||
|
|
||||||
|
|||||||
+200
-193
@@ -1,213 +1,220 @@
|
|||||||
using Newtonsoft.Json;
|
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using WireMock.Pact.Models.V2;
|
||||||
using WireMock.Serialization;
|
using WireMock.Serialization;
|
||||||
|
|
||||||
namespace WireMock.Util
|
namespace WireMock.Util;
|
||||||
|
|
||||||
|
internal static class JsonUtils
|
||||||
{
|
{
|
||||||
internal static class JsonUtils
|
public static bool TryParseAsComplexObject(string strInput, [NotNullWhen(true)] out JToken? token)
|
||||||
{
|
{
|
||||||
public static bool TryParseAsComplexObject(string strInput, out JToken token)
|
token = null;
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(strInput))
|
||||||
{
|
{
|
||||||
token = null;
|
return false;
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(strInput))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
strInput = strInput.Trim();
|
|
||||||
if ((!strInput.StartsWith("{") || !strInput.EndsWith("}")) && (!strInput.StartsWith("[") || !strInput.EndsWith("]")))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// Try to convert this string into a JToken
|
|
||||||
token = JToken.Parse(strInput);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string Serialize<T>(T value)
|
strInput = strInput.Trim();
|
||||||
|
if ((!strInput.StartsWith("{") || !strInput.EndsWith("}")) && (!strInput.StartsWith("[") || !strInput.EndsWith("]")))
|
||||||
{
|
{
|
||||||
return JsonConvert.SerializeObject(value, JsonSerializationConstants.JsonSerializerSettingsIncludeNullValues);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
try
|
||||||
/// Load a Newtonsoft.Json.Linq.JObject from a string that contains JSON.
|
|
||||||
/// Using : DateParseHandling = DateParseHandling.None
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="json">A System.String that contains JSON.</param>
|
|
||||||
/// <returns>A Newtonsoft.Json.Linq.JToken populated from the string that contains JSON.</returns>
|
|
||||||
public static JToken Parse(string json)
|
|
||||||
{
|
{
|
||||||
return JsonConvert.DeserializeObject<JToken>(json, JsonSerializationConstants.JsonDeserializerSettingsWithDateParsingNone);
|
// Try to convert this string into a JToken
|
||||||
|
token = JToken.Parse(strInput);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
catch
|
||||||
/// <summary>
|
|
||||||
/// Deserializes the JSON to a .NET object.
|
|
||||||
/// Using : DateParseHandling = DateParseHandling.None
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="json">A System.String that contains JSON.</param>
|
|
||||||
/// <returns>The deserialized object from the JSON string.</returns>
|
|
||||||
public static object DeserializeObject(string json)
|
|
||||||
{
|
{
|
||||||
return JsonConvert.DeserializeObject(json, JsonSerializationConstants.JsonDeserializerSettingsWithDateParsingNone);
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Deserializes the JSON to the specified .NET type.
|
|
||||||
/// Using : DateParseHandling = DateParseHandling.None
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="json">A System.String that contains JSON.</param>
|
|
||||||
/// <returns>The deserialized object from the JSON string.</returns>
|
|
||||||
public static T DeserializeObject<T>(string json)
|
|
||||||
{
|
|
||||||
return JsonConvert.DeserializeObject<T>(json, JsonSerializationConstants.JsonDeserializerSettingsWithDateParsingNone);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static T ParseJTokenToObject<T>(object value)
|
|
||||||
{
|
|
||||||
switch (value)
|
|
||||||
{
|
|
||||||
case JToken tokenValue:
|
|
||||||
return tokenValue.ToObject<T>();
|
|
||||||
|
|
||||||
default:
|
|
||||||
return default(T);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string GenerateDynamicLinqStatement(JToken jsonObject)
|
|
||||||
{
|
|
||||||
var lines = new List<string>();
|
|
||||||
WalkNode(jsonObject, null, null, lines);
|
|
||||||
|
|
||||||
return lines.First();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void WalkNode(JToken node, string path, string propertyName, List<string> lines)
|
|
||||||
{
|
|
||||||
if (node.Type == JTokenType.Object)
|
|
||||||
{
|
|
||||||
ProcessObject(node, propertyName, lines);
|
|
||||||
}
|
|
||||||
else if (node.Type == JTokenType.Array)
|
|
||||||
{
|
|
||||||
ProcessArray(node, propertyName, lines);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ProcessItem(node, path ?? "it", propertyName, lines);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void ProcessObject(JToken node, string propertyName, List<string> lines)
|
|
||||||
{
|
|
||||||
var items = new List<string>();
|
|
||||||
var text = new StringBuilder("new (");
|
|
||||||
|
|
||||||
// In case of Object, loop all children. Do a ToArray() to avoid `Collection was modified` exceptions.
|
|
||||||
foreach (JProperty child in node.Children<JProperty>().ToArray())
|
|
||||||
{
|
|
||||||
WalkNode(child.Value, child.Path, child.Name, items);
|
|
||||||
}
|
|
||||||
|
|
||||||
text.Append(string.Join(", ", items));
|
|
||||||
text.Append(")");
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(propertyName))
|
|
||||||
{
|
|
||||||
text.AppendFormat(" as {0}", propertyName);
|
|
||||||
}
|
|
||||||
|
|
||||||
lines.Add(text.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void ProcessArray(JToken node, string propertyName, List<string> lines)
|
|
||||||
{
|
|
||||||
var items = new List<string>();
|
|
||||||
var text = new StringBuilder("(new [] { ");
|
|
||||||
|
|
||||||
// In case of Array, loop all items. Do a ToArray() to avoid `Collection was modified` exceptions.
|
|
||||||
int idx = 0;
|
|
||||||
foreach (JToken child in node.Children().ToArray())
|
|
||||||
{
|
|
||||||
WalkNode(child, $"{node.Path}[{idx}]", null, items);
|
|
||||||
idx++;
|
|
||||||
}
|
|
||||||
|
|
||||||
text.Append(string.Join(", ", items));
|
|
||||||
text.Append("})");
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(propertyName))
|
|
||||||
{
|
|
||||||
text.AppendFormat(" as {0}", propertyName);
|
|
||||||
}
|
|
||||||
|
|
||||||
lines.Add(text.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void ProcessItem(JToken node, string path, string propertyName, List<string> lines)
|
|
||||||
{
|
|
||||||
string castText;
|
|
||||||
switch (node.Type)
|
|
||||||
{
|
|
||||||
case JTokenType.Boolean:
|
|
||||||
castText = $"bool({path})";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case JTokenType.Date:
|
|
||||||
castText = $"DateTime({path})";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case JTokenType.Float:
|
|
||||||
castText = $"double({path})";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case JTokenType.Guid:
|
|
||||||
castText = $"Guid({path})";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case JTokenType.Integer:
|
|
||||||
castText = $"long({path})";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case JTokenType.Null:
|
|
||||||
castText = "null";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case JTokenType.String:
|
|
||||||
castText = $"string({path})";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case JTokenType.TimeSpan:
|
|
||||||
castText = $"TimeSpan({path})";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case JTokenType.Uri:
|
|
||||||
castText = $"Uri({path})";
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
throw new NotSupportedException($"JTokenType '{node.Type}' cannot be converted to a Dynamic Linq cast operator.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(propertyName))
|
|
||||||
{
|
|
||||||
castText += $" as {propertyName}";
|
|
||||||
}
|
|
||||||
|
|
||||||
lines.Add(castText);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string Serialize(object value)
|
||||||
|
{
|
||||||
|
return JsonConvert.SerializeObject(value, JsonSerializationConstants.JsonSerializerSettingsIncludeNullValues);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] SerializeAsPactFile(object value)
|
||||||
|
{
|
||||||
|
var json = JsonConvert.SerializeObject(value, JsonSerializationConstants.JsonSerializerSettingsPact);
|
||||||
|
return Encoding.UTF8.GetBytes(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Load a Newtonsoft.Json.Linq.JObject from a string that contains JSON.
|
||||||
|
/// Using : DateParseHandling = DateParseHandling.None
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="json">A System.String that contains JSON.</param>
|
||||||
|
/// <returns>A Newtonsoft.Json.Linq.JToken populated from the string that contains JSON.</returns>
|
||||||
|
public static JToken Parse(string json)
|
||||||
|
{
|
||||||
|
return JsonConvert.DeserializeObject<JToken>(json, JsonSerializationConstants.JsonDeserializerSettingsWithDateParsingNone);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deserializes the JSON to a .NET object.
|
||||||
|
/// Using : DateParseHandling = DateParseHandling.None
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="json">A System.String that contains JSON.</param>
|
||||||
|
/// <returns>The deserialized object from the JSON string.</returns>
|
||||||
|
public static object DeserializeObject(string json)
|
||||||
|
{
|
||||||
|
return JsonConvert.DeserializeObject(json, JsonSerializationConstants.JsonDeserializerSettingsWithDateParsingNone);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deserializes the JSON to the specified .NET type.
|
||||||
|
/// Using : DateParseHandling = DateParseHandling.None
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="json">A System.String that contains JSON.</param>
|
||||||
|
/// <returns>The deserialized object from the JSON string.</returns>
|
||||||
|
public static T DeserializeObject<T>(string json)
|
||||||
|
{
|
||||||
|
return JsonConvert.DeserializeObject<T>(json, JsonSerializationConstants.JsonDeserializerSettingsWithDateParsingNone);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static T ParseJTokenToObject<T>(object value)
|
||||||
|
{
|
||||||
|
switch (value)
|
||||||
|
{
|
||||||
|
case JToken tokenValue:
|
||||||
|
return tokenValue.ToObject<T>();
|
||||||
|
|
||||||
|
default:
|
||||||
|
return default(T);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string GenerateDynamicLinqStatement(JToken jsonObject)
|
||||||
|
{
|
||||||
|
var lines = new List<string>();
|
||||||
|
WalkNode(jsonObject, null, null, lines);
|
||||||
|
|
||||||
|
return lines.First();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void WalkNode(JToken node, string? path, string? propertyName, List<string> lines)
|
||||||
|
{
|
||||||
|
if (node.Type == JTokenType.Object)
|
||||||
|
{
|
||||||
|
ProcessObject(node, propertyName, lines);
|
||||||
|
}
|
||||||
|
else if (node.Type == JTokenType.Array)
|
||||||
|
{
|
||||||
|
ProcessArray(node, propertyName, lines);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ProcessItem(node, path ?? "it", propertyName, lines);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ProcessObject(JToken node, string? propertyName, List<string> lines)
|
||||||
|
{
|
||||||
|
var items = new List<string>();
|
||||||
|
var text = new StringBuilder("new (");
|
||||||
|
|
||||||
|
// In case of Object, loop all children. Do a ToArray() to avoid `Collection was modified` exceptions.
|
||||||
|
foreach (JProperty child in node.Children<JProperty>().ToArray())
|
||||||
|
{
|
||||||
|
WalkNode(child.Value, child.Path, child.Name, items);
|
||||||
|
}
|
||||||
|
|
||||||
|
text.Append(string.Join(", ", items));
|
||||||
|
text.Append(")");
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(propertyName))
|
||||||
|
{
|
||||||
|
text.AppendFormat(" as {0}", propertyName);
|
||||||
|
}
|
||||||
|
|
||||||
|
lines.Add(text.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ProcessArray(JToken node, string? propertyName, List<string> lines)
|
||||||
|
{
|
||||||
|
var items = new List<string>();
|
||||||
|
var text = new StringBuilder("(new [] { ");
|
||||||
|
|
||||||
|
// In case of Array, loop all items. Do a ToArray() to avoid `Collection was modified` exceptions.
|
||||||
|
int idx = 0;
|
||||||
|
foreach (JToken child in node.Children().ToArray())
|
||||||
|
{
|
||||||
|
WalkNode(child, $"{node.Path}[{idx}]", null, items);
|
||||||
|
idx++;
|
||||||
|
}
|
||||||
|
|
||||||
|
text.Append(string.Join(", ", items));
|
||||||
|
text.Append("})");
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(propertyName))
|
||||||
|
{
|
||||||
|
text.AppendFormat(" as {0}", propertyName);
|
||||||
|
}
|
||||||
|
|
||||||
|
lines.Add(text.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ProcessItem(JToken node, string path, string propertyName, List<string> lines)
|
||||||
|
{
|
||||||
|
string castText;
|
||||||
|
switch (node.Type)
|
||||||
|
{
|
||||||
|
case JTokenType.Boolean:
|
||||||
|
castText = $"bool({path})";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case JTokenType.Date:
|
||||||
|
castText = $"DateTime({path})";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case JTokenType.Float:
|
||||||
|
castText = $"double({path})";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case JTokenType.Guid:
|
||||||
|
castText = $"Guid({path})";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case JTokenType.Integer:
|
||||||
|
castText = $"long({path})";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case JTokenType.Null:
|
||||||
|
castText = "null";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case JTokenType.String:
|
||||||
|
castText = $"string({path})";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case JTokenType.TimeSpan:
|
||||||
|
castText = $"TimeSpan({path})";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case JTokenType.Uri:
|
||||||
|
castText = $"Uri({path})";
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new NotSupportedException($"JTokenType '{node.Type}' cannot be converted to a Dynamic Linq cast operator.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(propertyName))
|
||||||
|
{
|
||||||
|
castText += $" as {propertyName}";
|
||||||
|
}
|
||||||
|
|
||||||
|
lines.Add(castText);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -2,29 +2,28 @@ using Nelibur.ObjectMapper;
|
|||||||
using WireMock.Admin.Settings;
|
using WireMock.Admin.Settings;
|
||||||
using WireMock.Settings;
|
using WireMock.Settings;
|
||||||
|
|
||||||
namespace WireMock.Util
|
namespace WireMock.Util;
|
||||||
|
|
||||||
|
internal sealed class TinyMapperUtils
|
||||||
{
|
{
|
||||||
internal sealed class TinyMapperUtils
|
public static TinyMapperUtils Instance { get; } = new();
|
||||||
|
|
||||||
|
private TinyMapperUtils()
|
||||||
{
|
{
|
||||||
public static TinyMapperUtils Instance { get; } = new TinyMapperUtils();
|
TinyMapper.Bind<ProxyAndRecordSettings, ProxyAndRecordSettingsModel>();
|
||||||
|
TinyMapper.Bind<WebProxySettings, WebProxySettingsModel>();
|
||||||
|
|
||||||
private TinyMapperUtils()
|
TinyMapper.Bind<ProxyAndRecordSettingsModel, ProxyAndRecordSettings>();
|
||||||
{
|
TinyMapper.Bind<WebProxySettingsModel, WebProxySettings>();
|
||||||
TinyMapper.Bind<ProxyAndRecordSettings, ProxyAndRecordSettingsModel>();
|
}
|
||||||
TinyMapper.Bind<WebProxySettings, WebProxySettingsModel>();
|
|
||||||
|
|
||||||
TinyMapper.Bind<ProxyAndRecordSettingsModel, ProxyAndRecordSettings>();
|
public ProxyAndRecordSettingsModel? Map(ProxyAndRecordSettings? instance)
|
||||||
TinyMapper.Bind<WebProxySettingsModel, WebProxySettings>();
|
{
|
||||||
}
|
return instance == null ? null : TinyMapper.Map<ProxyAndRecordSettingsModel>(instance);
|
||||||
|
}
|
||||||
|
|
||||||
public ProxyAndRecordSettingsModel Map(ProxyAndRecordSettings instance)
|
public ProxyAndRecordSettings? Map(ProxyAndRecordSettingsModel? model)
|
||||||
{
|
{
|
||||||
return instance == null ? null : TinyMapper.Map<ProxyAndRecordSettingsModel>(instance);
|
return model == null ? null : TinyMapper.Map<ProxyAndRecordSettings>(model);
|
||||||
}
|
|
||||||
|
|
||||||
public ProxyAndRecordSettings Map(ProxyAndRecordSettingsModel model)
|
|
||||||
{
|
|
||||||
return model == null ? null : TinyMapper.Map<ProxyAndRecordSettings>(model);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -52,6 +52,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Remove="Util\FileSystemWatcherExtensions.cs" />
|
<Compile Remove="Util\FileSystemWatcherExtensions.cs" />
|
||||||
|
<Compile Remove="Matchers\Request\IRequestMatcher.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -88,6 +89,7 @@
|
|||||||
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
|
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
|
||||||
<PackageReference Include="Scriban.Signed" Version="2.1.4" />
|
<PackageReference Include="Scriban.Signed" Version="2.1.4" />
|
||||||
<!--<PackageReference Include="Mapster" Version="7.2.0" />-->
|
<!--<PackageReference Include="Mapster" Version="7.2.0" />-->
|
||||||
|
<PackageReference Include="Nullable" Version="1.3.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net46' ">
|
<ItemGroup Condition=" '$(TargetFramework)' == 'net46' ">
|
||||||
@@ -98,11 +100,13 @@
|
|||||||
<PackageReference Include="System.Net.Http" Version="4.3.4" />
|
<PackageReference Include="System.Net.Http" Version="4.3.4" />
|
||||||
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
|
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
|
||||||
<PackageReference Include="Scriban.Signed" Version="2.1.4" />
|
<PackageReference Include="Scriban.Signed" Version="2.1.4" />
|
||||||
|
<PackageReference Include="Nullable" Version="1.3.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
|
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
|
||||||
<PackageReference Include="Scriban.Signed" Version="2.1.4" />
|
<PackageReference Include="Scriban.Signed" Version="2.1.4" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
|
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
|
||||||
|
<PackageReference Include="Nullable" Version="1.3.0" />
|
||||||
|
|
||||||
<!-- https://github.com/WireMock-Net/WireMock.Net/issues/697 -->
|
<!-- https://github.com/WireMock-Net/WireMock.Net/issues/697 -->
|
||||||
<PackageReference Include="System.Text.Encodings.Web" Version="4.7.2" />
|
<PackageReference Include="System.Text.Encodings.Web" Version="4.7.2" />
|
||||||
@@ -112,17 +116,20 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
|
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
|
||||||
|
<PackageReference Include="System.Collections.Specialized" Version="4.3.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.7" />
|
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.7" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Https" Version="1.1.3" />
|
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Https" Version="1.1.3" />
|
||||||
<PackageReference Include="System.Xml.XmlDocument" Version="4.3.0" />
|
<PackageReference Include="System.Xml.XmlDocument" Version="4.3.0" />
|
||||||
<PackageReference Include="System.Xml.XPath.XmlDocument" Version="4.3.0" />
|
<PackageReference Include="System.Xml.XPath.XmlDocument" Version="4.3.0" />
|
||||||
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
|
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
|
||||||
<PackageReference Include="Scriban.Signed" Version="2.1.4" />
|
<PackageReference Include="Scriban.Signed" Version="2.1.4" />
|
||||||
|
<PackageReference Include="Nullable" Version="1.3.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1' ">
|
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1' ">
|
||||||
<PackageReference Include="Scriban.Signed" Version="3.3.2" />
|
<PackageReference Include="Scriban.Signed" Version="3.3.2" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
|
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
|
||||||
|
<PackageReference Include="Nullable" Version="1.3.0" />
|
||||||
|
|
||||||
<!-- https://github.com/WireMock-Net/WireMock.Net/issues/507 -->
|
<!-- https://github.com/WireMock-Net/WireMock.Net/issues/507 -->
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Server.IIS" Version="2.2.6" />
|
<PackageReference Include="Microsoft.AspNetCore.Server.IIS" Version="2.2.6" />
|
||||||
@@ -133,6 +140,12 @@
|
|||||||
<PackageReference Include="Scriban.Signed" Version="3.3.2" />
|
<PackageReference Include="Scriban.Signed" Version="3.3.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Update="Server\WireMockServer.*.cs">
|
||||||
|
<DependentUpon>WireMockServer.cs</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Handlebars.Net.Helpers" Version="2.3.3" />
|
<PackageReference Include="Handlebars.Net.Helpers" Version="2.3.3" />
|
||||||
<PackageReference Include="Handlebars.Net.Helpers.DynamicLinq" Version="2.3.3" />
|
<PackageReference Include="Handlebars.Net.Helpers.DynamicLinq" Version="2.3.3" />
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ namespace WireMock.Net.Tests.Owin
|
|||||||
_mappingMock.SetupGet(m => m.Provider).Returns(responseBuilder);
|
_mappingMock.SetupGet(m => m.Provider).Returns(responseBuilder);
|
||||||
_mappingMock.SetupGet(m => m.Settings).Returns(settings);
|
_mappingMock.SetupGet(m => m.Settings).Returns(settings);
|
||||||
|
|
||||||
var newMappingFromProxy = new Mapping(Guid.NewGuid(), "", null, settings, Request.Create(), Response.Create(), 0, null, null, null, null, null, null);
|
var newMappingFromProxy = new Mapping(Guid.NewGuid(), string.Empty, string.Empty, null, settings, Request.Create(), Response.Create(), 0, null, null, null, null, null, null);
|
||||||
_mappingMock.Setup(m => m.ProvideResponseAsync(It.IsAny<RequestMessage>())).ReturnsAsync((new ResponseMessage(), newMappingFromProxy));
|
_mappingMock.Setup(m => m.ProvideResponseAsync(It.IsAny<RequestMessage>())).ReturnsAsync((new ResponseMessage(), newMappingFromProxy));
|
||||||
|
|
||||||
var requestBuilder = Request.Create().UsingAnyMethod();
|
var requestBuilder = Request.Create().UsingAnyMethod();
|
||||||
@@ -230,7 +230,7 @@ namespace WireMock.Net.Tests.Owin
|
|||||||
_mappingMock.SetupGet(m => m.Provider).Returns(responseBuilder);
|
_mappingMock.SetupGet(m => m.Provider).Returns(responseBuilder);
|
||||||
_mappingMock.SetupGet(m => m.Settings).Returns(settings);
|
_mappingMock.SetupGet(m => m.Settings).Returns(settings);
|
||||||
|
|
||||||
var newMappingFromProxy = new Mapping(Guid.NewGuid(), "", null, settings, Request.Create(), Response.Create(), 0, null, null, null, null, null, null);
|
var newMappingFromProxy = new Mapping(Guid.NewGuid(), "my-title", "my-description", null, settings, Request.Create(), Response.Create(), 0, null, null, null, null, null, null);
|
||||||
_mappingMock.Setup(m => m.ProvideResponseAsync(It.IsAny<RequestMessage>())).ReturnsAsync((new ResponseMessage(), newMappingFromProxy));
|
_mappingMock.Setup(m => m.ProvideResponseAsync(It.IsAny<RequestMessage>())).ReturnsAsync((new ResponseMessage(), newMappingFromProxy));
|
||||||
|
|
||||||
var requestBuilder = Request.Create().UsingAnyMethod();
|
var requestBuilder = Request.Create().UsingAnyMethod();
|
||||||
|
|||||||
@@ -0,0 +1,92 @@
|
|||||||
|
using System.IO;
|
||||||
|
using System.Net;
|
||||||
|
using WireMock.Matchers;
|
||||||
|
using WireMock.RequestBuilders;
|
||||||
|
using WireMock.ResponseBuilders;
|
||||||
|
using WireMock.Server;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace WireMock.Net.Tests.Pact;
|
||||||
|
|
||||||
|
public class PactTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void SavePact_Get_Request()
|
||||||
|
{
|
||||||
|
var server = WireMockServer.Start();
|
||||||
|
server
|
||||||
|
.WithConsumer("Something API Consumer Get")
|
||||||
|
.WithProvider("Something API")
|
||||||
|
|
||||||
|
.Given(Request.Create()
|
||||||
|
.UsingGet()
|
||||||
|
.WithPath("/tester")
|
||||||
|
.WithParam("q1", "test")
|
||||||
|
.WithParam("q2", "ok")
|
||||||
|
.WithHeader("Accept", "application/json")
|
||||||
|
)
|
||||||
|
.WithTitle("A GET request to retrieve the something")
|
||||||
|
.RespondWith(
|
||||||
|
Response.Create()
|
||||||
|
.WithStatusCode(HttpStatusCode.OK)
|
||||||
|
.WithHeader("Content-Type", "application/json; charset=utf-8")
|
||||||
|
.WithBodyAsJson(new
|
||||||
|
{
|
||||||
|
Id = "tester",
|
||||||
|
FirstName = "Totally",
|
||||||
|
LastName = "Awesome"
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
server.SavePact(Path.Combine("../../../", "Pact", "files"), "pact-get.json");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void SavePact_Multiple_Requests()
|
||||||
|
{
|
||||||
|
var server = WireMockServer.Start();
|
||||||
|
server
|
||||||
|
.WithConsumer("Something API Consumer Multiple")
|
||||||
|
.WithProvider("Something API")
|
||||||
|
|
||||||
|
.Given(Request.Create()
|
||||||
|
.UsingPost()
|
||||||
|
.WithPath("/tester")
|
||||||
|
.WithParam("q1", "test")
|
||||||
|
.WithParam("q2", "ok")
|
||||||
|
.WithHeader("Accept", "application/json")
|
||||||
|
)
|
||||||
|
.WithTitle("A GET request to retrieve the something")
|
||||||
|
.RespondWith(
|
||||||
|
Response.Create()
|
||||||
|
.WithStatusCode(HttpStatusCode.OK)
|
||||||
|
.WithHeader("Content-Type", "application/json; charset=utf-8")
|
||||||
|
.WithBodyAsJson(new
|
||||||
|
{
|
||||||
|
Id = "tester",
|
||||||
|
FirstName = "Totally",
|
||||||
|
LastName = "Awesome"
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
server
|
||||||
|
.Given(Request.Create()
|
||||||
|
.UsingPost()
|
||||||
|
.WithPath("/add")
|
||||||
|
.WithHeader("Accept", "application/json")
|
||||||
|
.WithBody(new JsonMatcher("{ \"Id\" : \"1\", \"FirstName\" : \"Totally\" }"))
|
||||||
|
)
|
||||||
|
.WithTitle("A Post request to add the something")
|
||||||
|
.RespondWith(
|
||||||
|
Response.Create()
|
||||||
|
.WithStatusCode(HttpStatusCode.RedirectMethod)
|
||||||
|
.WithBodyAsJson(new
|
||||||
|
{
|
||||||
|
Id = "1",
|
||||||
|
FirstName = "Totally"
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
server.SavePact(Path.Combine("../../../", "Pact", "files"), "pact-multiple.json");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
{
|
||||||
|
"Consumer": {
|
||||||
|
"Name": "Something API Consumer Get"
|
||||||
|
},
|
||||||
|
"Interactions": [
|
||||||
|
{
|
||||||
|
"ProviderState": "A GET request to retrieve the something",
|
||||||
|
"Request": {
|
||||||
|
"Headers": {
|
||||||
|
"Accept": "application/json"
|
||||||
|
},
|
||||||
|
"Method": "GET",
|
||||||
|
"Path": "/tester",
|
||||||
|
"Query": "q1=test&q2=ok"
|
||||||
|
},
|
||||||
|
"Response": {
|
||||||
|
"Body": {
|
||||||
|
"Id": "tester",
|
||||||
|
"FirstName": "Totally",
|
||||||
|
"LastName": "Awesome"
|
||||||
|
},
|
||||||
|
"Headers": {
|
||||||
|
"Content-Type": "application/json; charset=utf-8"
|
||||||
|
},
|
||||||
|
"Status": 200
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"Provider": {
|
||||||
|
"Name": "Something API"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
{
|
||||||
|
"Consumer": {
|
||||||
|
"Name": "Something API Consumer Multiple"
|
||||||
|
},
|
||||||
|
"Interactions": [
|
||||||
|
{
|
||||||
|
"ProviderState": "A Post request to add the something",
|
||||||
|
"Request": {
|
||||||
|
"Headers": {
|
||||||
|
"Accept": "application/json"
|
||||||
|
},
|
||||||
|
"Method": "POST",
|
||||||
|
"Path": "/add",
|
||||||
|
"Body": "{ \"Id\" : \"1\", \"FirstName\" : \"Totally\" }"
|
||||||
|
},
|
||||||
|
"Response": {
|
||||||
|
"Body": {
|
||||||
|
"Id": "1",
|
||||||
|
"FirstName": "Totally"
|
||||||
|
},
|
||||||
|
"Status": 303
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ProviderState": "A GET request to retrieve the something",
|
||||||
|
"Request": {
|
||||||
|
"Headers": {
|
||||||
|
"Accept": "application/json"
|
||||||
|
},
|
||||||
|
"Method": "POST",
|
||||||
|
"Path": "/tester",
|
||||||
|
"Query": "q1=test&q2=ok"
|
||||||
|
},
|
||||||
|
"Response": {
|
||||||
|
"Body": {
|
||||||
|
"Id": "tester",
|
||||||
|
"FirstName": "Totally",
|
||||||
|
"LastName": "Awesome"
|
||||||
|
},
|
||||||
|
"Headers": {
|
||||||
|
"Content-Type": "application/json; charset=utf-8"
|
||||||
|
},
|
||||||
|
"Status": 200
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"Provider": {
|
||||||
|
"Name": "Something API"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using NFluent;
|
using NFluent;
|
||||||
using WireMock.Logging;
|
using WireMock.Logging;
|
||||||
using WireMock.Models;
|
using WireMock.Models;
|
||||||
@@ -8,114 +8,113 @@ using WireMock.Types;
|
|||||||
using WireMock.Util;
|
using WireMock.Util;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.Serialization
|
namespace WireMock.Net.Tests.Serialization;
|
||||||
|
|
||||||
|
public class LogEntryMapperTests
|
||||||
{
|
{
|
||||||
public class LogEntryMapperTests
|
[Fact]
|
||||||
|
public void LogEntryMapper_Map_LogEntry_Check_BodyTypeBytes()
|
||||||
{
|
{
|
||||||
[Fact]
|
// Assign
|
||||||
public void LogEntryMapper_Map_LogEntry_Check_BodyTypeBytes()
|
var logEntry = new LogEntry
|
||||||
{
|
{
|
||||||
// Assign
|
RequestMessage = new RequestMessage(
|
||||||
var logEntry = new LogEntry
|
new UrlDetails("http://localhost"),
|
||||||
{
|
"post",
|
||||||
RequestMessage = new RequestMessage(
|
"::1",
|
||||||
new UrlDetails("http://localhost"),
|
new BodyData
|
||||||
"post",
|
|
||||||
"::1",
|
|
||||||
new BodyData
|
|
||||||
{
|
|
||||||
DetectedBodyType = BodyType.Bytes,
|
|
||||||
BodyAsBytes = new byte[] { 0 }
|
|
||||||
}
|
|
||||||
),
|
|
||||||
ResponseMessage = new ResponseMessage
|
|
||||||
{
|
{
|
||||||
BodyData = new BodyData
|
DetectedBodyType = BodyType.Bytes,
|
||||||
{
|
BodyAsBytes = new byte[] { 0 }
|
||||||
DetectedBodyType = BodyType.Bytes,
|
|
||||||
BodyAsBytes = new byte[] { 0 }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
),
|
||||||
|
ResponseMessage = new ResponseMessage
|
||||||
|
{
|
||||||
|
BodyData = new BodyData
|
||||||
|
{
|
||||||
|
DetectedBodyType = BodyType.Bytes,
|
||||||
|
BodyAsBytes = new byte[] { 0 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = LogEntryMapper.Map(logEntry);
|
var result = LogEntryMapper.Map(logEntry);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(result.Request.DetectedBodyType).IsEqualTo("Bytes");
|
Check.That(result.Request.DetectedBodyType).IsEqualTo("Bytes");
|
||||||
Check.That(result.Request.DetectedBodyTypeFromContentType).IsEqualTo("None");
|
Check.That(result.Request.DetectedBodyTypeFromContentType).IsNull();
|
||||||
Check.That(result.Request.BodyAsBytes).ContainsExactly(new byte[] { 0 });
|
Check.That(result.Request.BodyAsBytes).ContainsExactly(new byte[] { 0 });
|
||||||
Check.That(result.Request.Body).IsNull();
|
Check.That(result.Request.Body).IsNull();
|
||||||
Check.That(result.Request.BodyAsJson).IsNull();
|
Check.That(result.Request.BodyAsJson).IsNull();
|
||||||
|
|
||||||
Check.That(result.Response.DetectedBodyType).IsEqualTo(BodyType.Bytes);
|
Check.That(result.Response.DetectedBodyType).IsEqualTo(BodyType.Bytes);
|
||||||
Check.That(result.Response.DetectedBodyTypeFromContentType).IsEqualTo(BodyType.None);
|
Check.That(result.Response.DetectedBodyTypeFromContentType).IsNull();
|
||||||
Check.That(result.Response.BodyAsBytes).ContainsExactly(new byte[] { 0 });
|
Check.That(result.Response.BodyAsBytes).ContainsExactly(new byte[] { 0 });
|
||||||
Check.That(result.Response.Body).IsNull();
|
Check.That(result.Response.Body).IsNull();
|
||||||
Check.That(result.Response.BodyAsJson).IsNull();
|
Check.That(result.Response.BodyAsJson).IsNull();
|
||||||
Check.That(result.Response.BodyAsFile).IsNull();
|
Check.That(result.Response.BodyAsFile).IsNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void LogEntryMapper_Map_LogEntry_Check_ResponseBodyTypeFile()
|
public void LogEntryMapper_Map_LogEntry_Check_ResponseBodyTypeFile()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var logEntry = new LogEntry
|
||||||
{
|
{
|
||||||
// Assign
|
RequestMessage = new RequestMessage(new UrlDetails("http://localhost"), "get", "::1"),
|
||||||
var logEntry = new LogEntry
|
ResponseMessage = new ResponseMessage
|
||||||
{
|
{
|
||||||
RequestMessage = new RequestMessage(new UrlDetails("http://localhost"), "get", "::1"),
|
BodyData = new BodyData
|
||||||
ResponseMessage = new ResponseMessage
|
|
||||||
{
|
{
|
||||||
BodyData = new BodyData
|
DetectedBodyType = BodyType.File,
|
||||||
{
|
BodyAsFile = "test"
|
||||||
DetectedBodyType = BodyType.File,
|
|
||||||
BodyAsFile = "test"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = LogEntryMapper.Map(logEntry);
|
var result = LogEntryMapper.Map(logEntry);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(result.Request.DetectedBodyType).IsNull();
|
Check.That(result.Request.DetectedBodyType).IsNull();
|
||||||
Check.That(result.Request.DetectedBodyTypeFromContentType).IsNull();
|
Check.That(result.Request.DetectedBodyTypeFromContentType).IsNull();
|
||||||
Check.That(result.Request.BodyAsBytes).IsNull();
|
Check.That(result.Request.BodyAsBytes).IsNull();
|
||||||
Check.That(result.Request.Body).IsNull();
|
Check.That(result.Request.Body).IsNull();
|
||||||
Check.That(result.Request.BodyAsJson).IsNull();
|
Check.That(result.Request.BodyAsJson).IsNull();
|
||||||
|
|
||||||
Check.That(result.Response.DetectedBodyType).IsEqualTo(BodyType.File);
|
Check.That(result.Response.DetectedBodyType).IsEqualTo(BodyType.File);
|
||||||
Check.That(result.Response.DetectedBodyTypeFromContentType).IsEqualTo(BodyType.None);
|
Check.That(result.Response.DetectedBodyTypeFromContentType).IsNull();
|
||||||
Check.That(result.Request.BodyAsBytes).IsNull();
|
Check.That(result.Request.BodyAsBytes).IsNull();
|
||||||
Check.That(result.Response.Body).IsNull();
|
Check.That(result.Response.Body).IsNull();
|
||||||
Check.That(result.Response.BodyAsJson).IsNull();
|
Check.That(result.Response.BodyAsJson).IsNull();
|
||||||
Check.That(result.Response.BodyAsFile).IsEqualTo("test");
|
Check.That(result.Response.BodyAsFile).IsEqualTo("test");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void LogEntryMapper_Map_LogEntry_WithFault()
|
public void LogEntryMapper_Map_LogEntry_WithFault()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var logEntry = new LogEntry
|
||||||
{
|
{
|
||||||
// Assign
|
RequestMessage = new RequestMessage(new UrlDetails("http://localhost"), "get", "::1"),
|
||||||
var logEntry = new LogEntry
|
ResponseMessage = new ResponseMessage
|
||||||
{
|
{
|
||||||
RequestMessage = new RequestMessage(new UrlDetails("http://localhost"), "get", "::1"),
|
BodyData = new BodyData
|
||||||
ResponseMessage = new ResponseMessage
|
|
||||||
{
|
{
|
||||||
BodyData = new BodyData
|
DetectedBodyType = BodyType.File,
|
||||||
{
|
BodyAsFile = "test"
|
||||||
DetectedBodyType = BodyType.File,
|
},
|
||||||
BodyAsFile = "test"
|
FaultType = FaultType.EMPTY_RESPONSE,
|
||||||
},
|
FaultPercentage = 0.5
|
||||||
FaultType = FaultType.EMPTY_RESPONSE,
|
}
|
||||||
FaultPercentage = 0.5
|
};
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = LogEntryMapper.Map(logEntry);
|
var result = LogEntryMapper.Map(logEntry);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Response.FaultType.Should().Be("EMPTY_RESPONSE");
|
result.Response.FaultType.Should().Be("EMPTY_RESPONSE");
|
||||||
result.Response.FaultPercentage.Should().Be(0.5);
|
result.Response.FaultPercentage.Should().Be(0.5);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -52,7 +52,7 @@ namespace WireMock.Net.Tests.Serialization
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var mapping = new Mapping(Guid.NewGuid(), "", null, _settings, request, response, 0, null, null, null, null, webhooks, null);
|
var mapping = new Mapping(Guid.NewGuid(), string.Empty, string.Empty, null, _settings, request, response, 0, null, null, null, null, webhooks, null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var model = _sut.ToMappingModel(mapping);
|
var model = _sut.ToMappingModel(mapping);
|
||||||
@@ -121,7 +121,7 @@ namespace WireMock.Net.Tests.Serialization
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var mapping = new Mapping(Guid.NewGuid(), "", null, _settings, request, response, 0, null, null, null, null, webhooks, null);
|
var mapping = new Mapping(Guid.NewGuid(), string.Empty, string.Empty, null, _settings, request, response, 0, null, null, null, null, webhooks, null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var model = _sut.ToMappingModel(mapping);
|
var model = _sut.ToMappingModel(mapping);
|
||||||
@@ -147,13 +147,32 @@ namespace WireMock.Net.Tests.Serialization
|
|||||||
model.Webhooks[1].Request.Body.Should().Be("2");
|
model.Webhooks[1].Request.Body.Should().Be("2");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ToMappingModel_WithTitle_And_Description_ReturnsCorrectModel()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var title = "my-title";
|
||||||
|
var description = "my-description";
|
||||||
|
var request = Request.Create();
|
||||||
|
var response = Response.Create();
|
||||||
|
var mapping = new Mapping(Guid.NewGuid(), title, description, null, _settings, request, response, 0, null, null, null, null, null, null);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var model = _sut.ToMappingModel(mapping);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
model.Should().NotBeNull();
|
||||||
|
model.Title.Should().Be(title);
|
||||||
|
model.Description.Should().Be(description);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToMappingModel_WithPriority_ReturnsPriority()
|
public void ToMappingModel_WithPriority_ReturnsPriority()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var request = Request.Create();
|
var request = Request.Create();
|
||||||
var response = Response.Create().WithBodyAsJson(new { x = "x" }).WithTransformer();
|
var response = Response.Create().WithBodyAsJson(new { x = "x" }).WithTransformer();
|
||||||
var mapping = new Mapping(Guid.NewGuid(), "", null, _settings, request, response, 42, null, null, null, null, null, null);
|
var mapping = new Mapping(Guid.NewGuid(), string.Empty, string.Empty, null, _settings, request, response, 42, null, null, null, null, null, null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var model = _sut.ToMappingModel(mapping);
|
var model = _sut.ToMappingModel(mapping);
|
||||||
@@ -179,7 +198,7 @@ namespace WireMock.Net.Tests.Serialization
|
|||||||
End = end,
|
End = end,
|
||||||
TTL = ttl
|
TTL = ttl
|
||||||
};
|
};
|
||||||
var mapping = new Mapping(Guid.NewGuid(), "", null, _settings, request, response, 42, null, null, null, null, null, timeSettings);
|
var mapping = new Mapping(Guid.NewGuid(), string.Empty, string.Empty, null, _settings, request, response, 42, null, null, null, null, null, timeSettings);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var model = _sut.ToMappingModel(mapping);
|
var model = _sut.ToMappingModel(mapping);
|
||||||
@@ -207,7 +226,7 @@ namespace WireMock.Net.Tests.Serialization
|
|||||||
{
|
{
|
||||||
var request = Request.Create();
|
var request = Request.Create();
|
||||||
var response = Response.Create().WithDelay(test.Delay);
|
var response = Response.Create().WithDelay(test.Delay);
|
||||||
var mapping = new Mapping(Guid.NewGuid(), "", null, _settings, request, response, 42, null, null, null, null, null, null);
|
var mapping = new Mapping(Guid.NewGuid(), string.Empty, string.Empty, string.Empty, _settings, request, response, 42, null, null, null, null, null, null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var model = _sut.ToMappingModel(mapping);
|
var model = _sut.ToMappingModel(mapping);
|
||||||
@@ -225,7 +244,7 @@ namespace WireMock.Net.Tests.Serialization
|
|||||||
var delay = 1000;
|
var delay = 1000;
|
||||||
var request = Request.Create();
|
var request = Request.Create();
|
||||||
var response = Response.Create().WithDelay(delay);
|
var response = Response.Create().WithDelay(delay);
|
||||||
var mapping = new Mapping(Guid.NewGuid(), "", null, _settings, request, response, 42, null, null, null, null, null, null);
|
var mapping = new Mapping(Guid.NewGuid(), string.Empty, string.Empty, null, _settings, request, response, 42, null, null, null, null, null, null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var model = _sut.ToMappingModel(mapping);
|
var model = _sut.ToMappingModel(mapping);
|
||||||
@@ -242,7 +261,7 @@ namespace WireMock.Net.Tests.Serialization
|
|||||||
int minimumDelay = 1000;
|
int minimumDelay = 1000;
|
||||||
var request = Request.Create();
|
var request = Request.Create();
|
||||||
var response = Response.Create().WithRandomDelay(minimumDelay);
|
var response = Response.Create().WithRandomDelay(minimumDelay);
|
||||||
var mapping = new Mapping(Guid.NewGuid(), "", null, _settings, request, response, 42, null, null, null, null, null, null);
|
var mapping = new Mapping(Guid.NewGuid(), string.Empty, string.Empty, null, _settings, request, response, 42, null, null, null, null, null, null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var model = _sut.ToMappingModel(mapping);
|
var model = _sut.ToMappingModel(mapping);
|
||||||
@@ -262,7 +281,7 @@ namespace WireMock.Net.Tests.Serialization
|
|||||||
int maximumDelay = 2000;
|
int maximumDelay = 2000;
|
||||||
var request = Request.Create();
|
var request = Request.Create();
|
||||||
var response = Response.Create().WithRandomDelay(minimumDelay, maximumDelay);
|
var response = Response.Create().WithRandomDelay(minimumDelay, maximumDelay);
|
||||||
var mapping = new Mapping(Guid.NewGuid(), "", null, _settings, request, response, 42, null, null, null, null, null, null);
|
var mapping = new Mapping(Guid.NewGuid(), string.Empty, string.Empty, null, _settings, request, response, 42, null, null, null, null, null, null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var model = _sut.ToMappingModel(mapping);
|
var model = _sut.ToMappingModel(mapping);
|
||||||
|
|||||||
@@ -113,4 +113,8 @@
|
|||||||
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
|
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Pact\files\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
Reference in New Issue
Block a user