mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-24 09:18:27 +02:00
Refactor: extract interfaces (#484)
* . * MatchDetail * rm * resp * log * f
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
using System.Threading;
|
using System;
|
||||||
|
using System.Threading;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using WireMock.Admin.Requests;
|
||||||
using WireMock.Logging;
|
using WireMock.Logging;
|
||||||
using WireMock.Models.Requests;
|
|
||||||
using WireMock.Server;
|
using WireMock.Server;
|
||||||
using WireMock.Settings;
|
using WireMock.Settings;
|
||||||
|
|
||||||
@@ -49,6 +50,11 @@ namespace WireMock.Net.WebApplication
|
|||||||
string message = JsonConvert.SerializeObject(logEntryModel, Formatting.Indented);
|
string message = JsonConvert.SerializeObject(logEntryModel, Formatting.Indented);
|
||||||
_logger.LogDebug("Admin[{0}] {1}", isAdminrequest, message);
|
_logger.LogDebug("Admin[{0}] {1}", isAdminrequest, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Error(string formatString, Exception exception)
|
||||||
|
{
|
||||||
|
_logger.LogError(formatString, exception.Message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public WireMockService(ILogger logger, WireMockServerSettings settings)
|
public WireMockService(ILogger logger, WireMockServerSettings settings)
|
||||||
|
|||||||
140
src/WireMock.Net.Abstractions/IRequestMessage.cs
Normal file
140
src/WireMock.Net.Abstractions/IRequestMessage.cs
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using WireMock.Types;
|
||||||
|
using WireMock.Util;
|
||||||
|
|
||||||
|
namespace WireMock
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// IRequestMessage
|
||||||
|
/// </summary>
|
||||||
|
public interface IRequestMessage
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the Client IP Address.
|
||||||
|
/// </summary>
|
||||||
|
string ClientIP { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the url (relative).
|
||||||
|
/// </summary>
|
||||||
|
string Url { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the AbsoluteUrl.
|
||||||
|
/// </summary>
|
||||||
|
string AbsoluteUrl { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The ProxyUrl (if a proxy is used).
|
||||||
|
/// </summary>
|
||||||
|
string ProxyUrl { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the DateTime.
|
||||||
|
/// </summary>
|
||||||
|
DateTime DateTime { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the path (relative).
|
||||||
|
/// </summary>
|
||||||
|
string Path { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the AbsolutePath.
|
||||||
|
/// </summary>
|
||||||
|
string AbsolutePath { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the path segments.
|
||||||
|
/// </summary>
|
||||||
|
string[] PathSegments { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the absolute path segments.
|
||||||
|
/// </summary>
|
||||||
|
string[] AbsolutePathSegments { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the method.
|
||||||
|
/// </summary>
|
||||||
|
string Method { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the headers.
|
||||||
|
/// </summary>
|
||||||
|
IDictionary<string, WireMockList<string>> Headers { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the cookies.
|
||||||
|
/// </summary>
|
||||||
|
IDictionary<string, string> Cookies { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the query.
|
||||||
|
/// </summary>
|
||||||
|
IDictionary<string, WireMockList<string>> Query { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the raw query.
|
||||||
|
/// </summary>
|
||||||
|
string RawQuery { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The body.
|
||||||
|
/// </summary>
|
||||||
|
IBodyData BodyData { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The original body as string. Convenience getter for Handlebars.
|
||||||
|
/// </summary>
|
||||||
|
string Body { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The body (as JSON object). Convenience getter for Handlebars.
|
||||||
|
/// </summary>
|
||||||
|
object BodyAsJson { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The body (as bytearray). Convenience getter for Handlebars.
|
||||||
|
/// </summary>
|
||||||
|
byte[] BodyAsBytes { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The detected body type. Convenience getter for Handlebars.
|
||||||
|
/// </summary>
|
||||||
|
string DetectedBodyType { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The detected body type from the Content-Type header. Convenience getter for Handlebars.
|
||||||
|
/// </summary>
|
||||||
|
string DetectedBodyTypeFromContentType { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The detected compression from the Content-Encoding header. Convenience getter for Handlebars.
|
||||||
|
/// </summary>
|
||||||
|
string DetectedCompression { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the Host
|
||||||
|
/// </summary>
|
||||||
|
string Host { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the protocol
|
||||||
|
/// </summary>
|
||||||
|
string Protocol { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the port
|
||||||
|
/// </summary>
|
||||||
|
int Port { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the origin
|
||||||
|
/// </summary>
|
||||||
|
string Origin { get; }
|
||||||
|
|
||||||
|
// WireMockList<string> GetParameter(string key, bool ignoreCase = false);
|
||||||
|
}
|
||||||
|
}
|
||||||
51
src/WireMock.Net.Abstractions/IResponseMessage.cs
Normal file
51
src/WireMock.Net.Abstractions/IResponseMessage.cs
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using WireMock.ResponseBuilders;
|
||||||
|
using WireMock.Types;
|
||||||
|
using WireMock.Util;
|
||||||
|
|
||||||
|
namespace WireMock
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// IResponseMessage
|
||||||
|
/// </summary>
|
||||||
|
public interface IResponseMessage
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The Body.
|
||||||
|
/// </summary>
|
||||||
|
IBodyData BodyData { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the body destination (SameAsSource, String or Bytes).
|
||||||
|
/// </summary>
|
||||||
|
string BodyDestination { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the body.
|
||||||
|
/// </summary>
|
||||||
|
string BodyOriginal { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the Fault percentage.
|
||||||
|
/// </summary>
|
||||||
|
double? FaultPercentage { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The FaultType.
|
||||||
|
/// </summary>
|
||||||
|
FaultType FaultType { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the headers.
|
||||||
|
/// </summary>
|
||||||
|
IDictionary<string, WireMockList<string>> Headers { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the status code.
|
||||||
|
/// </summary>
|
||||||
|
object StatusCode { get; }
|
||||||
|
|
||||||
|
//void AddHeader(string name, params string[] values);
|
||||||
|
//void AddHeader(string name, string value);
|
||||||
|
}
|
||||||
|
}
|
||||||
80
src/WireMock.Net.Abstractions/Logging/ILogEntry.cs
Normal file
80
src/WireMock.Net.Abstractions/Logging/ILogEntry.cs
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
using System;
|
||||||
|
using WireMock.Matchers.Request;
|
||||||
|
|
||||||
|
namespace WireMock.Logging
|
||||||
|
{
|
||||||
|
public interface ILogEntry
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the unique identifier.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>
|
||||||
|
/// The unique identifier.
|
||||||
|
/// </value>
|
||||||
|
Guid Guid { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the mapping unique identifier.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>
|
||||||
|
/// The mapping unique identifier.
|
||||||
|
/// </value>
|
||||||
|
Guid? MappingGuid { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the mapping unique title.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>
|
||||||
|
/// The mapping unique title.
|
||||||
|
/// </value>
|
||||||
|
string MappingTitle { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the partial mapping unique identifier.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>
|
||||||
|
/// The mapping unique identifier.
|
||||||
|
/// </value>
|
||||||
|
Guid? PartialMappingGuid { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the partial mapping unique title.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>
|
||||||
|
/// The mapping unique title.
|
||||||
|
/// </value>
|
||||||
|
string PartialMappingTitle { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the partial match result.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>
|
||||||
|
/// The request match result.
|
||||||
|
/// </value>
|
||||||
|
IRequestMatchResult PartialMatchResult { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the request match result.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>
|
||||||
|
/// The request match result.
|
||||||
|
/// </value>
|
||||||
|
IRequestMatchResult RequestMatchResult { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the request message.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>
|
||||||
|
/// The request message.
|
||||||
|
/// </value>
|
||||||
|
IRequestMessage RequestMessage { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the response message.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>
|
||||||
|
/// The response message.
|
||||||
|
/// </value>
|
||||||
|
IResponseMessage ResponseMessage { get; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace WireMock.Matchers.Request
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// IRequestMatchResult
|
||||||
|
/// </summary>
|
||||||
|
public interface IRequestMatchResult : IComparable
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the match percentage.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>
|
||||||
|
/// The match percentage.
|
||||||
|
/// </value>
|
||||||
|
double AverageTotalScore { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value indicating whether this instance is perfect match.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>
|
||||||
|
/// <c>true</c> if this instance is perfect match; otherwise, <c>false</c>.
|
||||||
|
/// </value>
|
||||||
|
bool IsPerfectMatch { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the match details.
|
||||||
|
/// </summary>
|
||||||
|
IList<MatchDetail> MatchDetails { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the total number of matches.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>
|
||||||
|
/// The total number of matches.
|
||||||
|
/// </value>
|
||||||
|
int TotalNumber { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the match-score.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>
|
||||||
|
/// The match-score.
|
||||||
|
/// </value>
|
||||||
|
double TotalScore { get; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using WireMock.Admin.Mappings;
|
using WireMock.Admin.Mappings;
|
||||||
|
using WireMock.Logging;
|
||||||
|
|
||||||
namespace WireMock.Server
|
namespace WireMock.Server
|
||||||
{
|
{
|
||||||
@@ -16,13 +17,20 @@ namespace WireMock.Server
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
bool IsStarted { get; }
|
bool IsStarted { get; }
|
||||||
|
|
||||||
//IEnumerable<LogEntry> LogEntries { get; }
|
/// <summary>
|
||||||
|
/// Gets the request logs.
|
||||||
|
/// </summary>
|
||||||
|
IEnumerable<ILogEntry> LogEntries { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the mappings as MappingModels.
|
/// Gets the mappings as MappingModels.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
IEnumerable<MappingModel> MappingModels { get; }
|
IEnumerable<MappingModel> MappingModels { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the mappings.
|
||||||
|
/// </summary>
|
||||||
|
//[PublicAPI]
|
||||||
//IEnumerable<IMapping> Mappings { get; }
|
//IEnumerable<IMapping> Mappings { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
61
src/WireMock.Net.Abstractions/Util/IBodyData.cs
Normal file
61
src/WireMock.Net.Abstractions/Util/IBodyData.cs
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
using System.Text;
|
||||||
|
using WireMock.Types;
|
||||||
|
|
||||||
|
namespace WireMock.Util
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// IBodyData
|
||||||
|
/// </summary>
|
||||||
|
public interface IBodyData
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The body (as bytearray).
|
||||||
|
/// </summary>
|
||||||
|
byte[] BodyAsBytes { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the body as a file.
|
||||||
|
/// </summary>
|
||||||
|
string BodyAsFile { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Is the body as file cached?
|
||||||
|
/// </summary>
|
||||||
|
bool? BodyAsFileIsCached { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The body (as JSON object).
|
||||||
|
/// </summary>
|
||||||
|
object BodyAsJson { get; set; }
|
||||||
|
|
||||||
|
/// <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.
|
||||||
|
/// </summary>
|
||||||
|
bool? BodyAsJsonIndented { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The body as string, this is defined when BodyAsString or BodyAsJson are not null.
|
||||||
|
/// </summary>
|
||||||
|
string BodyAsString { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The detected body type (detection based on body content).
|
||||||
|
/// </summary>
|
||||||
|
BodyType DetectedBodyType { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The detected body type (detection based on Content-Type).
|
||||||
|
/// </summary>
|
||||||
|
BodyType DetectedBodyTypeFromContentType { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The detected compression.
|
||||||
|
/// </summary>
|
||||||
|
string DetectedCompression { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The body encoding.
|
||||||
|
/// </summary>
|
||||||
|
Encoding Encoding { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,10 +5,10 @@ namespace WireMock.FluentAssertions
|
|||||||
{
|
{
|
||||||
public class WireMockANumberOfCallsAssertions
|
public class WireMockANumberOfCallsAssertions
|
||||||
{
|
{
|
||||||
private readonly WireMockServer _server;
|
private readonly IWireMockServer _server;
|
||||||
private readonly int _callsCount;
|
private readonly int _callsCount;
|
||||||
|
|
||||||
public WireMockANumberOfCallsAssertions(WireMockServer server, int callsCount)
|
public WireMockANumberOfCallsAssertions(IWireMockServer server, int callsCount)
|
||||||
{
|
{
|
||||||
_server = server;
|
_server = server;
|
||||||
_callsCount = callsCount;
|
_callsCount = callsCount;
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ namespace WireMock.FluentAssertions
|
|||||||
{
|
{
|
||||||
public class WireMockAssertions
|
public class WireMockAssertions
|
||||||
{
|
{
|
||||||
private readonly WireMockServer _instance;
|
private readonly IWireMockServer _instance;
|
||||||
|
|
||||||
public WireMockAssertions(WireMockServer instance, int? callsCount)
|
public WireMockAssertions(IWireMockServer instance, int? callsCount)
|
||||||
{
|
{
|
||||||
_instance = instance;
|
_instance = instance;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ using WireMock.Server;
|
|||||||
// ReSharper disable once CheckNamespace
|
// ReSharper disable once CheckNamespace
|
||||||
namespace WireMock.FluentAssertions
|
namespace WireMock.FluentAssertions
|
||||||
{
|
{
|
||||||
public class WireMockReceivedAssertions : ReferenceTypeAssertions<WireMockServer, WireMockReceivedAssertions>
|
public class WireMockReceivedAssertions : ReferenceTypeAssertions<IWireMockServer, WireMockReceivedAssertions>
|
||||||
{
|
{
|
||||||
public WireMockReceivedAssertions(WireMockServer server)
|
public WireMockReceivedAssertions(IWireMockServer server)
|
||||||
{
|
{
|
||||||
Subject = server;
|
Subject = server;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ namespace WireMock.FluentAssertions
|
|||||||
{
|
{
|
||||||
public static class WireMockExtensions
|
public static class WireMockExtensions
|
||||||
{
|
{
|
||||||
public static WireMockReceivedAssertions Should(this WireMockServer instance)
|
public static WireMockReceivedAssertions Should(this IWireMockServer instance)
|
||||||
{
|
{
|
||||||
return new WireMockReceivedAssertions(instance);
|
return new WireMockReceivedAssertions(instance);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\WireMock.Net\WireMock.Net.csproj" />
|
<ProjectReference Include="..\WireMock.Net.Abstractions\WireMock.Net.Abstractions.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ namespace WireMock
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <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="RequestMatchResult"/>.</returns>
|
/// <returns>The <see cref="IRequestMatchResult"/>.</returns>
|
||||||
RequestMatchResult GetRequestMatchResult(RequestMessage requestMessage, [CanBeNull] string nextState);
|
RequestMatchResult GetRequestMatchResult(RequestMessage requestMessage, [CanBeNull] string nextState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,78 +6,33 @@ namespace WireMock.Logging
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// LogEntry
|
/// LogEntry
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class LogEntry
|
public class LogEntry : ILogEntry
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <inheritdoc cref="ILogEntry.Guid" />
|
||||||
/// Gets or sets the unique identifier.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>
|
|
||||||
/// The unique identifier.
|
|
||||||
/// </value>
|
|
||||||
public Guid Guid { get; set; }
|
public Guid Guid { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="ILogEntry.RequestMessage" />
|
||||||
/// Gets or sets the request message.
|
public IRequestMessage RequestMessage { get; set; }
|
||||||
/// </summary>
|
|
||||||
/// <value>
|
|
||||||
/// The request message.
|
|
||||||
/// </value>
|
|
||||||
public RequestMessage RequestMessage { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="ILogEntry.ResponseMessage" />
|
||||||
/// Gets or sets the response message.
|
public IResponseMessage ResponseMessage { get; set; }
|
||||||
/// </summary>
|
|
||||||
/// <value>
|
|
||||||
/// The response message.
|
|
||||||
/// </value>
|
|
||||||
public ResponseMessage ResponseMessage { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="ILogEntry.RequestMatchResult" />
|
||||||
/// Gets or sets the request match result.
|
public IRequestMatchResult RequestMatchResult { get; set; }
|
||||||
/// </summary>
|
|
||||||
/// <value>
|
|
||||||
/// The request match result.
|
|
||||||
/// </value>
|
|
||||||
public RequestMatchResult RequestMatchResult { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="ILogEntry.MappingGuid" />
|
||||||
/// Gets or sets the mapping unique identifier.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>
|
|
||||||
/// The mapping unique identifier.
|
|
||||||
/// </value>
|
|
||||||
public Guid? MappingGuid { get; set; }
|
public Guid? MappingGuid { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="ILogEntry.MappingTitle" />
|
||||||
/// Gets or sets the mapping unique title.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>
|
|
||||||
/// The mapping unique title.
|
|
||||||
/// </value>
|
|
||||||
public string MappingTitle { get; set; }
|
public string MappingTitle { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="ILogEntry.PartialMappingGuid" />
|
||||||
/// Gets or sets the partial mapping unique identifier.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>
|
|
||||||
/// The mapping unique identifier.
|
|
||||||
/// </value>
|
|
||||||
public Guid? PartialMappingGuid { get; set; }
|
public Guid? PartialMappingGuid { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="ILogEntry.PartialMappingTitle" />
|
||||||
/// Gets or sets the partial mapping unique title.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>
|
|
||||||
/// The mapping unique title.
|
|
||||||
/// </value>
|
|
||||||
public string PartialMappingTitle { get; set; }
|
public string PartialMappingTitle { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="ILogEntry.PartialMatchResult" />
|
||||||
/// Gets or sets the partial match result.
|
public IRequestMatchResult PartialMatchResult { get; set; }
|
||||||
/// </summary>
|
|
||||||
/// <value>
|
|
||||||
/// The request match result.
|
|
||||||
/// </value>
|
|
||||||
public RequestMatchResult PartialMatchResult { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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] RequestMessage requestMessage, [NotNull] RequestMatchResult requestMatchResult);
|
double GetMatchingScore([NotNull] IRequestMessage requestMessage, [NotNull] RequestMatchResult requestMatchResult);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,43 +7,21 @@ namespace WireMock.Matchers.Request
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// RequestMatchResult
|
/// RequestMatchResult
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class RequestMatchResult : IComparable
|
public class RequestMatchResult : IRequestMatchResult
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <inheritdoc cref="IRequestMatchResult.TotalScore" />
|
||||||
/// Gets or sets the match-score.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>
|
|
||||||
/// The match-score.
|
|
||||||
/// </value>
|
|
||||||
public double TotalScore => MatchDetails.Sum(md => md.Score);
|
public double TotalScore => MatchDetails.Sum(md => md.Score);
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IRequestMatchResult.TotalNumber" />
|
||||||
/// Gets or sets the total number of matches.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>
|
|
||||||
/// The total number of matches.
|
|
||||||
/// </value>
|
|
||||||
public int TotalNumber => MatchDetails.Count;
|
public int TotalNumber => MatchDetails.Count;
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IRequestMatchResult.IsPerfectMatch" />
|
||||||
/// Gets or sets a value indicating whether this instance is perfect match.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>
|
|
||||||
/// <c>true</c> if this instance is perfect match; otherwise, <c>false</c>.
|
|
||||||
/// </value>
|
|
||||||
public bool IsPerfectMatch => Math.Abs(TotalScore - TotalNumber) < MatchScores.Tolerance;
|
public bool IsPerfectMatch => Math.Abs(TotalScore - TotalNumber) < MatchScores.Tolerance;
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IRequestMatchResult.AverageTotalScore" />
|
||||||
/// Gets the match percentage.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>
|
|
||||||
/// The match percentage.
|
|
||||||
/// </value>
|
|
||||||
public double AverageTotalScore => TotalNumber == 0 ? 0.0 : TotalScore / TotalNumber;
|
public double AverageTotalScore => TotalNumber == 0 ? 0.0 : TotalScore / TotalNumber;
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IRequestMatchResult.MatchDetails" />
|
||||||
/// Gets the match details.
|
|
||||||
/// </summary>
|
|
||||||
public IList<MatchDetail> MatchDetails { get; } = new List<MatchDetail>();
|
public IList<MatchDetail> MatchDetails { get; } = new List<MatchDetail>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -99,13 +99,13 @@ namespace WireMock.Matchers.Request
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <see cref="IRequestMatcher.GetMatchingScore"/>
|
/// <see cref="IRequestMatcher.GetMatchingScore"/>
|
||||||
public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
public double GetMatchingScore(IRequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
||||||
{
|
{
|
||||||
double score = CalculateMatchScore(requestMessage);
|
double score = CalculateMatchScore(requestMessage);
|
||||||
return requestMatchResult.AddScore(GetType(), score);
|
return requestMatchResult.AddScore(GetType(), score);
|
||||||
}
|
}
|
||||||
|
|
||||||
private double CalculateMatchScore(RequestMessage requestMessage, IMatcher matcher)
|
private double CalculateMatchScore(IRequestMessage requestMessage, IMatcher matcher)
|
||||||
{
|
{
|
||||||
// Check if the matcher is a IObjectMatcher
|
// Check if the matcher is a IObjectMatcher
|
||||||
if (matcher is IObjectMatcher objectMatcher)
|
if (matcher is IObjectMatcher objectMatcher)
|
||||||
@@ -136,7 +136,7 @@ namespace WireMock.Matchers.Request
|
|||||||
return MatchScores.Mismatch;
|
return MatchScores.Mismatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
private double CalculateMatchScore(RequestMessage requestMessage)
|
private double CalculateMatchScore(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
if (Matchers != null && Matchers.Any())
|
if (Matchers != null && Matchers.Any())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -51,13 +51,13 @@ namespace WireMock.Matchers.Request
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
||||||
public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
public double GetMatchingScore(IRequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
||||||
{
|
{
|
||||||
double score = IsMatch(requestMessage);
|
double score = IsMatch(requestMessage);
|
||||||
return requestMatchResult.AddScore(GetType(), score);
|
return requestMatchResult.AddScore(GetType(), score);
|
||||||
}
|
}
|
||||||
|
|
||||||
private double IsMatch(RequestMessage requestMessage)
|
private double IsMatch(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
if (Matchers != null)
|
if (Matchers != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace WireMock.Matchers.Request
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
||||||
public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
public double GetMatchingScore(IRequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
||||||
{
|
{
|
||||||
if (!RequestMatchers.Any())
|
if (!RequestMatchers.Any())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -91,13 +91,13 @@ namespace WireMock.Matchers.Request
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
||||||
public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
public double GetMatchingScore(IRequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
||||||
{
|
{
|
||||||
double score = IsMatch(requestMessage);
|
double score = IsMatch(requestMessage);
|
||||||
return requestMatchResult.AddScore(GetType(), score);
|
return requestMatchResult.AddScore(GetType(), score);
|
||||||
}
|
}
|
||||||
|
|
||||||
private double IsMatch(RequestMessage requestMessage)
|
private double IsMatch(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
if (requestMessage.Cookies == null)
|
if (requestMessage.Cookies == null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -92,13 +92,13 @@ namespace WireMock.Matchers.Request
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
||||||
public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
public double GetMatchingScore(IRequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
||||||
{
|
{
|
||||||
double score = IsMatch(requestMessage);
|
double score = IsMatch(requestMessage);
|
||||||
return requestMatchResult.AddScore(GetType(), score);
|
return requestMatchResult.AddScore(GetType(), score);
|
||||||
}
|
}
|
||||||
|
|
||||||
private double IsMatch(RequestMessage requestMessage)
|
private double IsMatch(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
if (requestMessage.Headers == null)
|
if (requestMessage.Headers == null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -31,13 +31,13 @@ namespace WireMock.Matchers.Request
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
||||||
public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
public double GetMatchingScore(IRequestMessage requestMessage, RequestMatchResult 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
private double IsMatch(RequestMessage requestMessage)
|
private double IsMatch(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
return MatchScores.ToScore(Methods.Contains(requestMessage.Method, StringComparer.OrdinalIgnoreCase));
|
return MatchScores.ToScore(Methods.Contains(requestMessage.Method, StringComparer.OrdinalIgnoreCase));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,20 +84,20 @@ namespace WireMock.Matchers.Request
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
||||||
public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
public double GetMatchingScore(IRequestMessage requestMessage, RequestMatchResult 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
private double IsMatch(RequestMessage requestMessage)
|
private double IsMatch(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
if (Funcs != null)
|
if (Funcs != null)
|
||||||
{
|
{
|
||||||
return MatchScores.ToScore(requestMessage.Query != null && Funcs.Any(f => f(requestMessage.Query)));
|
return MatchScores.ToScore(requestMessage.Query != null && Funcs.Any(f => f(requestMessage.Query)));
|
||||||
}
|
}
|
||||||
|
|
||||||
WireMockList<string> valuesPresentInRequestMessage = requestMessage.GetParameter(Key, IgnoreCase ?? false);
|
WireMockList<string> valuesPresentInRequestMessage = ((RequestMessage) requestMessage).GetParameter(Key, IgnoreCase ?? false);
|
||||||
if (valuesPresentInRequestMessage == null)
|
if (valuesPresentInRequestMessage == null)
|
||||||
{
|
{
|
||||||
// Key is not present at all, just return Mismatch
|
// Key is not present at all, just return Mismatch
|
||||||
|
|||||||
@@ -53,13 +53,13 @@ namespace WireMock.Matchers.Request
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
||||||
public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
public double GetMatchingScore(IRequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
||||||
{
|
{
|
||||||
double score = IsMatch(requestMessage);
|
double score = IsMatch(requestMessage);
|
||||||
return requestMatchResult.AddScore(GetType(), score);
|
return requestMatchResult.AddScore(GetType(), score);
|
||||||
}
|
}
|
||||||
|
|
||||||
private double IsMatch(RequestMessage requestMessage)
|
private double IsMatch(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
if (Matchers != null)
|
if (Matchers != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ namespace WireMock.Matchers.Request
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
public double GetMatchingScore(IRequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
||||||
{
|
{
|
||||||
double score = IsMatch();
|
double score = IsMatch();
|
||||||
return requestMatchResult.AddScore(GetType(), score);
|
return requestMatchResult.AddScore(GetType(), score);
|
||||||
|
|||||||
@@ -51,13 +51,13 @@ namespace WireMock.Matchers.Request
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
||||||
public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
public double GetMatchingScore(IRequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
||||||
{
|
{
|
||||||
double score = IsMatch(requestMessage);
|
double score = IsMatch(requestMessage);
|
||||||
return requestMatchResult.AddScore(GetType(), score);
|
return requestMatchResult.AddScore(GetType(), score);
|
||||||
}
|
}
|
||||||
|
|
||||||
private double IsMatch(RequestMessage requestMessage)
|
private double IsMatch(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
if (Matchers != null)
|
if (Matchers != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,131 +15,81 @@ namespace WireMock
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The RequestMessage.
|
/// The RequestMessage.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class RequestMessage
|
public class RequestMessage : IRequestMessage
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <inheritdoc cref="IRequestMessage.ClientIP" />
|
||||||
/// Gets the Client IP Address.
|
|
||||||
/// </summary>
|
|
||||||
public string ClientIP { get; }
|
public string ClientIP { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IRequestMessage.Url" />
|
||||||
/// Gets the url (relative).
|
|
||||||
/// </summary>
|
|
||||||
public string Url { get; }
|
public string Url { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IRequestMessage.AbsoluteUrl" />
|
||||||
/// Gets the AbsoluteUrl.
|
|
||||||
/// </summary>
|
|
||||||
public string AbsoluteUrl { get; }
|
public string AbsoluteUrl { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IRequestMessage.ProxyUrl" />
|
||||||
/// The ProxyUrl (if a proxy is used).
|
|
||||||
/// </summary>
|
|
||||||
public string ProxyUrl { get; set; }
|
public string ProxyUrl { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IRequestMessage.DateTime" />
|
||||||
/// Gets the DateTime.
|
|
||||||
/// </summary>
|
|
||||||
public DateTime DateTime { get; set; }
|
public DateTime DateTime { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IRequestMessage.Path" />
|
||||||
/// Gets the path (relative).
|
|
||||||
/// </summary>
|
|
||||||
public string Path { get; }
|
public string Path { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IRequestMessage.AbsolutePath" />
|
||||||
/// Gets the AbsolutePath.
|
|
||||||
/// </summary>
|
|
||||||
public string AbsolutePath { get; }
|
public string AbsolutePath { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IRequestMessage.PathSegments" />
|
||||||
/// Gets the path segments.
|
|
||||||
/// </summary>
|
|
||||||
public string[] PathSegments { get; }
|
public string[] PathSegments { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IRequestMessage.AbsolutePathSegments" />
|
||||||
/// Gets the absolute path segments.
|
|
||||||
/// </summary>
|
|
||||||
public string[] AbsolutePathSegments { get; }
|
public string[] AbsolutePathSegments { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IRequestMessage.Method" />
|
||||||
/// Gets the method.
|
|
||||||
/// </summary>
|
|
||||||
public string Method { get; }
|
public string Method { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IRequestMessage.Headers" />
|
||||||
/// Gets the headers.
|
|
||||||
/// </summary>
|
|
||||||
public IDictionary<string, WireMockList<string>> Headers { get; }
|
public IDictionary<string, WireMockList<string>> Headers { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IRequestMessage.Cookies" />
|
||||||
/// Gets the cookies.
|
|
||||||
/// </summary>
|
|
||||||
public IDictionary<string, string> Cookies { get; }
|
public IDictionary<string, string> Cookies { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IRequestMessage.Query" />
|
||||||
/// Gets the query.
|
|
||||||
/// </summary>
|
|
||||||
public IDictionary<string, WireMockList<string>> Query { get; }
|
public IDictionary<string, WireMockList<string>> Query { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IRequestMessage.RawQuery" />
|
||||||
/// Gets the raw query.
|
|
||||||
/// </summary>
|
|
||||||
public string RawQuery { get; }
|
public string RawQuery { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IRequestMessage.BodyData" />
|
||||||
/// The body.
|
public IBodyData BodyData { get; }
|
||||||
/// </summary>
|
|
||||||
public BodyData BodyData { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IRequestMessage.Body" />
|
||||||
/// The original body as string. Convenience getter for Handlebars.
|
|
||||||
/// </summary>
|
|
||||||
public string Body { get; }
|
public string Body { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IRequestMessage.BodyAsJson" />
|
||||||
/// The body (as JSON object). Convenience getter for Handlebars.
|
|
||||||
/// </summary>
|
|
||||||
public object BodyAsJson { get; }
|
public object BodyAsJson { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IRequestMessage.BodyAsBytes" />
|
||||||
/// The body (as bytearray). Convenience getter for Handlebars.
|
|
||||||
/// </summary>
|
|
||||||
public byte[] BodyAsBytes { get; }
|
public byte[] BodyAsBytes { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IRequestMessage.DetectedBodyType" />
|
||||||
/// The detected body type. Convenience getter for Handlebars.
|
|
||||||
/// </summary>
|
|
||||||
public string DetectedBodyType { get; }
|
public string DetectedBodyType { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IRequestMessage.DetectedBodyTypeFromContentType" />
|
||||||
/// The detected body type from the Content-Type header. Convenience getter for Handlebars.
|
|
||||||
/// </summary>
|
|
||||||
public string DetectedBodyTypeFromContentType { get; }
|
public string DetectedBodyTypeFromContentType { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IRequestMessage.DetectedCompression" />
|
||||||
/// The detected compression from the Content-Encoding header. Convenience getter for Handlebars.
|
|
||||||
/// </summary>
|
|
||||||
public string DetectedCompression { get; }
|
public string DetectedCompression { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IRequestMessage.Host" />
|
||||||
/// Gets the Host
|
|
||||||
/// </summary>
|
|
||||||
public string Host { get; }
|
public string Host { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IRequestMessage.Protocol" />
|
||||||
/// Gets the protocol
|
|
||||||
/// </summary>
|
|
||||||
public string Protocol { get; }
|
public string Protocol { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IRequestMessage.Port" />
|
||||||
/// Gets the port
|
|
||||||
/// </summary>
|
|
||||||
public int Port { get; }
|
public int Port { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IRequestMessage.Origin" />
|
||||||
/// Gets the origin
|
|
||||||
/// </summary>
|
|
||||||
public string Origin { get; }
|
public string Origin { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -12,41 +12,27 @@ namespace WireMock
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The ResponseMessage.
|
/// The ResponseMessage.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ResponseMessage
|
public class ResponseMessage : IResponseMessage
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <inheritdoc cref="IResponseMessage.Headers" />
|
||||||
/// Gets the headers.
|
|
||||||
/// </summary>
|
|
||||||
public IDictionary<string, WireMockList<string>> Headers { get; set; } = new Dictionary<string, WireMockList<string>>();
|
public IDictionary<string, WireMockList<string>> Headers { get; set; } = new Dictionary<string, WireMockList<string>>();
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IResponseMessage.StatusCode" />
|
||||||
/// Gets or sets the status code.
|
|
||||||
/// </summary>
|
|
||||||
public object StatusCode { get; set; }
|
public object StatusCode { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IResponseMessage.BodyOriginal" />
|
||||||
/// Gets or sets the body.
|
|
||||||
/// </summary>
|
|
||||||
public string BodyOriginal { get; set; }
|
public string BodyOriginal { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IResponseMessage.BodyDestination" />
|
||||||
/// Gets or sets the body destination (SameAsSource, String or Bytes).
|
|
||||||
/// </summary>
|
|
||||||
public string BodyDestination { get; set; }
|
public string BodyDestination { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IResponseMessage.BodyData" />
|
||||||
/// The Body.
|
public IBodyData BodyData { get; set; }
|
||||||
/// </summary>
|
|
||||||
public BodyData BodyData { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IResponseMessage.FaultType" />
|
||||||
/// The FaultType.
|
|
||||||
/// </summary>
|
|
||||||
public FaultType FaultType { get; set; }
|
public FaultType FaultType { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IResponseMessage.FaultPercentage" />
|
||||||
/// Gets or sets the Fault percentage.
|
|
||||||
/// </summary>
|
|
||||||
public double? FaultPercentage { get; set; }
|
public double? FaultPercentage { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace WireMock.Serialization
|
|||||||
{
|
{
|
||||||
internal static class LogEntryMapper
|
internal static class LogEntryMapper
|
||||||
{
|
{
|
||||||
public static LogEntryModel Map(LogEntry logEntry)
|
public static LogEntryModel Map(ILogEntry logEntry)
|
||||||
{
|
{
|
||||||
var logRequestModel = new LogRequestModel
|
var logRequestModel = new LogRequestModel
|
||||||
{
|
{
|
||||||
@@ -124,7 +124,7 @@ namespace WireMock.Serialization
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static LogRequestMatchModel Map(RequestMatchResult matchResult)
|
private static LogRequestMatchModel Map(IRequestMatchResult matchResult)
|
||||||
{
|
{
|
||||||
if (matchResult == null)
|
if (matchResult == null)
|
||||||
{
|
{
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,93 +1,91 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using WireMock.Logging;
|
using WireMock.Logging;
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using WireMock.Matchers.Request;
|
using WireMock.Matchers.Request;
|
||||||
|
|
||||||
namespace WireMock.Server
|
namespace WireMock.Server
|
||||||
{
|
{
|
||||||
public partial class WireMockServer
|
public partial class WireMockServer
|
||||||
{
|
{
|
||||||
/// <inheritdoc cref="IWireMockServer.LogEntriesChanged" />
|
/// <inheritdoc cref="IWireMockServer.LogEntriesChanged" />
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public event NotifyCollectionChangedEventHandler LogEntriesChanged
|
public event NotifyCollectionChangedEventHandler LogEntriesChanged
|
||||||
{
|
{
|
||||||
add
|
add
|
||||||
{
|
{
|
||||||
_options.LogEntries.CollectionChanged += (sender, eventRecordArgs) =>
|
_options.LogEntries.CollectionChanged += (sender, eventRecordArgs) =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
value(sender, eventRecordArgs);
|
value(sender, eventRecordArgs);
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
_options.Logger.Error("Error calling the LogEntriesChanged event handler: {0}", exception.Message);
|
_options.Logger.Error("Error calling the LogEntriesChanged event handler: {0}", exception.Message);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
remove => _options.LogEntries.CollectionChanged -= value;
|
remove => _options.LogEntries.CollectionChanged -= value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IWireMockServer.LogEntries" />
|
||||||
/// Gets the request logs.
|
[PublicAPI]
|
||||||
/// </summary>
|
public IEnumerable<ILogEntry> LogEntries => new ReadOnlyCollection<LogEntry>(_options.LogEntries.ToList());
|
||||||
[PublicAPI]
|
|
||||||
public IEnumerable<LogEntry> LogEntries => new ReadOnlyCollection<LogEntry>(_options.LogEntries.ToList());
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The search log-entries based on matchers.
|
/// The search log-entries based on matchers.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="matchers">The matchers.</param>
|
/// <param name="matchers">The matchers.</param>
|
||||||
/// <returns>The <see cref="IEnumerable"/>.</returns>
|
/// <returns>The <see cref="IEnumerable"/>.</returns>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public IEnumerable<LogEntry> FindLogEntries([NotNull] params IRequestMatcher[] matchers)
|
public IEnumerable<LogEntry> FindLogEntries([NotNull] params IRequestMatcher[] matchers)
|
||||||
{
|
{
|
||||||
var results = new Dictionary<LogEntry, RequestMatchResult>();
|
var results = new Dictionary<LogEntry, RequestMatchResult>();
|
||||||
|
|
||||||
foreach (var log in _options.LogEntries.ToList())
|
foreach (var log in _options.LogEntries.ToList())
|
||||||
{
|
{
|
||||||
var requestMatchResult = new RequestMatchResult();
|
var requestMatchResult = new RequestMatchResult();
|
||||||
foreach (var matcher in matchers)
|
foreach (var matcher in matchers)
|
||||||
{
|
{
|
||||||
matcher.GetMatchingScore(log.RequestMessage, requestMatchResult);
|
matcher.GetMatchingScore(log.RequestMessage, requestMatchResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (requestMatchResult.AverageTotalScore > MatchScores.AlmostPerfect)
|
if (requestMatchResult.AverageTotalScore > MatchScores.AlmostPerfect)
|
||||||
{
|
{
|
||||||
results.Add(log, requestMatchResult);
|
results.Add(log, requestMatchResult);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ReadOnlyCollection<LogEntry>(results.OrderBy(x => x.Value).Select(x => x.Key).ToList());
|
return new ReadOnlyCollection<LogEntry>(results.OrderBy(x => x.Value).Select(x => x.Key).ToList());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IWireMockServer.ResetLogEntries" />
|
/// <inheritdoc cref="IWireMockServer.ResetLogEntries" />
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public void ResetLogEntries()
|
public void ResetLogEntries()
|
||||||
{
|
{
|
||||||
_options.LogEntries.Clear();
|
_options.LogEntries.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IWireMockServer.DeleteLogEntry" />
|
/// <inheritdoc cref="IWireMockServer.DeleteLogEntry" />
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public bool DeleteLogEntry(Guid guid)
|
public bool DeleteLogEntry(Guid guid)
|
||||||
{
|
{
|
||||||
// Check a logentry exists with the same GUID, if so, remove it.
|
// Check a logentry exists with the same GUID, if so, remove it.
|
||||||
var existing = _options.LogEntries.ToList().FirstOrDefault(m => m.Guid == guid);
|
var existing = _options.LogEntries.ToList().FirstOrDefault(m => m.Guid == guid);
|
||||||
if (existing != null)
|
if (existing != null)
|
||||||
{
|
{
|
||||||
_options.LogEntries.Remove(existing);
|
_options.LogEntries.Remove(existing);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,56 +6,36 @@ namespace WireMock.Util
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// BodyData
|
/// BodyData
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class BodyData
|
public class BodyData : IBodyData
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <inheritdoc cref="IBodyData.Encoding" />
|
||||||
/// The body encoding.
|
|
||||||
/// </summary>
|
|
||||||
public Encoding Encoding { get; set; }
|
public Encoding Encoding { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IBodyData.BodyAsBytes" />
|
||||||
/// The body as string, this is defined when BodyAsString or BodyAsJson are not null.
|
|
||||||
/// </summary>
|
|
||||||
public string BodyAsString { get; set; }
|
public string BodyAsString { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IBodyData.BodyAsJson" />
|
||||||
/// The body (as JSON object).
|
|
||||||
/// </summary>
|
|
||||||
public object BodyAsJson { get; set; }
|
public object BodyAsJson { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IBodyData.BodyAsBytes" />
|
||||||
/// The body (as bytearray).
|
|
||||||
/// </summary>
|
|
||||||
public byte[] BodyAsBytes { get; set; }
|
public byte[] BodyAsBytes { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IBodyData.BodyAsJsonIndented" />
|
||||||
/// 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>
|
|
||||||
public bool? BodyAsJsonIndented { get; set; }
|
public bool? BodyAsJsonIndented { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IBodyData.BodyAsFile" />
|
||||||
/// Gets or sets the body as a file.
|
|
||||||
/// </summary>
|
|
||||||
public string BodyAsFile { get; set; }
|
public string BodyAsFile { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IBodyData.BodyAsFileIsCached" />
|
||||||
/// Is the body as file cached?
|
|
||||||
/// </summary>
|
|
||||||
public bool? BodyAsFileIsCached { get; set; }
|
public bool? BodyAsFileIsCached { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IBodyData.DetectedBodyType" />
|
||||||
/// The detected body type (detection based on body content).
|
|
||||||
/// </summary>
|
|
||||||
public BodyType DetectedBodyType { get; set; }
|
public BodyType DetectedBodyType { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IBodyData.DetectedBodyTypeFromContentType" />
|
||||||
/// The detected body type (detection based on Content-Type).
|
|
||||||
/// </summary>
|
|
||||||
public BodyType DetectedBodyTypeFromContentType { get; set; }
|
public BodyType DetectedBodyTypeFromContentType { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IRequestMessage.DetectedCompression" />
|
||||||
/// The detected compression.
|
|
||||||
/// </summary>
|
|
||||||
public string DetectedCompression { get; set; }
|
public string DetectedCompression { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user