Only load MimeKitUtils when request message is multipart

This commit is contained in:
Stef Heyenrath committed 2026-12-06 08:53:32 +01:00
1 parent 3f3e576750
commit acbc33f04e
8 files changed
+122 -41

No files matched your search

@@ -7,7 +7,7 @@ namespace WireMock.Net.Tests.Matchers;
public class MimePartMatcherTests
{
private static readonly IMimeKitUtils MimeKitUtils = new MimeKitUtils();
private static readonly MimeKitUtils MimeKitUtils = new();
private const string TestMultiPart =
"""
+35 -1
View File
@@ -1,6 +1,7 @@
// Copyright © WireMock.Net
using WireMock.Models;
using WireMock.Util;
namespace WireMock.Net.Tests;
@@ -82,4 +83,37 @@ public class RequestMessageTests
request.GetParameter("key").Should().Contain("2");
request.GetParameter("key").Should().Contain("3");
}
}
[Fact]
public void RequestMessage_TryGetMultipartMimeHeader_WithMultipartContentType()
{
// Arrange
var contentType = " MULTIPART/form-data; boundary=boundary";
var body = new BodyData();
var headers = new Dictionary<string, string[]> { { "Content-Type", [contentType] } };
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, body, headers);
// Act
var result = request.TryGetMultipartMimeHeader(out var contentTypeHeader);
// Assert
result.Should().BeTrue();
contentTypeHeader.Should().ContainSingle(contentType);
}
[Fact]
public void RequestMessage_TryGetMultipartMimeHeader_WithNonMultipartContentType()
{
// Arrange
var body = new BodyData();
var headers = new Dictionary<string, string[]> { { "Content-Type", ["application/json"] } };
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, body, headers);
// Act
var result = request.TryGetMultipartMimeHeader(out var contentTypeHeader);
// Assert
result.Should().BeFalse();
contentTypeHeader.Should().BeNull();
}
}