mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-20 15:31:20 +02:00
Refactor: extract interfaces (#484)
* . * MatchDetail * rm * resp * log * f
This commit is contained in:
@@ -99,7 +99,7 @@ namespace WireMock
|
||||
/// </summary>
|
||||
/// <param name="requestMessage">The request message.</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);
|
||||
}
|
||||
}
|
||||
@@ -6,78 +6,33 @@ namespace WireMock.Logging
|
||||
/// <summary>
|
||||
/// LogEntry
|
||||
/// </summary>
|
||||
public class LogEntry
|
||||
public class LogEntry : ILogEntry
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the unique identifier.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The unique identifier.
|
||||
/// </value>
|
||||
/// <inheritdoc cref="ILogEntry.Guid" />
|
||||
public Guid Guid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the request message.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The request message.
|
||||
/// </value>
|
||||
public RequestMessage RequestMessage { get; set; }
|
||||
/// <inheritdoc cref="ILogEntry.RequestMessage" />
|
||||
public IRequestMessage RequestMessage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the response message.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The response message.
|
||||
/// </value>
|
||||
public ResponseMessage ResponseMessage { get; set; }
|
||||
/// <inheritdoc cref="ILogEntry.ResponseMessage" />
|
||||
public IResponseMessage ResponseMessage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the request match result.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The request match result.
|
||||
/// </value>
|
||||
public RequestMatchResult RequestMatchResult { get; set; }
|
||||
/// <inheritdoc cref="ILogEntry.RequestMatchResult" />
|
||||
public IRequestMatchResult RequestMatchResult { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the mapping unique identifier.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The mapping unique identifier.
|
||||
/// </value>
|
||||
/// <inheritdoc cref="ILogEntry.MappingGuid" />
|
||||
public Guid? MappingGuid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the mapping unique title.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The mapping unique title.
|
||||
/// </value>
|
||||
/// <inheritdoc cref="ILogEntry.MappingTitle" />
|
||||
public string MappingTitle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the partial mapping unique identifier.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The mapping unique identifier.
|
||||
/// </value>
|
||||
/// <inheritdoc cref="ILogEntry.PartialMappingGuid" />
|
||||
public Guid? PartialMappingGuid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the partial mapping unique title.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The mapping unique title.
|
||||
/// </value>
|
||||
/// <inheritdoc cref="ILogEntry.PartialMappingTitle" />
|
||||
public string PartialMappingTitle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the partial match result.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The request match result.
|
||||
/// </value>
|
||||
public RequestMatchResult PartialMatchResult { get; set; }
|
||||
/// <inheritdoc cref="ILogEntry.PartialMatchResult" />
|
||||
public IRequestMatchResult PartialMatchResult { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,6 @@ namespace WireMock.Matchers.Request
|
||||
/// <returns>
|
||||
/// A value between 0.0 - 1.0 of the similarity.
|
||||
/// </returns>
|
||||
double GetMatchingScore([NotNull] RequestMessage requestMessage, [NotNull] RequestMatchResult requestMatchResult);
|
||||
double GetMatchingScore([NotNull] IRequestMessage requestMessage, [NotNull] RequestMatchResult requestMatchResult);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace WireMock.Matchers.Request
|
||||
{
|
||||
public class MatchDetail
|
||||
{
|
||||
public Type MatcherType { get; set; }
|
||||
|
||||
public double Score { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -7,43 +7,21 @@ namespace WireMock.Matchers.Request
|
||||
/// <summary>
|
||||
/// RequestMatchResult
|
||||
/// </summary>
|
||||
public class RequestMatchResult : IComparable
|
||||
public class RequestMatchResult : IRequestMatchResult
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the match-score.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The match-score.
|
||||
/// </value>
|
||||
/// <inheritdoc cref="IRequestMatchResult.TotalScore" />
|
||||
public double TotalScore => MatchDetails.Sum(md => md.Score);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the total number of matches.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The total number of matches.
|
||||
/// </value>
|
||||
/// <inheritdoc cref="IRequestMatchResult.TotalNumber" />
|
||||
public int TotalNumber => MatchDetails.Count;
|
||||
|
||||
/// <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>
|
||||
/// <inheritdoc cref="IRequestMatchResult.IsPerfectMatch" />
|
||||
public bool IsPerfectMatch => Math.Abs(TotalScore - TotalNumber) < MatchScores.Tolerance;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the match percentage.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The match percentage.
|
||||
/// </value>
|
||||
/// <inheritdoc cref="IRequestMatchResult.AverageTotalScore" />
|
||||
public double AverageTotalScore => TotalNumber == 0 ? 0.0 : TotalScore / TotalNumber;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the match details.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IRequestMatchResult.MatchDetails" />
|
||||
public IList<MatchDetail> MatchDetails { get; } = new List<MatchDetail>();
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -99,13 +99,13 @@ namespace WireMock.Matchers.Request
|
||||
}
|
||||
|
||||
/// <see cref="IRequestMatcher.GetMatchingScore"/>
|
||||
public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
||||
public double GetMatchingScore(IRequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
||||
{
|
||||
double score = CalculateMatchScore(requestMessage);
|
||||
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
|
||||
if (matcher is IObjectMatcher objectMatcher)
|
||||
@@ -136,7 +136,7 @@ namespace WireMock.Matchers.Request
|
||||
return MatchScores.Mismatch;
|
||||
}
|
||||
|
||||
private double CalculateMatchScore(RequestMessage requestMessage)
|
||||
private double CalculateMatchScore(IRequestMessage requestMessage)
|
||||
{
|
||||
if (Matchers != null && Matchers.Any())
|
||||
{
|
||||
|
||||
@@ -51,13 +51,13 @@ namespace WireMock.Matchers.Request
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
||||
public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
||||
public double GetMatchingScore(IRequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
||||
{
|
||||
double score = IsMatch(requestMessage);
|
||||
return requestMatchResult.AddScore(GetType(), score);
|
||||
}
|
||||
|
||||
private double IsMatch(RequestMessage requestMessage)
|
||||
private double IsMatch(IRequestMessage requestMessage)
|
||||
{
|
||||
if (Matchers != null)
|
||||
{
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace WireMock.Matchers.Request
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
||||
public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
||||
public double GetMatchingScore(IRequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
||||
{
|
||||
if (!RequestMatchers.Any())
|
||||
{
|
||||
|
||||
@@ -91,13 +91,13 @@ namespace WireMock.Matchers.Request
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
||||
public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
||||
public double GetMatchingScore(IRequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
||||
{
|
||||
double score = IsMatch(requestMessage);
|
||||
return requestMatchResult.AddScore(GetType(), score);
|
||||
}
|
||||
|
||||
private double IsMatch(RequestMessage requestMessage)
|
||||
private double IsMatch(IRequestMessage requestMessage)
|
||||
{
|
||||
if (requestMessage.Cookies == null)
|
||||
{
|
||||
|
||||
@@ -92,13 +92,13 @@ namespace WireMock.Matchers.Request
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
||||
public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
||||
public double GetMatchingScore(IRequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
||||
{
|
||||
double score = IsMatch(requestMessage);
|
||||
return requestMatchResult.AddScore(GetType(), score);
|
||||
}
|
||||
|
||||
private double IsMatch(RequestMessage requestMessage)
|
||||
private double IsMatch(IRequestMessage requestMessage)
|
||||
{
|
||||
if (requestMessage.Headers == null)
|
||||
{
|
||||
|
||||
@@ -31,13 +31,13 @@ namespace WireMock.Matchers.Request
|
||||
}
|
||||
|
||||
/// <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));
|
||||
return requestMatchResult.AddScore(GetType(), score);
|
||||
}
|
||||
|
||||
private double IsMatch(RequestMessage requestMessage)
|
||||
private double IsMatch(IRequestMessage requestMessage)
|
||||
{
|
||||
return MatchScores.ToScore(Methods.Contains(requestMessage.Method, StringComparer.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
@@ -84,20 +84,20 @@ namespace WireMock.Matchers.Request
|
||||
}
|
||||
|
||||
/// <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));
|
||||
return requestMatchResult.AddScore(GetType(), score);
|
||||
}
|
||||
|
||||
private double IsMatch(RequestMessage requestMessage)
|
||||
private double IsMatch(IRequestMessage requestMessage)
|
||||
{
|
||||
if (Funcs != null)
|
||||
{
|
||||
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)
|
||||
{
|
||||
// Key is not present at all, just return Mismatch
|
||||
|
||||
@@ -53,13 +53,13 @@ namespace WireMock.Matchers.Request
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
||||
public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
||||
public double GetMatchingScore(IRequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
||||
{
|
||||
double score = IsMatch(requestMessage);
|
||||
return requestMatchResult.AddScore(GetType(), score);
|
||||
}
|
||||
|
||||
private double IsMatch(RequestMessage requestMessage)
|
||||
private double IsMatch(IRequestMessage requestMessage)
|
||||
{
|
||||
if (Matchers != null)
|
||||
{
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace WireMock.Matchers.Request
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
||||
public double GetMatchingScore(IRequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
||||
{
|
||||
double score = IsMatch();
|
||||
return requestMatchResult.AddScore(GetType(), score);
|
||||
|
||||
@@ -51,13 +51,13 @@ namespace WireMock.Matchers.Request
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
||||
public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
||||
public double GetMatchingScore(IRequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
||||
{
|
||||
double score = IsMatch(requestMessage);
|
||||
return requestMatchResult.AddScore(GetType(), score);
|
||||
}
|
||||
|
||||
private double IsMatch(RequestMessage requestMessage)
|
||||
private double IsMatch(IRequestMessage requestMessage)
|
||||
{
|
||||
if (Matchers != null)
|
||||
{
|
||||
|
||||
@@ -15,131 +15,81 @@ namespace WireMock
|
||||
/// <summary>
|
||||
/// The RequestMessage.
|
||||
/// </summary>
|
||||
public class RequestMessage
|
||||
public class RequestMessage : IRequestMessage
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the Client IP Address.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IRequestMessage.ClientIP" />
|
||||
public string ClientIP { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the url (relative).
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IRequestMessage.Url" />
|
||||
public string Url { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the AbsoluteUrl.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IRequestMessage.AbsoluteUrl" />
|
||||
public string AbsoluteUrl { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The ProxyUrl (if a proxy is used).
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IRequestMessage.ProxyUrl" />
|
||||
public string ProxyUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the DateTime.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IRequestMessage.DateTime" />
|
||||
public DateTime DateTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the path (relative).
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IRequestMessage.Path" />
|
||||
public string Path { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the AbsolutePath.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IRequestMessage.AbsolutePath" />
|
||||
public string AbsolutePath { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the path segments.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IRequestMessage.PathSegments" />
|
||||
public string[] PathSegments { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the absolute path segments.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IRequestMessage.AbsolutePathSegments" />
|
||||
public string[] AbsolutePathSegments { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the method.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IRequestMessage.Method" />
|
||||
public string Method { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the headers.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IRequestMessage.Headers" />
|
||||
public IDictionary<string, WireMockList<string>> Headers { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the cookies.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IRequestMessage.Cookies" />
|
||||
public IDictionary<string, string> Cookies { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the query.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IRequestMessage.Query" />
|
||||
public IDictionary<string, WireMockList<string>> Query { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the raw query.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IRequestMessage.RawQuery" />
|
||||
public string RawQuery { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The body.
|
||||
/// </summary>
|
||||
public BodyData BodyData { get; }
|
||||
/// <inheritdoc cref="IRequestMessage.BodyData" />
|
||||
public IBodyData BodyData { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The original body as string. Convenience getter for Handlebars.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IRequestMessage.Body" />
|
||||
public string Body { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The body (as JSON object). Convenience getter for Handlebars.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IRequestMessage.BodyAsJson" />
|
||||
public object BodyAsJson { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The body (as bytearray). Convenience getter for Handlebars.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IRequestMessage.BodyAsBytes" />
|
||||
public byte[] BodyAsBytes { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The detected body type. Convenience getter for Handlebars.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IRequestMessage.DetectedBodyType" />
|
||||
public string DetectedBodyType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The detected body type from the Content-Type header. Convenience getter for Handlebars.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IRequestMessage.DetectedBodyTypeFromContentType" />
|
||||
public string DetectedBodyTypeFromContentType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The detected compression from the Content-Encoding header. Convenience getter for Handlebars.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IRequestMessage.DetectedCompression" />
|
||||
public string DetectedCompression { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Host
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IRequestMessage.Host" />
|
||||
public string Host { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the protocol
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IRequestMessage.Protocol" />
|
||||
public string Protocol { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the port
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IRequestMessage.Port" />
|
||||
public int Port { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the origin
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IRequestMessage.Origin" />
|
||||
public string Origin { get; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
namespace WireMock.ResponseBuilders
|
||||
{
|
||||
/// <summary>
|
||||
/// The FaultType enumeration
|
||||
/// </summary>
|
||||
public enum FaultType
|
||||
{
|
||||
/// <summary>
|
||||
/// No Fault
|
||||
/// </summary>
|
||||
NONE,
|
||||
|
||||
/// <summary>
|
||||
/// Return a completely empty response.
|
||||
/// </summary>
|
||||
EMPTY_RESPONSE,
|
||||
|
||||
/// <summary>
|
||||
/// Send a defined status header, then garbage, then close the connection.
|
||||
/// </summary>
|
||||
MALFORMED_RESPONSE_CHUNK
|
||||
}
|
||||
}
|
||||
@@ -12,41 +12,27 @@ namespace WireMock
|
||||
/// <summary>
|
||||
/// The ResponseMessage.
|
||||
/// </summary>
|
||||
public class ResponseMessage
|
||||
public class ResponseMessage : IResponseMessage
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the headers.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IResponseMessage.Headers" />
|
||||
public IDictionary<string, WireMockList<string>> Headers { get; set; } = new Dictionary<string, WireMockList<string>>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the status code.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IResponseMessage.StatusCode" />
|
||||
public object StatusCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the body.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IResponseMessage.BodyOriginal" />
|
||||
public string BodyOriginal { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the body destination (SameAsSource, String or Bytes).
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IResponseMessage.BodyDestination" />
|
||||
public string BodyDestination { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The Body.
|
||||
/// </summary>
|
||||
public BodyData BodyData { get; set; }
|
||||
/// <inheritdoc cref="IResponseMessage.BodyData" />
|
||||
public IBodyData BodyData { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The FaultType.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IResponseMessage.FaultType" />
|
||||
public FaultType FaultType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Fault percentage.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IResponseMessage.FaultPercentage" />
|
||||
public double? FaultPercentage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace WireMock.Serialization
|
||||
{
|
||||
internal static class LogEntryMapper
|
||||
{
|
||||
public static LogEntryModel Map(LogEntry logEntry)
|
||||
public static LogEntryModel Map(ILogEntry logEntry)
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,93 +1,91 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
|
||||
namespace WireMock.Server
|
||||
{
|
||||
public partial class WireMockServer
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
|
||||
namespace WireMock.Server
|
||||
{
|
||||
public partial class WireMockServer
|
||||
{
|
||||
/// <inheritdoc cref="IWireMockServer.LogEntriesChanged" />
|
||||
[PublicAPI]
|
||||
public event NotifyCollectionChangedEventHandler LogEntriesChanged
|
||||
{
|
||||
add
|
||||
{
|
||||
_options.LogEntries.CollectionChanged += (sender, eventRecordArgs) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
value(sender, eventRecordArgs);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
_options.Logger.Error("Error calling the LogEntriesChanged event handler: {0}", exception.Message);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
remove => _options.LogEntries.CollectionChanged -= value;
|
||||
/// <inheritdoc cref="IWireMockServer.LogEntriesChanged" />
|
||||
[PublicAPI]
|
||||
public event NotifyCollectionChangedEventHandler LogEntriesChanged
|
||||
{
|
||||
add
|
||||
{
|
||||
_options.LogEntries.CollectionChanged += (sender, eventRecordArgs) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
value(sender, eventRecordArgs);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
_options.Logger.Error("Error calling the LogEntriesChanged event handler: {0}", exception.Message);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
remove => _options.LogEntries.CollectionChanged -= value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the request logs.
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
public IEnumerable<LogEntry> LogEntries => new ReadOnlyCollection<LogEntry>(_options.LogEntries.ToList());
|
||||
/// <inheritdoc cref="IWireMockServer.LogEntries" />
|
||||
[PublicAPI]
|
||||
public IEnumerable<ILogEntry> LogEntries => new ReadOnlyCollection<LogEntry>(_options.LogEntries.ToList());
|
||||
|
||||
/// <summary>
|
||||
/// The search log-entries based on matchers.
|
||||
/// </summary>
|
||||
/// <param name="matchers">The matchers.</param>
|
||||
/// <returns>The <see cref="IEnumerable"/>.</returns>
|
||||
[PublicAPI]
|
||||
public IEnumerable<LogEntry> FindLogEntries([NotNull] params IRequestMatcher[] matchers)
|
||||
{
|
||||
var results = new Dictionary<LogEntry, RequestMatchResult>();
|
||||
|
||||
foreach (var log in _options.LogEntries.ToList())
|
||||
{
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
foreach (var matcher in matchers)
|
||||
{
|
||||
matcher.GetMatchingScore(log.RequestMessage, requestMatchResult);
|
||||
}
|
||||
|
||||
if (requestMatchResult.AverageTotalScore > MatchScores.AlmostPerfect)
|
||||
{
|
||||
results.Add(log, requestMatchResult);
|
||||
}
|
||||
}
|
||||
|
||||
return new ReadOnlyCollection<LogEntry>(results.OrderBy(x => x.Value).Select(x => x.Key).ToList());
|
||||
/// <summary>
|
||||
/// The search log-entries based on matchers.
|
||||
/// </summary>
|
||||
/// <param name="matchers">The matchers.</param>
|
||||
/// <returns>The <see cref="IEnumerable"/>.</returns>
|
||||
[PublicAPI]
|
||||
public IEnumerable<LogEntry> FindLogEntries([NotNull] params IRequestMatcher[] matchers)
|
||||
{
|
||||
var results = new Dictionary<LogEntry, RequestMatchResult>();
|
||||
|
||||
foreach (var log in _options.LogEntries.ToList())
|
||||
{
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
foreach (var matcher in matchers)
|
||||
{
|
||||
matcher.GetMatchingScore(log.RequestMessage, requestMatchResult);
|
||||
}
|
||||
|
||||
if (requestMatchResult.AverageTotalScore > MatchScores.AlmostPerfect)
|
||||
{
|
||||
results.Add(log, requestMatchResult);
|
||||
}
|
||||
}
|
||||
|
||||
return new ReadOnlyCollection<LogEntry>(results.OrderBy(x => x.Value).Select(x => x.Key).ToList());
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IWireMockServer.ResetLogEntries" />
|
||||
[PublicAPI]
|
||||
public void ResetLogEntries()
|
||||
{
|
||||
_options.LogEntries.Clear();
|
||||
/// <inheritdoc cref="IWireMockServer.ResetLogEntries" />
|
||||
[PublicAPI]
|
||||
public void ResetLogEntries()
|
||||
{
|
||||
_options.LogEntries.Clear();
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IWireMockServer.DeleteLogEntry" />
|
||||
[PublicAPI]
|
||||
public bool DeleteLogEntry(Guid guid)
|
||||
{
|
||||
// Check a logentry exists with the same GUID, if so, remove it.
|
||||
var existing = _options.LogEntries.ToList().FirstOrDefault(m => m.Guid == guid);
|
||||
if (existing != null)
|
||||
{
|
||||
_options.LogEntries.Remove(existing);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <inheritdoc cref="IWireMockServer.DeleteLogEntry" />
|
||||
[PublicAPI]
|
||||
public bool DeleteLogEntry(Guid guid)
|
||||
{
|
||||
// Check a logentry exists with the same GUID, if so, remove it.
|
||||
var existing = _options.LogEntries.ToList().FirstOrDefault(m => m.Guid == guid);
|
||||
if (existing != null)
|
||||
{
|
||||
_options.LogEntries.Remove(existing);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,56 +6,36 @@ namespace WireMock.Util
|
||||
/// <summary>
|
||||
/// BodyData
|
||||
/// </summary>
|
||||
public class BodyData
|
||||
public class BodyData : IBodyData
|
||||
{
|
||||
/// <summary>
|
||||
/// The body encoding.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IBodyData.Encoding" />
|
||||
public Encoding Encoding { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The body as string, this is defined when BodyAsString or BodyAsJson are not null.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IBodyData.BodyAsBytes" />
|
||||
public string BodyAsString { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The body (as JSON object).
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IBodyData.BodyAsJson" />
|
||||
public object BodyAsJson { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The body (as bytearray).
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IBodyData.BodyAsBytes" />
|
||||
public byte[] BodyAsBytes { 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>
|
||||
/// <inheritdoc cref="IBodyData.BodyAsJsonIndented" />
|
||||
public bool? BodyAsJsonIndented { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the body as a file.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IBodyData.BodyAsFile" />
|
||||
public string BodyAsFile { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Is the body as file cached?
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IBodyData.BodyAsFileIsCached" />
|
||||
public bool? BodyAsFileIsCached { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The detected body type (detection based on body content).
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IBodyData.DetectedBodyType" />
|
||||
public BodyType DetectedBodyType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The detected body type (detection based on Content-Type).
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IBodyData.DetectedBodyTypeFromContentType" />
|
||||
public BodyType DetectedBodyTypeFromContentType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The detected compression.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IRequestMessage.DetectedCompression" />
|
||||
public string DetectedCompression { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user