mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-26 18:28:27 +02:00
Add MultiPart/MimePart Request Matcher (#981)
* wip * . * mm * x * . * . * . * tests * . * more tests * trans * x * win * fix * . * tests
This commit is contained in:
@@ -8,6 +8,7 @@ using System.Net;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
#endif
|
||||
using Stef.Validation;
|
||||
using WireMock.Http;
|
||||
using WireMock.Models;
|
||||
using WireMock.Owin;
|
||||
using WireMock.Types;
|
||||
@@ -20,40 +21,40 @@ namespace WireMock;
|
||||
/// </summary>
|
||||
public class RequestMessage : IRequestMessage
|
||||
{
|
||||
/// <inheritdoc cref="IRequestMessage.ClientIP" />
|
||||
/// <inheritdoc />
|
||||
public string ClientIP { get; }
|
||||
|
||||
/// <inheritdoc cref="IRequestMessage.Url" />
|
||||
/// <inheritdoc />
|
||||
public string Url { get; }
|
||||
|
||||
/// <inheritdoc cref="IRequestMessage.AbsoluteUrl" />
|
||||
/// <inheritdoc />
|
||||
public string AbsoluteUrl { get; }
|
||||
|
||||
/// <inheritdoc cref="IRequestMessage.ProxyUrl" />
|
||||
/// <inheritdoc />
|
||||
public string? ProxyUrl { get; set; }
|
||||
|
||||
/// <inheritdoc cref="IRequestMessage.DateTime" />
|
||||
/// <inheritdoc />
|
||||
public DateTime DateTime { get; set; }
|
||||
|
||||
/// <inheritdoc cref="IRequestMessage.Path" />
|
||||
/// <inheritdoc />
|
||||
public string Path { get; }
|
||||
|
||||
/// <inheritdoc cref="IRequestMessage.AbsolutePath" />
|
||||
/// <inheritdoc />
|
||||
public string AbsolutePath { get; }
|
||||
|
||||
/// <inheritdoc cref="IRequestMessage.PathSegments" />
|
||||
/// <inheritdoc />
|
||||
public string[] PathSegments { get; }
|
||||
|
||||
/// <inheritdoc cref="IRequestMessage.AbsolutePathSegments" />
|
||||
/// <inheritdoc />
|
||||
public string[] AbsolutePathSegments { get; }
|
||||
|
||||
/// <inheritdoc cref="IRequestMessage.Method" />
|
||||
/// <inheritdoc />
|
||||
public string Method { get; }
|
||||
|
||||
/// <inheritdoc cref="IRequestMessage.Headers" />
|
||||
/// <inheritdoc />
|
||||
public IDictionary<string, WireMockList<string>>? Headers { get; }
|
||||
|
||||
/// <inheritdoc cref="IRequestMessage.Cookies" />
|
||||
/// <inheritdoc />
|
||||
public IDictionary<string, string>? Cookies { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -61,45 +62,50 @@ public class RequestMessage : IRequestMessage
|
||||
|
||||
/// <inheritdoc />
|
||||
public IDictionary<string, WireMockList<string>>? QueryIgnoreCase { get; }
|
||||
|
||||
/// <inheritdoc cref="IRequestMessage.RawQuery" />
|
||||
|
||||
/// <inheritdoc />
|
||||
public string RawQuery { get; }
|
||||
|
||||
/// <inheritdoc cref="IRequestMessage.BodyData" />
|
||||
/// <inheritdoc />
|
||||
public IBodyData? BodyData { get; }
|
||||
|
||||
/// <inheritdoc cref="IRequestMessage.Body" />
|
||||
public string Body { get; }
|
||||
/// <inheritdoc />
|
||||
public string? Body { get; }
|
||||
|
||||
/// <inheritdoc cref="IRequestMessage.BodyAsJson" />
|
||||
public object BodyAsJson { get; }
|
||||
/// <inheritdoc />
|
||||
public object? BodyAsJson { get; }
|
||||
|
||||
/// <inheritdoc cref="IRequestMessage.BodyAsBytes" />
|
||||
public byte[] BodyAsBytes { get; }
|
||||
/// <inheritdoc />
|
||||
public byte[]? BodyAsBytes { get; }
|
||||
|
||||
/// <inheritdoc cref="IRequestMessage.DetectedBodyType" />
|
||||
public string DetectedBodyType { get; }
|
||||
#if MIMEKIT
|
||||
/// <inheritdoc />
|
||||
public object? BodyAsMimeMessage { get; }
|
||||
#endif
|
||||
|
||||
/// <inheritdoc cref="IRequestMessage.DetectedBodyTypeFromContentType" />
|
||||
public string DetectedBodyTypeFromContentType { get; }
|
||||
/// <inheritdoc />
|
||||
public string? DetectedBodyType { get; }
|
||||
|
||||
/// <inheritdoc cref="IRequestMessage.DetectedCompression" />
|
||||
public string DetectedCompression { get; }
|
||||
/// <inheritdoc />
|
||||
public string? DetectedBodyTypeFromContentType { get; }
|
||||
|
||||
/// <inheritdoc cref="IRequestMessage.Host" />
|
||||
/// <inheritdoc />
|
||||
public string? DetectedCompression { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Host { get; }
|
||||
|
||||
/// <inheritdoc cref="IRequestMessage.Protocol" />
|
||||
/// <inheritdoc />
|
||||
public string Protocol { get; }
|
||||
|
||||
/// <inheritdoc cref="IRequestMessage.Port" />
|
||||
/// <inheritdoc />
|
||||
public int Port { get; }
|
||||
|
||||
/// <inheritdoc cref="IRequestMessage.Origin" />
|
||||
/// <inheritdoc />
|
||||
public string Origin { get; }
|
||||
|
||||
#if USE_ASPNETCORE
|
||||
/// <inheritdoc cref="IRequestMessage.ClientCertificate" />
|
||||
/// <inheritdoc />
|
||||
public X509Certificate2? ClientCertificate { get; }
|
||||
#endif
|
||||
|
||||
@@ -139,11 +145,11 @@ public class RequestMessage : IRequestMessage
|
||||
#if USE_ASPNETCORE
|
||||
, X509Certificate2? clientCertificate = null
|
||||
#endif
|
||||
)
|
||||
)
|
||||
{
|
||||
Guard.NotNull(urlDetails, nameof(urlDetails));
|
||||
Guard.NotNull(method, nameof(method));
|
||||
Guard.NotNull(clientIP, nameof(clientIP));
|
||||
Guard.NotNull(urlDetails);
|
||||
Guard.NotNull(method);
|
||||
Guard.NotNull(clientIP);
|
||||
|
||||
AbsoluteUrl = urlDetails.AbsoluteUrl.ToString();
|
||||
Url = urlDetails.Url.ToString();
|
||||
@@ -166,10 +172,22 @@ public class RequestMessage : IRequestMessage
|
||||
Body = BodyData?.BodyAsString;
|
||||
BodyAsJson = BodyData?.BodyAsJson;
|
||||
BodyAsBytes = BodyData?.BodyAsBytes;
|
||||
|
||||
DetectedBodyType = BodyData?.DetectedBodyType.ToString();
|
||||
DetectedBodyTypeFromContentType = BodyData?.DetectedBodyTypeFromContentType.ToString();
|
||||
DetectedCompression = BodyData?.DetectedCompression;
|
||||
|
||||
#if MIMEKIT
|
||||
try
|
||||
{
|
||||
BodyAsMimeMessage = MimeKitUtils.GetMimeMessage(BodyData, headers![HttpKnownHeaderNames.ContentType].First());
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore exception from MimeMessage.Load
|
||||
}
|
||||
#endif
|
||||
|
||||
Headers = headers?.ToDictionary(header => header.Key, header => new WireMockList<string>(header.Value));
|
||||
Cookies = cookies;
|
||||
RawQuery = urlDetails.Url.Query;
|
||||
|
||||
Reference in New Issue
Block a user