From a1ecd4cada92e42738d30524d87a1bc630d3e24a Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Mon, 7 Jul 2025 22:21:16 +0200 Subject: [PATCH 01/18] Implement IMimeMessageData --- .../Models/MimeMessageDataWrapper.cs | 118 ++++++++ .../Util/MimeKitUtils.cs | 19 +- .../Models/IMimeMessageData.cs | 273 ++++++++++++++++++ src/WireMock.Net.Shared/Util/IMimeKitUtils.cs | 11 +- 4 files changed, 407 insertions(+), 14 deletions(-) create mode 100644 src/WireMock.Net.MimePart/Models/MimeMessageDataWrapper.cs create mode 100644 src/WireMock.Net.Shared/Models/IMimeMessageData.cs diff --git a/src/WireMock.Net.MimePart/Models/MimeMessageDataWrapper.cs b/src/WireMock.Net.MimePart/Models/MimeMessageDataWrapper.cs new file mode 100644 index 000000000..14891f987 --- /dev/null +++ b/src/WireMock.Net.MimePart/Models/MimeMessageDataWrapper.cs @@ -0,0 +1,118 @@ +// Copyright © WireMock.Net + +using System; +using System.Collections.Generic; +using MimeKit; +using Stef.Validation; + +namespace WireMock.Models; + +/// +/// A wrapper class that implements the > interface by wrapping an interface. +/// +/// +/// This class provides a simplified, read-only view of an . +/// +internal class MimeMessageDataWrapper : IMimeMessageData +{ + public IMimeMessage Message { get; } + + /// + /// Initializes a new instance of the class. + /// + /// The MIME message to wrap. + /// + /// is . + /// + public MimeMessageDataWrapper(IMimeMessage message) + { + Message = Guard.NotNull(message); + } + + /// + public IEnumerable Headers => Message.Headers; + + /// + public int Importance => (int)Message.Importance; + + /// + public int Priority => (int)Message.Priority; + + /// + public int XPriority => (int)Message.XPriority; + + /// + public object Sender => Message.Sender; + + /// + public object ResentSender => Message.ResentSender; + + /// + public object From => Message.From; + + /// + public object ResentFrom => Message.ResentFrom; + + /// + public object ReplyTo => Message.ReplyTo; + + /// + public object ResentReplyTo => Message.ResentReplyTo; + + /// + public object To => Message.To; + + /// + public object ResentTo => Message.ResentTo; + + /// + public object Cc => Message.Cc; + + /// + public object ResentCc => Message.ResentCc; + + /// + public object Bcc => Message.Bcc; + + /// + public object ResentBcc => Message.ResentBcc; + + /// + public string Subject => Message.Subject; + + /// + public DateTimeOffset Date => Message.Date; + + /// + public DateTimeOffset ResentDate => Message.ResentDate; + + /// + public IList References => Message.References; + + /// + public string InReplyTo => Message.InReplyTo; + + /// + public string MessageId => Message.MessageId; + + /// + public string ResentMessageId => Message.ResentMessageId; + + /// + public Version MimeVersion => Message.MimeVersion; + + /// + public object Body => Message.Body; + + /// + public string TextBody => Message.TextBody; + + /// + public string HtmlBody => Message.HtmlBody; + + /// + public IEnumerable BodyParts => Message.BodyParts; + + /// + public IEnumerable Attachments => Message.Attachments; +} \ No newline at end of file diff --git a/src/WireMock.Net.MimePart/Util/MimeKitUtils.cs b/src/WireMock.Net.MimePart/Util/MimeKitUtils.cs index e0bd93ca1..140dfb725 100644 --- a/src/WireMock.Net.MimePart/Util/MimeKitUtils.cs +++ b/src/WireMock.Net.MimePart/Util/MimeKitUtils.cs @@ -9,6 +9,7 @@ using MimeKit; using Stef.Validation; using WireMock.Http; +using WireMock.Models; using WireMock.Types; namespace WireMock.Util; @@ -16,13 +17,13 @@ namespace WireMock.Util; internal class MimeKitUtils : IMimeKitUtils { /// - public object LoadFromStream(Stream stream) + public IMimeMessageData LoadFromStream(Stream stream) { - return MimeMessage.Load(Guard.NotNull(stream)); + return new MimeMessageDataWrapper(MimeMessage.Load(Guard.NotNull(stream))); } /// - public bool TryGetMimeMessage(IRequestMessage requestMessage, [NotNullWhen(true)] out object? mimeMessage) + public bool TryGetMimeMessage(IRequestMessage requestMessage, [NotNullWhen(true)] out IMimeMessageData? mimeMessageData) { Guard.NotNull(requestMessage); @@ -44,23 +45,23 @@ public bool TryGetMimeMessage(IRequestMessage requestMessage, [NotNullWhen(true) var fixedBytes = FixBytes(bytes, contentTypeHeader[0]); - mimeMessage = LoadFromStream(new MemoryStream(fixedBytes)); + mimeMessageData = LoadFromStream(new MemoryStream(fixedBytes)); return true; } - mimeMessage = null; + mimeMessageData = null; return false; } /// - public IReadOnlyList GetBodyParts(object mimeMessage) + public IReadOnlyList GetBodyParts(IMimeMessageData mimeMessageData) { - if (mimeMessage is not MimeMessage mm) + if (mimeMessageData is not MimeMessageDataWrapper wrapper) { - throw new ArgumentException($"The mimeMessage must be of type {nameof(MimeMessage)}", nameof(mimeMessage)); + throw new ArgumentException($"The mimeMessage must be of type {nameof(MimeMessageDataWrapper)}", nameof(mimeMessageData)); } - return mm.BodyParts + return wrapper.Message.BodyParts .OfType() .ToArray(); } diff --git a/src/WireMock.Net.Shared/Models/IMimeMessageData.cs b/src/WireMock.Net.Shared/Models/IMimeMessageData.cs new file mode 100644 index 000000000..4b471a479 --- /dev/null +++ b/src/WireMock.Net.Shared/Models/IMimeMessageData.cs @@ -0,0 +1,273 @@ +// Copyright © WireMock.Net + +using System; +using System.Collections.Generic; + +namespace WireMock.Models; + +/// +/// A simplified interface exposing the public, readable properties of a MIME message. +/// +public interface IMimeMessageData +{ + /// + /// Get the list of headers. + /// + /// The list of headers. + IEnumerable Headers + { + get; + } + + /// + /// Get the value of the Importance header. + /// + /// The importance, as an integer. + int Importance + { + get; + } + + /// + /// Get the value of the Priority header. + /// + /// The priority, as an integer. + int Priority + { + get; + } + + /// + /// Get the value of the X-Priority header. + /// + /// The X-priority, as an integer. + int XPriority + { + get; + } + + /// + /// Get the address in the Sender header. + /// + /// The address in the Sender header. + object Sender + { + get; + } + + /// + /// Get the address in the Resent-Sender header. + /// + /// The address in the Resent-Sender header. + object ResentSender + { + get; + } + + /// + /// Get the list of addresses in the From header. + /// + /// The list of addresses in the From header. + object From + { + get; + } + + /// + /// Get the list of addresses in the Resent-From header. + /// + /// The list of addresses in the Resent-From header. + object ResentFrom + { + get; + } + + /// + /// Get the list of addresses in the Reply-To header. + /// + /// The list of addresses in the Reply-To header. + object ReplyTo + { + get; + } + + /// + /// Get the list of addresses in the Resent-Reply-To header. + /// + /// The list of addresses in the Resent-Reply-To header. + object ResentReplyTo + { + get; + } + + /// + /// Get the list of addresses in the To header. + /// + /// The list of addresses in the To header. + object To + { + get; + } + + /// + /// Get the list of addresses in the Resent-To header. + /// + /// The list of addresses in the Resent-To header. + object ResentTo + { + get; + } + + /// + /// Get the list of addresses in the Cc header. + /// + /// The list of addresses in the Cc header. + object Cc + { + get; + } + + /// + /// Get the list of addresses in the Resent-Cc header. + /// + /// The list of addresses in the Resent-Cc header. + object ResentCc + { + get; + } + + /// + /// Get the list of addresses in the Bcc header. + /// + /// The list of addresses in the Bcc header. + object Bcc + { + get; + } + + /// + /// Get the list of addresses in the Resent-Bcc header. + /// + /// The list of addresses in the Resent-Bcc header. + object ResentBcc + { + get; + } + + /// + /// Get the subject of the message. + /// + /// The subject of the message. + string Subject + { + get; + } + + /// + /// Get the date of the message. + /// + /// The date of the message. + DateTimeOffset Date + { + get; + } + + /// + /// Get the Resent-Date of the message. + /// + /// The Resent-Date of the message. + DateTimeOffset ResentDate + { + get; + } + + /// + /// Get the list of references to other messages. + /// + /// The references. + IList References + { + get; + } + + /// + /// Get the Message-Id that this message is replying to. + /// + /// The message id that this message is in reply to. + string InReplyTo + { + get; + } + + /// + /// Get the message identifier. + /// + /// The message identifier. + string MessageId + { + get; + } + + /// + /// Get the Resent-Message-Id header. + /// + /// The Resent-Message-Id. + string ResentMessageId + { + get; + } + + /// + /// Get the MIME-Version. + /// + /// The MIME version. + Version MimeVersion + { + get; + } + + /// + /// Get the body of the message. + /// + /// The body of the message. + object Body + { + get; + } + + /// + /// Get the text body of the message if it exists. + /// + /// The text body if it exists; otherwise, . + string TextBody + { + get; + } + + /// + /// Get the html body of the message if it exists. + /// + /// The html body if it exists; otherwise, . + string HtmlBody + { + get; + } + + /// + /// Get the body parts of the message. + /// + /// The body parts. + IEnumerable BodyParts + { + get; + } + + /// + /// Get the attachments. + /// + /// The attachments. + IEnumerable Attachments + { + get; + } +} \ No newline at end of file diff --git a/src/WireMock.Net.Shared/Util/IMimeKitUtils.cs b/src/WireMock.Net.Shared/Util/IMimeKitUtils.cs index 35d5adbb6..a20a18e35 100644 --- a/src/WireMock.Net.Shared/Util/IMimeKitUtils.cs +++ b/src/WireMock.Net.Shared/Util/IMimeKitUtils.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.IO; +using WireMock.Models; namespace WireMock.Util; @@ -16,20 +17,20 @@ public interface IMimeKitUtils /// /// The stream /// MimeKit.MimeMessage - object LoadFromStream(Stream stream); + IMimeMessageData LoadFromStream(Stream stream); /// /// Tries to get the MimeKit.MimeMessage from the request message. /// /// The request message. - /// The MimeKit.MimeMessage + /// A class MimeMessageDataWrapper which wraps a MimeKit.MimeMessage. /// true when parsed correctly, else false - bool TryGetMimeMessage(IRequestMessage requestMessage, [NotNullWhen(true)] out object? mimeMessage); + bool TryGetMimeMessage(IRequestMessage requestMessage, [NotNullWhen(true)] out IMimeMessageData? mimeMessageData); /// /// Gets the body parts from the MimeKit.MimeMessage. /// - /// The MimeKit.MimeMessage. + /// The MimeKit.MimeMessage. /// A list of MimeParts. - IReadOnlyList GetBodyParts(object mimeMessage); + IReadOnlyList GetBodyParts(IMimeMessageData mimeMessageData); } \ No newline at end of file From 78c2333e0d5a99898f8fef6c43bd9b309123c1d2 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Mon, 7 Jul 2025 22:24:13 +0200 Subject: [PATCH 02/18] 1 --- .../Models/IMimeMessageData.cs | 145 ++++-------------- 1 file changed, 29 insertions(+), 116 deletions(-) diff --git a/src/WireMock.Net.Shared/Models/IMimeMessageData.cs b/src/WireMock.Net.Shared/Models/IMimeMessageData.cs index 4b471a479..b954b6ee6 100644 --- a/src/WireMock.Net.Shared/Models/IMimeMessageData.cs +++ b/src/WireMock.Net.Shared/Models/IMimeMessageData.cs @@ -14,260 +14,173 @@ public interface IMimeMessageData /// Get the list of headers. /// /// The list of headers. - IEnumerable Headers - { - get; - } + IEnumerable Headers { get; } /// /// Get the value of the Importance header. /// /// The importance, as an integer. - int Importance - { - get; - } + int Importance { get; } /// /// Get the value of the Priority header. /// /// The priority, as an integer. - int Priority - { - get; - } + int Priority { get; } /// /// Get the value of the X-Priority header. /// /// The X-priority, as an integer. - int XPriority - { - get; - } + int XPriority { get; } /// /// Get the address in the Sender header. /// /// The address in the Sender header. - object Sender - { - get; - } + object Sender { get; } /// /// Get the address in the Resent-Sender header. /// /// The address in the Resent-Sender header. - object ResentSender - { - get; - } + object ResentSender { get; } /// /// Get the list of addresses in the From header. /// /// The list of addresses in the From header. - object From - { - get; - } + object From { get; } /// /// Get the list of addresses in the Resent-From header. /// /// The list of addresses in the Resent-From header. - object ResentFrom - { - get; - } + object ResentFrom { get; } /// /// Get the list of addresses in the Reply-To header. /// /// The list of addresses in the Reply-To header. - object ReplyTo - { - get; - } + object ReplyTo { get; } /// /// Get the list of addresses in the Resent-Reply-To header. /// /// The list of addresses in the Resent-Reply-To header. - object ResentReplyTo - { - get; - } + object ResentReplyTo { get; } /// /// Get the list of addresses in the To header. /// /// The list of addresses in the To header. - object To - { - get; - } + object To { get; } /// /// Get the list of addresses in the Resent-To header. /// /// The list of addresses in the Resent-To header. - object ResentTo - { - get; - } + object ResentTo { get; } /// /// Get the list of addresses in the Cc header. /// /// The list of addresses in the Cc header. - object Cc - { - get; - } + object Cc { get; } /// /// Get the list of addresses in the Resent-Cc header. /// /// The list of addresses in the Resent-Cc header. - object ResentCc - { - get; - } + object ResentCc { get; } /// /// Get the list of addresses in the Bcc header. /// /// The list of addresses in the Bcc header. - object Bcc - { - get; - } + object Bcc { get; } /// /// Get the list of addresses in the Resent-Bcc header. /// /// The list of addresses in the Resent-Bcc header. - object ResentBcc - { - get; - } + object ResentBcc { get; } /// /// Get the subject of the message. /// /// The subject of the message. - string Subject - { - get; - } + string Subject { get; } /// /// Get the date of the message. /// /// The date of the message. - DateTimeOffset Date - { - get; - } + DateTimeOffset Date { get; } /// /// Get the Resent-Date of the message. /// /// The Resent-Date of the message. - DateTimeOffset ResentDate - { - get; - } + DateTimeOffset ResentDate { get; } /// /// Get the list of references to other messages. /// /// The references. - IList References - { - get; - } + IList References { get; } /// /// Get the Message-Id that this message is replying to. /// /// The message id that this message is in reply to. - string InReplyTo - { - get; - } + string InReplyTo { get; } /// /// Get the message identifier. /// /// The message identifier. - string MessageId - { - get; - } + string MessageId { get; } /// /// Get the Resent-Message-Id header. /// /// The Resent-Message-Id. - string ResentMessageId - { - get; - } + string ResentMessageId { get; } /// /// Get the MIME-Version. /// /// The MIME version. - Version MimeVersion - { - get; - } + Version MimeVersion { get; } /// /// Get the body of the message. /// /// The body of the message. - object Body - { - get; - } + object Body { get; } /// /// Get the text body of the message if it exists. /// /// The text body if it exists; otherwise, . - string TextBody - { - get; - } + string TextBody { get; } /// /// Get the html body of the message if it exists. /// /// The html body if it exists; otherwise, . - string HtmlBody - { - get; - } + string HtmlBody { get; } /// /// Get the body parts of the message. /// /// The body parts. - IEnumerable BodyParts - { - get; - } + IEnumerable BodyParts { get; } /// /// Get the attachments. /// /// The attachments. - IEnumerable Attachments - { - get; - } + IEnumerable Attachments { get; } } \ No newline at end of file From 8816d3774fc2fbf47a0c125d1bc6d7c0397d7c7d Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Tue, 8 Jul 2025 10:50:13 +0200 Subject: [PATCH 03/18] Update src/WireMock.Net.MimePart/Util/MimeKitUtils.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/WireMock.Net.MimePart/Util/MimeKitUtils.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WireMock.Net.MimePart/Util/MimeKitUtils.cs b/src/WireMock.Net.MimePart/Util/MimeKitUtils.cs index 140dfb725..6a9d8b5ae 100644 --- a/src/WireMock.Net.MimePart/Util/MimeKitUtils.cs +++ b/src/WireMock.Net.MimePart/Util/MimeKitUtils.cs @@ -58,7 +58,7 @@ public IReadOnlyList GetBodyParts(IMimeMessageData mimeMessageData) { if (mimeMessageData is not MimeMessageDataWrapper wrapper) { - throw new ArgumentException($"The mimeMessage must be of type {nameof(MimeMessageDataWrapper)}", nameof(mimeMessageData)); + throw new ArgumentException($"The mimeMessageData must be of type {nameof(MimeMessageDataWrapper)}", nameof(mimeMessageData)); } return wrapper.Message.BodyParts From b0bcea51b0730093b7a8c1a5dad04e6be919a5cc Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Fri, 11 Jul 2025 08:32:10 +0200 Subject: [PATCH 04/18] v1 --- .../Models/MimeEntityDataWrapper.cs | 54 ++++++++++++++++++ .../Models/MimeMessageDataWrapper.cs | 36 ++++++------ .../Models/MimePartDataWrapper.cs | 48 ++++++++++++++++ .../Models/IMimeEntityData.cs | 55 +++++++++++++++++++ .../Models/IMimeMessageData.cs | 32 +++++------ .../Models/IMimePartData.cs | 46 ++++++++++++++++ 6 files changed, 236 insertions(+), 35 deletions(-) create mode 100644 src/WireMock.Net.MimePart/Models/MimeEntityDataWrapper.cs create mode 100644 src/WireMock.Net.MimePart/Models/MimePartDataWrapper.cs create mode 100644 src/WireMock.Net.Shared/Models/IMimeEntityData.cs create mode 100644 src/WireMock.Net.Shared/Models/IMimePartData.cs diff --git a/src/WireMock.Net.MimePart/Models/MimeEntityDataWrapper.cs b/src/WireMock.Net.MimePart/Models/MimeEntityDataWrapper.cs new file mode 100644 index 000000000..9d628ba42 --- /dev/null +++ b/src/WireMock.Net.MimePart/Models/MimeEntityDataWrapper.cs @@ -0,0 +1,54 @@ +// Copyright © WireMock.Net + +using System; +using System.Collections.Generic; +using System.Linq; +using MimeKit; +using Stef.Validation; + +namespace WireMock.Models +{ + /// + /// A wrapper class that implements the > interface by wrapping an interface. + /// + /// + /// This class provides a simplified, read-only view of an . + /// + public class MimeEntityDataWrapper : IMimeEntityData + { + private readonly IMimeEntity _entity; + + /// + /// Initializes a new instance of the class. + /// + /// The MIME entity to wrap. + /// + /// is . + /// + public MimeEntityDataWrapper(IMimeEntity entity) + { + _entity = Guard.NotNull(entity); + } + + /// + public IEnumerable Headers => _entity.Headers.Select(h => h.ToString()); + + /// + public string ContentDisposition => _entity.ContentDisposition.ToString(); + + /// + public string ContentType => _entity.ContentType.ToString(); + + /// + public Uri ContentBase => _entity.ContentBase; + + /// + public Uri ContentLocation => _entity.ContentLocation; + + /// + public string ContentId => _entity.ContentId; + + /// + public bool IsAttachment => _entity.IsAttachment; + } +} diff --git a/src/WireMock.Net.MimePart/Models/MimeMessageDataWrapper.cs b/src/WireMock.Net.MimePart/Models/MimeMessageDataWrapper.cs index 14891f987..219e1f754 100644 --- a/src/WireMock.Net.MimePart/Models/MimeMessageDataWrapper.cs +++ b/src/WireMock.Net.MimePart/Models/MimeMessageDataWrapper.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; +using System.Linq; using MimeKit; using Stef.Validation; @@ -21,16 +22,13 @@ internal class MimeMessageDataWrapper : IMimeMessageData /// Initializes a new instance of the class. /// /// The MIME message to wrap. - /// - /// is . - /// public MimeMessageDataWrapper(IMimeMessage message) { Message = Guard.NotNull(message); } /// - public IEnumerable Headers => Message.Headers; + public IEnumerable Headers => Message.Headers.Select(h => h.ToString()); /// public int Importance => (int)Message.Importance; @@ -42,40 +40,40 @@ public MimeMessageDataWrapper(IMimeMessage message) public int XPriority => (int)Message.XPriority; /// - public object Sender => Message.Sender; + public string Sender => Message.Sender.Address; /// - public object ResentSender => Message.ResentSender; + public string ResentSender => Message.ResentSender.ToString(); /// - public object From => Message.From; + public IEnumerable From => Message.From.Select(h => h.ToString()); /// - public object ResentFrom => Message.ResentFrom; + public IEnumerable ResentFrom => Message.ResentFrom.Select(h => h.ToString()); /// - public object ReplyTo => Message.ReplyTo; + public IEnumerable ReplyTo => Message.ReplyTo.Select(h => h.ToString()); /// - public object ResentReplyTo => Message.ResentReplyTo; + public IEnumerable ResentReplyTo => Message.ResentReplyTo.Select(h => h.ToString()); /// - public object To => Message.To; + public IEnumerable To => Message.To.Select(h => h.ToString()); /// - public object ResentTo => Message.ResentTo; + public IEnumerable ResentTo => Message.ResentTo.Select(h => h.ToString()); /// - public object Cc => Message.Cc; + public IEnumerable Cc => Message.Cc.Select(h => h.ToString()); /// - public object ResentCc => Message.ResentCc; + public IEnumerable ResentCc => Message.ResentCc.Select(h => h.ToString()); /// - public object Bcc => Message.Bcc; + public IEnumerable Bcc => Message.Bcc.Select(h => h.ToString()); /// - public object ResentBcc => Message.ResentBcc; + public IEnumerable ResentBcc => Message.ResentBcc.Select(h => h.ToString()); /// public string Subject => Message.Subject; @@ -102,7 +100,7 @@ public MimeMessageDataWrapper(IMimeMessage message) public Version MimeVersion => Message.MimeVersion; /// - public object Body => Message.Body; + public IMimeEntityData Body => new MimeEntityDataWrapper(Message.Body); /// public string TextBody => Message.TextBody; @@ -111,8 +109,8 @@ public MimeMessageDataWrapper(IMimeMessage message) public string HtmlBody => Message.HtmlBody; /// - public IEnumerable BodyParts => Message.BodyParts; + public IEnumerable BodyParts => Message.BodyParts.OfType().Select(mp => new MimePartDataWrapper(mp)); /// - public IEnumerable Attachments => Message.Attachments; + public IEnumerable Attachments => Message.Attachments.Select(me => new MimeEntityDataWrapper(me)); } \ No newline at end of file diff --git a/src/WireMock.Net.MimePart/Models/MimePartDataWrapper.cs b/src/WireMock.Net.MimePart/Models/MimePartDataWrapper.cs new file mode 100644 index 000000000..fe9936962 --- /dev/null +++ b/src/WireMock.Net.MimePart/Models/MimePartDataWrapper.cs @@ -0,0 +1,48 @@ +// Copyright © WireMock.Net + +using MimeKit; +using Stef.Validation; + +namespace WireMock.Models +{ + /// + /// A wrapper class that implements the > interface by wrapping an interface. + /// + /// + /// This class provides a simplified, read-only view of an . + /// + public class MimePartDataWrapper : MimeEntityDataWrapper, IMimePartData + { + private readonly IMimePart _part; + + /// + /// Initializes a new instance of the class. + /// + /// The MIME part to wrap. + /// + /// is . + /// + public MimePartDataWrapper(IMimePart part) : base(part) + { + _part = Guard.NotNull(part); + } + + /// + public string ContentDescription => _part.ContentDescription; + + /// + public int? ContentDuration => _part.ContentDuration; + + /// + public string ContentMd5 => _part.ContentMd5; + + /// + public int ContentTransferEncoding => (int)_part.ContentTransferEncoding; + + /// + public string FileName => _part.FileName; + + /// + public object Content => _part.Content; + } +} \ No newline at end of file diff --git a/src/WireMock.Net.Shared/Models/IMimeEntityData.cs b/src/WireMock.Net.Shared/Models/IMimeEntityData.cs new file mode 100644 index 000000000..80d88928f --- /dev/null +++ b/src/WireMock.Net.Shared/Models/IMimeEntityData.cs @@ -0,0 +1,55 @@ +// Copyright © WireMock.Net + +using System; +using System.Collections.Generic; + +namespace WireMock.Models +{ + /// + /// A simplified interface exposing the public, readable properties of MimeEntity. + /// + public interface IMimeEntityData + { + /// + /// Get the list of headers. + /// + /// The list of headers. + IEnumerable Headers { get; } + + /// + /// Get the content disposition. + /// + /// The content disposition. + string ContentDisposition { get; } + + /// + /// Get the type of the content. + /// + /// The type of the content. + string ContentType { get; } + + /// + /// Get the base content URI. + /// + /// The base content URI or . + Uri ContentBase { get; } + + /// + /// Get the content location. + /// + /// The content location or . + Uri ContentLocation { get; } + + /// + /// Get the Content-Id. + /// + /// The content identifier. + string ContentId { get; } + + /// + /// Get a value indicating whether this is an attachment. + /// + /// if this is an attachment; otherwise, . + bool IsAttachment { get; } + } +} \ No newline at end of file diff --git a/src/WireMock.Net.Shared/Models/IMimeMessageData.cs b/src/WireMock.Net.Shared/Models/IMimeMessageData.cs index b954b6ee6..02fd1171c 100644 --- a/src/WireMock.Net.Shared/Models/IMimeMessageData.cs +++ b/src/WireMock.Net.Shared/Models/IMimeMessageData.cs @@ -14,7 +14,7 @@ public interface IMimeMessageData /// Get the list of headers. /// /// The list of headers. - IEnumerable Headers { get; } + IEnumerable Headers { get; } /// /// Get the value of the Importance header. @@ -38,73 +38,73 @@ public interface IMimeMessageData /// Get the address in the Sender header. /// /// The address in the Sender header. - object Sender { get; } + string Sender { get; } /// /// Get the address in the Resent-Sender header. /// /// The address in the Resent-Sender header. - object ResentSender { get; } + string ResentSender { get; } /// /// Get the list of addresses in the From header. /// /// The list of addresses in the From header. - object From { get; } + IEnumerable From { get; } /// /// Get the list of addresses in the Resent-From header. /// /// The list of addresses in the Resent-From header. - object ResentFrom { get; } + IEnumerable ResentFrom { get; } /// /// Get the list of addresses in the Reply-To header. /// /// The list of addresses in the Reply-To header. - object ReplyTo { get; } + IEnumerable ReplyTo { get; } /// /// Get the list of addresses in the Resent-Reply-To header. /// /// The list of addresses in the Resent-Reply-To header. - object ResentReplyTo { get; } + IEnumerable ResentReplyTo { get; } /// /// Get the list of addresses in the To header. /// /// The list of addresses in the To header. - object To { get; } + IEnumerable To { get; } /// /// Get the list of addresses in the Resent-To header. /// /// The list of addresses in the Resent-To header. - object ResentTo { get; } + IEnumerable ResentTo { get; } /// /// Get the list of addresses in the Cc header. /// /// The list of addresses in the Cc header. - object Cc { get; } + IEnumerable Cc { get; } /// /// Get the list of addresses in the Resent-Cc header. /// /// The list of addresses in the Resent-Cc header. - object ResentCc { get; } + IEnumerable ResentCc { get; } /// /// Get the list of addresses in the Bcc header. /// /// The list of addresses in the Bcc header. - object Bcc { get; } + IEnumerable Bcc { get; } /// /// Get the list of addresses in the Resent-Bcc header. /// /// The list of addresses in the Resent-Bcc header. - object ResentBcc { get; } + IEnumerable ResentBcc { get; } /// /// Get the subject of the message. @@ -158,7 +158,7 @@ public interface IMimeMessageData /// Get the body of the message. /// /// The body of the message. - object Body { get; } + IMimeEntityData Body { get; } /// /// Get the text body of the message if it exists. @@ -176,11 +176,11 @@ public interface IMimeMessageData /// Get the body parts of the message. /// /// The body parts. - IEnumerable BodyParts { get; } + IEnumerable BodyParts { get; } /// /// Get the attachments. /// /// The attachments. - IEnumerable Attachments { get; } + IEnumerable Attachments { get; } } \ No newline at end of file diff --git a/src/WireMock.Net.Shared/Models/IMimePartData.cs b/src/WireMock.Net.Shared/Models/IMimePartData.cs new file mode 100644 index 000000000..16cc73abc --- /dev/null +++ b/src/WireMock.Net.Shared/Models/IMimePartData.cs @@ -0,0 +1,46 @@ +// Copyright © WireMock.Net + +namespace WireMock.Models +{ + /// + /// A simplified interface exposing the public, readable properties of MimePart. + /// + public interface IMimePartData : IMimeEntityData + { + /// + /// Get the description of the content if available. + /// + /// The description of the content. + string ContentDescription { get; } + + /// + /// Get the duration of the content if available. + /// + /// The duration of the content. + int? ContentDuration { get; } + + /// + /// Get the md5sum of the content. + /// + /// The md5sum of the content. + string ContentMd5 { get; } + + /// + /// Get the content transfer encoding. + /// + /// The content transfer encoding as an integer. + int ContentTransferEncoding { get; } + + /// + /// Get the name of the file. + /// + /// The name of the file. + string FileName { get; } + + /// + /// Get the MIME content. + /// + /// The MIME content. + object Content { get; } + } +} From 3b98b36432492d50cef2c589a236306ba2587c4e Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Fri, 11 Jul 2025 08:37:36 +0200 Subject: [PATCH 05/18] v2 --- .../Models/MimeEntityDataWrapper.cs | 67 +++++++------- .../Models/MimePartDataWrapper.cs | 65 ++++++------- .../Models/IMimeEntityData.cs | 91 +++++++++--------- .../Models/IMimePartData.cs | 92 ++++++++++--------- 4 files changed, 163 insertions(+), 152 deletions(-) diff --git a/src/WireMock.Net.MimePart/Models/MimeEntityDataWrapper.cs b/src/WireMock.Net.MimePart/Models/MimeEntityDataWrapper.cs index 9d628ba42..12ed085b8 100644 --- a/src/WireMock.Net.MimePart/Models/MimeEntityDataWrapper.cs +++ b/src/WireMock.Net.MimePart/Models/MimeEntityDataWrapper.cs @@ -6,49 +6,48 @@ using MimeKit; using Stef.Validation; -namespace WireMock.Models +namespace WireMock.Models; + +/// +/// A wrapper class that implements the > interface by wrapping an interface. +/// +/// +/// This class provides a simplified, read-only view of an . +/// +public class MimeEntityDataWrapper : IMimeEntityData { + private readonly IMimeEntity _entity; + /// - /// A wrapper class that implements the > interface by wrapping an interface. + /// Initializes a new instance of the class. /// - /// - /// This class provides a simplified, read-only view of an . - /// - public class MimeEntityDataWrapper : IMimeEntityData + /// The MIME entity to wrap. + /// + /// is . + /// + public MimeEntityDataWrapper(IMimeEntity entity) { - private readonly IMimeEntity _entity; - - /// - /// Initializes a new instance of the class. - /// - /// The MIME entity to wrap. - /// - /// is . - /// - public MimeEntityDataWrapper(IMimeEntity entity) - { - _entity = Guard.NotNull(entity); - } + _entity = Guard.NotNull(entity); + } - /// - public IEnumerable Headers => _entity.Headers.Select(h => h.ToString()); + /// + public IEnumerable Headers => _entity.Headers.Select(h => h.ToString()); - /// - public string ContentDisposition => _entity.ContentDisposition.ToString(); + /// + public string ContentDisposition => _entity.ContentDisposition.ToString(); - /// - public string ContentType => _entity.ContentType.ToString(); + /// + public string ContentType => _entity.ContentType.ToString(); - /// - public Uri ContentBase => _entity.ContentBase; + /// + public Uri ContentBase => _entity.ContentBase; - /// - public Uri ContentLocation => _entity.ContentLocation; + /// + public Uri ContentLocation => _entity.ContentLocation; - /// - public string ContentId => _entity.ContentId; + /// + public string ContentId => _entity.ContentId; - /// - public bool IsAttachment => _entity.IsAttachment; - } + /// + public bool IsAttachment => _entity.IsAttachment; } diff --git a/src/WireMock.Net.MimePart/Models/MimePartDataWrapper.cs b/src/WireMock.Net.MimePart/Models/MimePartDataWrapper.cs index fe9936962..af811c183 100644 --- a/src/WireMock.Net.MimePart/Models/MimePartDataWrapper.cs +++ b/src/WireMock.Net.MimePart/Models/MimePartDataWrapper.cs @@ -1,48 +1,51 @@ // Copyright © WireMock.Net +using System.IO; using MimeKit; using Stef.Validation; -namespace WireMock.Models +namespace WireMock.Models; + +/// +/// A wrapper class that implements the > interface by wrapping an interface. +/// +/// +/// This class provides a simplified, read-only view of an . +/// +public class MimePartDataWrapper : MimeEntityDataWrapper, IMimePartData { + private readonly IMimePart _part; + /// - /// A wrapper class that implements the > interface by wrapping an interface. + /// Initializes a new instance of the class. /// - /// - /// This class provides a simplified, read-only view of an . - /// - public class MimePartDataWrapper : MimeEntityDataWrapper, IMimePartData + /// The MIME part to wrap. + /// + /// is . + /// + public MimePartDataWrapper(IMimePart part) : base(part) { - private readonly IMimePart _part; + _part = Guard.NotNull(part); + } - /// - /// Initializes a new instance of the class. - /// - /// The MIME part to wrap. - /// - /// is . - /// - public MimePartDataWrapper(IMimePart part) : base(part) - { - _part = Guard.NotNull(part); - } + /// + public string ContentDescription => _part.ContentDescription; - /// - public string ContentDescription => _part.ContentDescription; + /// + public int? ContentDuration => _part.ContentDuration; - /// - public int? ContentDuration => _part.ContentDuration; + /// + public string ContentMd5 => _part.ContentMd5; - /// - public string ContentMd5 => _part.ContentMd5; + /// + public int ContentTransferEncoding => (int)_part.ContentTransferEncoding; - /// - public int ContentTransferEncoding => (int)_part.ContentTransferEncoding; + /// + public string FileName => _part.FileName; - /// - public string FileName => _part.FileName; + /// + public object Content => _part.Content; - /// - public object Content => _part.Content; - } + /// + public Stream Open() => _part.Content.Open(); } \ No newline at end of file diff --git a/src/WireMock.Net.Shared/Models/IMimeEntityData.cs b/src/WireMock.Net.Shared/Models/IMimeEntityData.cs index 80d88928f..224a810bf 100644 --- a/src/WireMock.Net.Shared/Models/IMimeEntityData.cs +++ b/src/WireMock.Net.Shared/Models/IMimeEntityData.cs @@ -3,53 +3,52 @@ using System; using System.Collections.Generic; -namespace WireMock.Models +namespace WireMock.Models; + +/// +/// A simplified interface exposing the public, readable properties of MimeEntity. +/// +public interface IMimeEntityData { /// - /// A simplified interface exposing the public, readable properties of MimeEntity. + /// Get the list of headers. + /// + /// The list of headers. + IEnumerable Headers { get; } + + /// + /// Get the content disposition. + /// + /// The content disposition. + string ContentDisposition { get; } + + /// + /// Get the type of the content. + /// + /// The type of the content. + string ContentType { get; } + + /// + /// Get the base content URI. + /// + /// The base content URI or . + Uri ContentBase { get; } + + /// + /// Get the content location. + /// + /// The content location or . + Uri ContentLocation { get; } + + /// + /// Get the Content-Id. + /// + /// The content identifier. + string ContentId { get; } + + /// + /// Get a value indicating whether this is an attachment. /// - public interface IMimeEntityData - { - /// - /// Get the list of headers. - /// - /// The list of headers. - IEnumerable Headers { get; } - - /// - /// Get the content disposition. - /// - /// The content disposition. - string ContentDisposition { get; } - - /// - /// Get the type of the content. - /// - /// The type of the content. - string ContentType { get; } - - /// - /// Get the base content URI. - /// - /// The base content URI or . - Uri ContentBase { get; } - - /// - /// Get the content location. - /// - /// The content location or . - Uri ContentLocation { get; } - - /// - /// Get the Content-Id. - /// - /// The content identifier. - string ContentId { get; } - - /// - /// Get a value indicating whether this is an attachment. - /// - /// if this is an attachment; otherwise, . - bool IsAttachment { get; } - } + /// if this is an attachment; otherwise, . + bool IsAttachment { get; } } \ No newline at end of file diff --git a/src/WireMock.Net.Shared/Models/IMimePartData.cs b/src/WireMock.Net.Shared/Models/IMimePartData.cs index 16cc73abc..0ca55c57a 100644 --- a/src/WireMock.Net.Shared/Models/IMimePartData.cs +++ b/src/WireMock.Net.Shared/Models/IMimePartData.cs @@ -1,46 +1,56 @@ // Copyright © WireMock.Net -namespace WireMock.Models +using System.IO; + +namespace WireMock.Models; + +/// +/// A simplified interface exposing the public, readable properties of MimePart. +/// +public interface IMimePartData : IMimeEntityData { /// - /// A simplified interface exposing the public, readable properties of MimePart. + /// Get the description of the content if available. + /// + /// The description of the content. + string ContentDescription { get; } + + /// + /// Get the duration of the content if available. + /// + /// The duration of the content. + int? ContentDuration { get; } + + /// + /// Get the md5sum of the content. + /// + /// The md5sum of the content. + string ContentMd5 { get; } + + /// + /// Get the content transfer encoding. + /// + /// The content transfer encoding as an integer. + int ContentTransferEncoding { get; } + + /// + /// Get the name of the file. + /// + /// The name of the file. + string FileName { get; } + + /// + /// Get the MIME content. + /// + /// The MIME content. + object Content { get; } + + /// + /// Open the decoded content stream. /// - public interface IMimePartData : IMimeEntityData - { - /// - /// Get the description of the content if available. - /// - /// The description of the content. - string ContentDescription { get; } - - /// - /// Get the duration of the content if available. - /// - /// The duration of the content. - int? ContentDuration { get; } - - /// - /// Get the md5sum of the content. - /// - /// The md5sum of the content. - string ContentMd5 { get; } - - /// - /// Get the content transfer encoding. - /// - /// The content transfer encoding as an integer. - int ContentTransferEncoding { get; } - - /// - /// Get the name of the file. - /// - /// The name of the file. - string FileName { get; } - - /// - /// Get the MIME content. - /// - /// The MIME content. - object Content { get; } - } -} + /// + /// Provides a means of reading the decoded content without having to first write it to another stream. + /// + /// The decoded content stream. + Stream Open(); +} \ No newline at end of file From 03ff95efe2582bf39411cab84eabc5825ec49f36 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Fri, 11 Jul 2025 09:17:50 +0200 Subject: [PATCH 06/18] e --- .../Matchers/MimePartMatcher.cs | 17 ++++++------- .../Models/MimeMessageDataWrapper.cs | 2 +- .../Models/MimePartDataWrapper.cs | 8 ++++++- .../Util/MimeKitUtils.cs | 24 +++++++++---------- .../Request/RequestMessageMultiPartMatcher.cs | 4 +++- .../Matchers/IMimePartMatcher.cs | 4 +++- .../Models/IMimeMessageData.cs | 4 ++-- .../Models/IMimePartData.cs | 3 ++- src/WireMock.Net.Shared/Util/IMimeKitUtils.cs | 12 +++++----- 9 files changed, 45 insertions(+), 33 deletions(-) diff --git a/src/WireMock.Net.MimePart/Matchers/MimePartMatcher.cs b/src/WireMock.Net.MimePart/Matchers/MimePartMatcher.cs index 6ad739ffa..35ca9b823 100644 --- a/src/WireMock.Net.MimePart/Matchers/MimePartMatcher.cs +++ b/src/WireMock.Net.MimePart/Matchers/MimePartMatcher.cs @@ -3,6 +3,7 @@ using System; using MimeKit; using WireMock.Matchers.Helpers; +using WireMock.Models; using WireMock.Util; namespace WireMock.Matchers; @@ -12,7 +13,7 @@ namespace WireMock.Matchers; /// public class MimePartMatcher : IMimePartMatcher { - private readonly Func[] _funcs; + private readonly Func[] _funcs; /// public string Name => nameof(MimePartMatcher); @@ -51,7 +52,7 @@ public MimePartMatcher( _funcs = [ - mp => ContentTypeMatcher?.IsMatch(GetContentTypeAsString(mp.ContentType)) ?? MatchScores.Perfect, + mp => ContentTypeMatcher?.IsMatch(GetContentTypeValue(mp.ContentType)) ?? MatchScores.Perfect, mp => ContentDispositionMatcher?.IsMatch(mp.ContentDisposition.ToString().Replace("Content-Disposition: ", string.Empty)) ?? MatchScores.Perfect, mp => ContentTransferEncodingMatcher?.IsMatch(mp.ContentTransferEncoding.ToString().ToLowerInvariant()) ?? MatchScores.Perfect, MatchOnContent @@ -59,14 +60,14 @@ public MimePartMatcher( } /// - public MatchResult IsMatch(object value) + public MatchResult IsMatch(IMimePartData value) { var score = MatchScores.Mismatch; Exception? exception = null; try { - if (value is MimePart mimePart && Array.TrueForAll(_funcs, func => func(mimePart).IsPerfect())) + if (value is IMimePartData mimePart && Array.TrueForAll(_funcs, func => func(mimePart).IsPerfect())) { score = MatchScores.Perfect; } @@ -85,7 +86,7 @@ public string GetCSharpCodeArguments() return "NotImplemented"; } - private MatchResult MatchOnContent(MimePart mimePart) + private MatchResult MatchOnContent(IMimePartData mimePart) { if (ContentMatcher == null) { @@ -94,8 +95,8 @@ private MatchResult MatchOnContent(MimePart mimePart) var bodyParserSettings = new BodyParserSettings { - Stream = mimePart.Content.Open(), - ContentType = GetContentTypeAsString(mimePart.ContentType), + Stream = mimePart.Open(), + ContentType = GetContentTypeValue(mimePart.ContentType), DeserializeJson = true, ContentEncoding = null, // mimePart.ContentType.CharsetEncoding.ToString(), DecompressGZipAndDeflate = true @@ -105,7 +106,7 @@ private MatchResult MatchOnContent(MimePart mimePart) return BodyDataMatchScoreCalculator.CalculateMatchScore(bodyData, ContentMatcher); } - private static string? GetContentTypeAsString(ContentType? contentType) + private static string? GetContentTypeValue(string? contentType) { return contentType?.ToString().Replace("Content-Type: ", string.Empty); } diff --git a/src/WireMock.Net.MimePart/Models/MimeMessageDataWrapper.cs b/src/WireMock.Net.MimePart/Models/MimeMessageDataWrapper.cs index 219e1f754..d84dacac7 100644 --- a/src/WireMock.Net.MimePart/Models/MimeMessageDataWrapper.cs +++ b/src/WireMock.Net.MimePart/Models/MimeMessageDataWrapper.cs @@ -85,7 +85,7 @@ public MimeMessageDataWrapper(IMimeMessage message) public DateTimeOffset ResentDate => Message.ResentDate; /// - public IList References => Message.References; + public IEnumerable References => Message.References; /// public string InReplyTo => Message.InReplyTo; diff --git a/src/WireMock.Net.MimePart/Models/MimePartDataWrapper.cs b/src/WireMock.Net.MimePart/Models/MimePartDataWrapper.cs index af811c183..00cc7dcf6 100644 --- a/src/WireMock.Net.MimePart/Models/MimePartDataWrapper.cs +++ b/src/WireMock.Net.MimePart/Models/MimePartDataWrapper.cs @@ -1,5 +1,6 @@ // Copyright © WireMock.Net +using System.Collections.Generic; using System.IO; using MimeKit; using Stef.Validation; @@ -44,7 +45,12 @@ public MimePartDataWrapper(IMimePart part) : base(part) public string FileName => _part.FileName; /// - public object Content => _part.Content; + public IDictionary Content => new Dictionary() + { + { nameof(MimePart.Content.Encoding), _part.Content.Encoding }, + { nameof(MimePart.Content.NewLineFormat), _part.Content.NewLineFormat }, + { nameof(MimePart.Content.Stream), _part.Content.Stream } + }; /// public Stream Open() => _part.Content.Open(); diff --git a/src/WireMock.Net.MimePart/Util/MimeKitUtils.cs b/src/WireMock.Net.MimePart/Util/MimeKitUtils.cs index 6a9d8b5ae..e855ef283 100644 --- a/src/WireMock.Net.MimePart/Util/MimeKitUtils.cs +++ b/src/WireMock.Net.MimePart/Util/MimeKitUtils.cs @@ -53,18 +53,18 @@ public bool TryGetMimeMessage(IRequestMessage requestMessage, [NotNullWhen(true) return false; } - /// - public IReadOnlyList GetBodyParts(IMimeMessageData mimeMessageData) - { - if (mimeMessageData is not MimeMessageDataWrapper wrapper) - { - throw new ArgumentException($"The mimeMessageData must be of type {nameof(MimeMessageDataWrapper)}", nameof(mimeMessageData)); - } - - return wrapper.Message.BodyParts - .OfType() - .ToArray(); - } + ///// + //public IReadOnlyList GetBodyParts(IMimeMessageData mimeMessageData) + //{ + // if (mimeMessageData is not MimeMessageDataWrapper wrapper) + // { + // throw new ArgumentException($"The mimeMessageData must be of type {nameof(MimeMessageDataWrapper)}", nameof(mimeMessageData)); + // } + + // return wrapper.Message.BodyParts + // .OfType() + // .ToArray(); + //} private static bool StartsWithMultiPart(WireMockList contentTypeHeader) { diff --git a/src/WireMock.Net.Minimal/Matchers/Request/RequestMessageMultiPartMatcher.cs b/src/WireMock.Net.Minimal/Matchers/Request/RequestMessageMultiPartMatcher.cs index 6ec3934d2..f93fa2452 100644 --- a/src/WireMock.Net.Minimal/Matchers/Request/RequestMessageMultiPartMatcher.cs +++ b/src/WireMock.Net.Minimal/Matchers/Request/RequestMessageMultiPartMatcher.cs @@ -72,7 +72,9 @@ public double GetMatchingScore(IRequestMessage requestMessage, IRequestMatchResu foreach (var mimePartMatcher in Matchers.OfType().ToArray()) { score = MatchScores.Mismatch; - foreach (var mimeBodyPart in MimeKitUtils.GetBodyParts(message)) + + //foreach (var mimeBodyPart in MimeKitUtils.GetBodyParts(message)) + foreach (var mimeBodyPart in message.BodyParts) { var matchResult = mimePartMatcher.IsMatch(mimeBodyPart); if (matchResult.IsPerfect()) diff --git a/src/WireMock.Net.Shared/Matchers/IMimePartMatcher.cs b/src/WireMock.Net.Shared/Matchers/IMimePartMatcher.cs index 37fa21688..2aa263cff 100644 --- a/src/WireMock.Net.Shared/Matchers/IMimePartMatcher.cs +++ b/src/WireMock.Net.Shared/Matchers/IMimePartMatcher.cs @@ -1,5 +1,7 @@ // Copyright © WireMock.Net +using WireMock.Models; + namespace WireMock.Matchers; /// @@ -33,5 +35,5 @@ public interface IMimePartMatcher : IMatcher /// /// The MimePart. /// A value between 0.0 - 1.0 of the similarity. - public MatchResult IsMatch(object value); + public MatchResult IsMatch(IMimePartData value); } \ No newline at end of file diff --git a/src/WireMock.Net.Shared/Models/IMimeMessageData.cs b/src/WireMock.Net.Shared/Models/IMimeMessageData.cs index 02fd1171c..4be8f33d4 100644 --- a/src/WireMock.Net.Shared/Models/IMimeMessageData.cs +++ b/src/WireMock.Net.Shared/Models/IMimeMessageData.cs @@ -105,7 +105,7 @@ public interface IMimeMessageData /// /// The list of addresses in the Resent-Bcc header. IEnumerable ResentBcc { get; } - + /// /// Get the subject of the message. /// @@ -128,7 +128,7 @@ public interface IMimeMessageData /// Get the list of references to other messages. /// /// The references. - IList References { get; } + IEnumerable References { get; } /// /// Get the Message-Id that this message is replying to. diff --git a/src/WireMock.Net.Shared/Models/IMimePartData.cs b/src/WireMock.Net.Shared/Models/IMimePartData.cs index 0ca55c57a..157c0eb75 100644 --- a/src/WireMock.Net.Shared/Models/IMimePartData.cs +++ b/src/WireMock.Net.Shared/Models/IMimePartData.cs @@ -1,5 +1,6 @@ // Copyright © WireMock.Net +using System.Collections.Generic; using System.IO; namespace WireMock.Models; @@ -43,7 +44,7 @@ public interface IMimePartData : IMimeEntityData /// Get the MIME content. /// /// The MIME content. - object Content { get; } + IDictionary Content { get; } /// /// Open the decoded content stream. diff --git a/src/WireMock.Net.Shared/Util/IMimeKitUtils.cs b/src/WireMock.Net.Shared/Util/IMimeKitUtils.cs index a20a18e35..9625c3ce0 100644 --- a/src/WireMock.Net.Shared/Util/IMimeKitUtils.cs +++ b/src/WireMock.Net.Shared/Util/IMimeKitUtils.cs @@ -27,10 +27,10 @@ public interface IMimeKitUtils /// true when parsed correctly, else false bool TryGetMimeMessage(IRequestMessage requestMessage, [NotNullWhen(true)] out IMimeMessageData? mimeMessageData); - /// - /// Gets the body parts from the MimeKit.MimeMessage. - /// - /// The MimeKit.MimeMessage. - /// A list of MimeParts. - IReadOnlyList GetBodyParts(IMimeMessageData mimeMessageData); + ///// + ///// Gets the body parts from the MimeKit.MimeMessage. + ///// + ///// The MimeKit.MimeMessage. + ///// A list of MimeParts. + //IReadOnlyList GetBodyParts(IMimeMessageData mimeMessageData); } \ No newline at end of file From 141e60d6779be0659b8130e88a737750eed32888 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Fri, 11 Jul 2025 09:36:12 +0200 Subject: [PATCH 07/18] ? --- .../Models/IMimeEntityData.cs | 2 +- .../Models/IMimeMessageData.cs | 28 +++---- .../Models/IMimePartData.cs | 0 .../Models/MimeEntityDataWrapper.cs | 7 +- .../Models/MimeMessageDataWrapper.cs | 79 +++++++++++-------- .../Matchers/MimePartMatcherTests.cs | 6 +- 6 files changed, 69 insertions(+), 53 deletions(-) rename src/{WireMock.Net.Shared => WireMock.Net.Abstractions}/Models/IMimeEntityData.cs (97%) rename src/{WireMock.Net.Shared => WireMock.Net.Abstractions}/Models/IMimeMessageData.cs (89%) rename src/{WireMock.Net.Shared => WireMock.Net.Abstractions}/Models/IMimePartData.cs (100%) diff --git a/src/WireMock.Net.Shared/Models/IMimeEntityData.cs b/src/WireMock.Net.Abstractions/Models/IMimeEntityData.cs similarity index 97% rename from src/WireMock.Net.Shared/Models/IMimeEntityData.cs rename to src/WireMock.Net.Abstractions/Models/IMimeEntityData.cs index 224a810bf..ea0b2cc03 100644 --- a/src/WireMock.Net.Shared/Models/IMimeEntityData.cs +++ b/src/WireMock.Net.Abstractions/Models/IMimeEntityData.cs @@ -14,7 +14,7 @@ public interface IMimeEntityData /// Get the list of headers. /// /// The list of headers. - IEnumerable Headers { get; } + IList Headers { get; } /// /// Get the content disposition. diff --git a/src/WireMock.Net.Shared/Models/IMimeMessageData.cs b/src/WireMock.Net.Abstractions/Models/IMimeMessageData.cs similarity index 89% rename from src/WireMock.Net.Shared/Models/IMimeMessageData.cs rename to src/WireMock.Net.Abstractions/Models/IMimeMessageData.cs index 4be8f33d4..d7eea95a2 100644 --- a/src/WireMock.Net.Shared/Models/IMimeMessageData.cs +++ b/src/WireMock.Net.Abstractions/Models/IMimeMessageData.cs @@ -14,7 +14,7 @@ public interface IMimeMessageData /// Get the list of headers. /// /// The list of headers. - IEnumerable Headers { get; } + IList Headers { get; } /// /// Get the value of the Importance header. @@ -50,61 +50,61 @@ public interface IMimeMessageData /// Get the list of addresses in the From header. /// /// The list of addresses in the From header. - IEnumerable From { get; } + IList From { get; } /// /// Get the list of addresses in the Resent-From header. /// /// The list of addresses in the Resent-From header. - IEnumerable ResentFrom { get; } + IList ResentFrom { get; } /// /// Get the list of addresses in the Reply-To header. /// /// The list of addresses in the Reply-To header. - IEnumerable ReplyTo { get; } + IList ReplyTo { get; } /// /// Get the list of addresses in the Resent-Reply-To header. /// /// The list of addresses in the Resent-Reply-To header. - IEnumerable ResentReplyTo { get; } + IList ResentReplyTo { get; } /// /// Get the list of addresses in the To header. /// /// The list of addresses in the To header. - IEnumerable To { get; } + IList To { get; } /// /// Get the list of addresses in the Resent-To header. /// /// The list of addresses in the Resent-To header. - IEnumerable ResentTo { get; } + IList ResentTo { get; } /// /// Get the list of addresses in the Cc header. /// /// The list of addresses in the Cc header. - IEnumerable Cc { get; } + IList Cc { get; } /// /// Get the list of addresses in the Resent-Cc header. /// /// The list of addresses in the Resent-Cc header. - IEnumerable ResentCc { get; } + IList ResentCc { get; } /// /// Get the list of addresses in the Bcc header. /// /// The list of addresses in the Bcc header. - IEnumerable Bcc { get; } + IList Bcc { get; } /// /// Get the list of addresses in the Resent-Bcc header. /// /// The list of addresses in the Resent-Bcc header. - IEnumerable ResentBcc { get; } + IList ResentBcc { get; } /// /// Get the subject of the message. @@ -128,7 +128,7 @@ public interface IMimeMessageData /// Get the list of references to other messages. /// /// The references. - IEnumerable References { get; } + IList References { get; } /// /// Get the Message-Id that this message is replying to. @@ -176,11 +176,11 @@ public interface IMimeMessageData /// Get the body parts of the message. /// /// The body parts. - IEnumerable BodyParts { get; } + IList BodyParts { get; } /// /// Get the attachments. /// /// The attachments. - IEnumerable Attachments { get; } + IList Attachments { get; } } \ No newline at end of file diff --git a/src/WireMock.Net.Shared/Models/IMimePartData.cs b/src/WireMock.Net.Abstractions/Models/IMimePartData.cs similarity index 100% rename from src/WireMock.Net.Shared/Models/IMimePartData.cs rename to src/WireMock.Net.Abstractions/Models/IMimePartData.cs diff --git a/src/WireMock.Net.MimePart/Models/MimeEntityDataWrapper.cs b/src/WireMock.Net.MimePart/Models/MimeEntityDataWrapper.cs index 12ed085b8..01082e81b 100644 --- a/src/WireMock.Net.MimePart/Models/MimeEntityDataWrapper.cs +++ b/src/WireMock.Net.MimePart/Models/MimeEntityDataWrapper.cs @@ -22,16 +22,15 @@ public class MimeEntityDataWrapper : IMimeEntityData /// Initializes a new instance of the class. /// /// The MIME entity to wrap. - /// - /// is . - /// public MimeEntityDataWrapper(IMimeEntity entity) { _entity = Guard.NotNull(entity); + + Headers = _entity.Headers.Select(h => h.ToString()).ToList(); } /// - public IEnumerable Headers => _entity.Headers.Select(h => h.ToString()); + public IList Headers { get; private set; } /// public string ContentDisposition => _entity.ContentDisposition.ToString(); diff --git a/src/WireMock.Net.MimePart/Models/MimeMessageDataWrapper.cs b/src/WireMock.Net.MimePart/Models/MimeMessageDataWrapper.cs index d84dacac7..154f61192 100644 --- a/src/WireMock.Net.MimePart/Models/MimeMessageDataWrapper.cs +++ b/src/WireMock.Net.MimePart/Models/MimeMessageDataWrapper.cs @@ -16,7 +16,7 @@ namespace WireMock.Models; /// internal class MimeMessageDataWrapper : IMimeMessageData { - public IMimeMessage Message { get; } + private readonly IMimeMessage _message; /// /// Initializes a new instance of the class. @@ -24,93 +24,110 @@ internal class MimeMessageDataWrapper : IMimeMessageData /// The MIME message to wrap. public MimeMessageDataWrapper(IMimeMessage message) { - Message = Guard.NotNull(message); + _message = Guard.NotNull(message); + + Bcc = _message.Bcc.Select(h => h.ToString()).ToList(); + Cc = _message.Cc.Select(h => h.ToString()).ToList(); + From = _message.From.Select(h => h.ToString()).ToList(); + Headers = _message.Headers.Select(h => h.ToString()).ToList(); + References = _message.References.ToList(); + ReplyTo = _message.ReplyTo.Select(h => h.ToString()).ToList(); + ResentBcc = _message.ResentBcc.Select(h => h.ToString()).ToList(); + ResentCc = _message.ResentCc.Select(h => h.ToString()).ToList(); + ResentFrom = _message.ResentFrom.Select(h => h.ToString()).ToList(); + ResentReplyTo = _message.ResentReplyTo.Select(h => h.ToString()).ToList(); + ResentTo = _message.ResentTo.Select(h => h.ToString()).ToList(); + To = _message.To.Select(h => h.ToString()).ToList(); + + Body = new MimeEntityDataWrapper(_message.Body); + BodyParts = _message.BodyParts.OfType().Select(mp => new MimePartDataWrapper(mp)).ToList(); + Attachments = _message.Attachments.Select(me => new MimeEntityDataWrapper(me)).ToList(); } /// - public IEnumerable Headers => Message.Headers.Select(h => h.ToString()); + public IList Headers { get; private set; } /// - public int Importance => (int)Message.Importance; + public int Importance => (int)_message.Importance; /// - public int Priority => (int)Message.Priority; + public int Priority => (int)_message.Priority; /// - public int XPriority => (int)Message.XPriority; + public int XPriority => (int)_message.XPriority; /// - public string Sender => Message.Sender.Address; + public string Sender => _message.Sender.Address; /// - public string ResentSender => Message.ResentSender.ToString(); + public string ResentSender => _message.ResentSender.ToString(); /// - public IEnumerable From => Message.From.Select(h => h.ToString()); + public IList From { get; private set; } /// - public IEnumerable ResentFrom => Message.ResentFrom.Select(h => h.ToString()); + public IList ResentFrom { get; private set; } /// - public IEnumerable ReplyTo => Message.ReplyTo.Select(h => h.ToString()); + public IList ReplyTo { get; private set; } /// - public IEnumerable ResentReplyTo => Message.ResentReplyTo.Select(h => h.ToString()); + public IList ResentReplyTo { get; private set; } /// - public IEnumerable To => Message.To.Select(h => h.ToString()); + public IList To { get; private set; } /// - public IEnumerable ResentTo => Message.ResentTo.Select(h => h.ToString()); + public IList ResentTo { get; private set; } /// - public IEnumerable Cc => Message.Cc.Select(h => h.ToString()); + public IList Cc { get; private set; } /// - public IEnumerable ResentCc => Message.ResentCc.Select(h => h.ToString()); + public IList ResentCc { get; private set; } /// - public IEnumerable Bcc => Message.Bcc.Select(h => h.ToString()); + public IList Bcc { get; private set; } /// - public IEnumerable ResentBcc => Message.ResentBcc.Select(h => h.ToString()); + public IList ResentBcc { get; private set; } /// - public string Subject => Message.Subject; + public string Subject => _message.Subject; /// - public DateTimeOffset Date => Message.Date; + public DateTimeOffset Date => _message.Date; /// - public DateTimeOffset ResentDate => Message.ResentDate; + public DateTimeOffset ResentDate => _message.ResentDate; /// - public IEnumerable References => Message.References; + public IList References { get; private set; } /// - public string InReplyTo => Message.InReplyTo; + public string InReplyTo => _message.InReplyTo; /// - public string MessageId => Message.MessageId; + public string MessageId => _message.MessageId; /// - public string ResentMessageId => Message.ResentMessageId; + public string ResentMessageId => _message.ResentMessageId; /// - public Version MimeVersion => Message.MimeVersion; + public Version MimeVersion => _message.MimeVersion; /// - public IMimeEntityData Body => new MimeEntityDataWrapper(Message.Body); + public IMimeEntityData Body { get; private set; } /// - public string TextBody => Message.TextBody; + public string TextBody => _message.TextBody; /// - public string HtmlBody => Message.HtmlBody; + public string HtmlBody => _message.HtmlBody; /// - public IEnumerable BodyParts => Message.BodyParts.OfType().Select(mp => new MimePartDataWrapper(mp)); + public IList BodyParts { get; private set; } /// - public IEnumerable Attachments => Message.Attachments.Select(me => new MimeEntityDataWrapper(me)); + public IList Attachments { get; private set; } } \ No newline at end of file diff --git a/test/WireMock.Net.Tests/Matchers/MimePartMatcherTests.cs b/test/WireMock.Net.Tests/Matchers/MimePartMatcherTests.cs index 2f9e02e34..c6b6596b8 100644 --- a/test/WireMock.Net.Tests/Matchers/MimePartMatcherTests.cs +++ b/test/WireMock.Net.Tests/Matchers/MimePartMatcherTests.cs @@ -48,7 +48,7 @@ public void MimePartMatcher_IsMatch_Part_TextPlain() { // Arrange var message = MimeKitUtils.LoadFromStream(StreamUtils.CreateStream(TestMultiPart)); - var part = MimeKitUtils.GetBodyParts(message)[0]; + var part = message.BodyParts[0]; // Act var contentTypeMatcher = new ContentTypeMatcher("text/plain"); @@ -67,7 +67,7 @@ public void MimePartMatcher_IsMatch_Part_TextJson() { // Arrange var message = MimeKitUtils.LoadFromStream(StreamUtils.CreateStream(TestMultiPart)); - var part = MimeKitUtils.GetBodyParts(message)[1]; + var part = message.BodyParts[1]; // Act var contentTypeMatcher = new ContentTypeMatcher("text/json"); @@ -85,7 +85,7 @@ public void MimePartMatcher_IsMatch_Part_ImagePng() { // Arrange var message = MimeKitUtils.LoadFromStream(StreamUtils.CreateStream(TestMultiPart)); - var part = MimeKitUtils.GetBodyParts(message)[2]; + var part = message.BodyParts[2]; // Act var contentTypeMatcher = new ContentTypeMatcher("image/png"); From 6440a7a96e71e662343cc5d6b4131ad22cdc7bf5 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Fri, 11 Jul 2025 16:29:55 +0200 Subject: [PATCH 08/18] fix --- .../Models/Mime/IContentDispositionData.cs | 59 ++++++++++++++++ .../Models/Mime/IContentTypeData.cs | 67 +++++++++++++++++++ .../Models/{ => Mime}/IMimeEntityData.cs | 6 +- .../Models/{ => Mime}/IMimeMessageData.cs | 2 +- .../Models/{ => Mime}/IMimePartData.cs | 6 +- .../Matchers/MimePartMatcher.cs | 14 ++-- .../Models/ContentDispositionDataWrapper.cs | 59 ++++++++++++++++ .../Models/ContentTypeDataWrapper.cs | 65 ++++++++++++++++++ .../Models/MimeEntityDataWrapper.cs | 13 +++- .../Models/MimeMessageDataWrapper.cs | 7 ++ .../Models/MimePartDataWrapper.cs | 9 ++- .../Util/MimeKitUtils.cs | 1 + .../Matchers/IMimePartMatcher.cs | 2 +- src/WireMock.Net.Shared/Util/IMimeKitUtils.cs | 2 +- 14 files changed, 293 insertions(+), 19 deletions(-) create mode 100644 src/WireMock.Net.Abstractions/Models/Mime/IContentDispositionData.cs create mode 100644 src/WireMock.Net.Abstractions/Models/Mime/IContentTypeData.cs rename src/WireMock.Net.Abstractions/Models/{ => Mime}/IMimeEntityData.cs (91%) rename src/WireMock.Net.Abstractions/Models/{ => Mime}/IMimeMessageData.cs (99%) rename src/WireMock.Net.Abstractions/Models/{ => Mime}/IMimePartData.cs (91%) create mode 100644 src/WireMock.Net.MimePart/Models/ContentDispositionDataWrapper.cs create mode 100644 src/WireMock.Net.MimePart/Models/ContentTypeDataWrapper.cs diff --git a/src/WireMock.Net.Abstractions/Models/Mime/IContentDispositionData.cs b/src/WireMock.Net.Abstractions/Models/Mime/IContentDispositionData.cs new file mode 100644 index 000000000..735e3cd2d --- /dev/null +++ b/src/WireMock.Net.Abstractions/Models/Mime/IContentDispositionData.cs @@ -0,0 +1,59 @@ +// Copyright © WireMock.Net + +using System; + +namespace WireMock.Models.Mime; + +/// +/// An interface exposing the public, readable properties of a ContentDisposition. +/// +public interface IContentDispositionData +{ + /// + /// Get the disposition. + /// + /// The disposition. + string Disposition { get; } + + /// + /// Get a value indicating whether the is an attachment. + /// + /// if the is an attachment; otherwise, . + bool IsAttachment { get; } + + /// + /// Get the list of parameters on the ContentDisposition. + /// + /// The parameters. + object Parameters { get; } + + /// + /// Get the name of the file. + /// + /// The name of the file. + string FileName { get; } + + /// + /// Get the creation-date parameter. + /// + /// The creation date. + DateTimeOffset? CreationDate { get; } + + /// + /// Get the modification-date parameter. + /// + /// The modification date. + DateTimeOffset? ModificationDate { get; } + + /// + /// Get the read-date parameter. + /// + /// The read date. + DateTimeOffset? ReadDate { get; } + + /// + /// Get the size parameter. + /// + /// The size. + long? Size { get; } +} \ No newline at end of file diff --git a/src/WireMock.Net.Abstractions/Models/Mime/IContentTypeData.cs b/src/WireMock.Net.Abstractions/Models/Mime/IContentTypeData.cs new file mode 100644 index 000000000..a5c4af5d2 --- /dev/null +++ b/src/WireMock.Net.Abstractions/Models/Mime/IContentTypeData.cs @@ -0,0 +1,67 @@ +// Copyright © WireMock.Net + +using System.Collections.Generic; +using System.Text; + +namespace WireMock.Models.Mime; + +/// +/// An interface exposing the public, readable properties of a ContentType +/// with complex types simplified to a generic object. +/// +public interface IContentTypeData +{ + /// + /// Get the type of the media. + /// + /// The type of the media. + string MediaType { get; } + + /// + /// Get the media subtype. + /// + /// The media subtype. + string MediaSubtype { get; } + + /// + /// Get the list of parameters on the ContentType. + /// + /// The parameters. + IList Parameters { get; } + + /// + /// Get the boundary parameter. + /// + /// The boundary. + string Boundary { get; } + + /// + /// Get the charset parameter. + /// + /// The charset. + string Charset { get; } + + /// + /// Get the charset parameter as an Encoding. + /// + /// The charset encoding. + Encoding CharsetEncoding { get; } + + /// + /// Get the format parameter. + /// + /// The format. + string Format { get; } + + /// + /// Get the simple mime-type. + /// + /// The mime-type. + string MimeType { get; } + + /// + /// Get the name parameter. + /// + /// The name. + string Name { get; } +} diff --git a/src/WireMock.Net.Abstractions/Models/IMimeEntityData.cs b/src/WireMock.Net.Abstractions/Models/Mime/IMimeEntityData.cs similarity index 91% rename from src/WireMock.Net.Abstractions/Models/IMimeEntityData.cs rename to src/WireMock.Net.Abstractions/Models/Mime/IMimeEntityData.cs index ea0b2cc03..004e5205f 100644 --- a/src/WireMock.Net.Abstractions/Models/IMimeEntityData.cs +++ b/src/WireMock.Net.Abstractions/Models/Mime/IMimeEntityData.cs @@ -3,7 +3,7 @@ using System; using System.Collections.Generic; -namespace WireMock.Models; +namespace WireMock.Models.Mime; /// /// A simplified interface exposing the public, readable properties of MimeEntity. @@ -20,13 +20,13 @@ public interface IMimeEntityData /// Get the content disposition. /// /// The content disposition. - string ContentDisposition { get; } + IContentDispositionData? ContentDisposition { get; } /// /// Get the type of the content. /// /// The type of the content. - string ContentType { get; } + IContentTypeData? ContentType { get; } /// /// Get the base content URI. diff --git a/src/WireMock.Net.Abstractions/Models/IMimeMessageData.cs b/src/WireMock.Net.Abstractions/Models/Mime/IMimeMessageData.cs similarity index 99% rename from src/WireMock.Net.Abstractions/Models/IMimeMessageData.cs rename to src/WireMock.Net.Abstractions/Models/Mime/IMimeMessageData.cs index d7eea95a2..391d01bd9 100644 --- a/src/WireMock.Net.Abstractions/Models/IMimeMessageData.cs +++ b/src/WireMock.Net.Abstractions/Models/Mime/IMimeMessageData.cs @@ -3,7 +3,7 @@ using System; using System.Collections.Generic; -namespace WireMock.Models; +namespace WireMock.Models.Mime; /// /// A simplified interface exposing the public, readable properties of a MIME message. diff --git a/src/WireMock.Net.Abstractions/Models/IMimePartData.cs b/src/WireMock.Net.Abstractions/Models/Mime/IMimePartData.cs similarity index 91% rename from src/WireMock.Net.Abstractions/Models/IMimePartData.cs rename to src/WireMock.Net.Abstractions/Models/Mime/IMimePartData.cs index 157c0eb75..27259da58 100644 --- a/src/WireMock.Net.Abstractions/Models/IMimePartData.cs +++ b/src/WireMock.Net.Abstractions/Models/Mime/IMimePartData.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.IO; -namespace WireMock.Models; +namespace WireMock.Models.Mime; /// /// A simplified interface exposing the public, readable properties of MimePart. @@ -31,8 +31,8 @@ public interface IMimePartData : IMimeEntityData /// /// Get the content transfer encoding. /// - /// The content transfer encoding as an integer. - int ContentTransferEncoding { get; } + /// The content transfer encoding as a string. + string ContentTransferEncoding { get; } /// /// Get the name of the file. diff --git a/src/WireMock.Net.MimePart/Matchers/MimePartMatcher.cs b/src/WireMock.Net.MimePart/Matchers/MimePartMatcher.cs index 35ca9b823..ae89a172a 100644 --- a/src/WireMock.Net.MimePart/Matchers/MimePartMatcher.cs +++ b/src/WireMock.Net.MimePart/Matchers/MimePartMatcher.cs @@ -3,7 +3,7 @@ using System; using MimeKit; using WireMock.Matchers.Helpers; -using WireMock.Models; +using WireMock.Models.Mime; using WireMock.Util; namespace WireMock.Matchers; @@ -52,9 +52,9 @@ public MimePartMatcher( _funcs = [ - mp => ContentTypeMatcher?.IsMatch(GetContentTypeValue(mp.ContentType)) ?? MatchScores.Perfect, - mp => ContentDispositionMatcher?.IsMatch(mp.ContentDisposition.ToString().Replace("Content-Disposition: ", string.Empty)) ?? MatchScores.Perfect, - mp => ContentTransferEncodingMatcher?.IsMatch(mp.ContentTransferEncoding.ToString().ToLowerInvariant()) ?? MatchScores.Perfect, + mp => ContentTypeMatcher?.IsMatch(GetContentTypeAsString(mp.ContentType)) ?? MatchScores.Perfect, + mp => ContentDispositionMatcher?.IsMatch(mp.ContentDisposition?.ToString()?.Replace("Content-Disposition: ", string.Empty)) ?? MatchScores.Perfect, + mp => ContentTransferEncodingMatcher?.IsMatch(mp.ContentTransferEncoding.ToLowerInvariant()) ?? MatchScores.Perfect, MatchOnContent ]; } @@ -96,7 +96,7 @@ private MatchResult MatchOnContent(IMimePartData mimePart) var bodyParserSettings = new BodyParserSettings { Stream = mimePart.Open(), - ContentType = GetContentTypeValue(mimePart.ContentType), + ContentType = GetContentTypeAsString(mimePart.ContentType), DeserializeJson = true, ContentEncoding = null, // mimePart.ContentType.CharsetEncoding.ToString(), DecompressGZipAndDeflate = true @@ -106,8 +106,8 @@ private MatchResult MatchOnContent(IMimePartData mimePart) return BodyDataMatchScoreCalculator.CalculateMatchScore(bodyData, ContentMatcher); } - private static string? GetContentTypeValue(string? contentType) + private static string? GetContentTypeAsString(IContentTypeData? contentType) { - return contentType?.ToString().Replace("Content-Type: ", string.Empty); + return contentType?.ToString()?.Replace("Content-Type: ", string.Empty); } } \ No newline at end of file diff --git a/src/WireMock.Net.MimePart/Models/ContentDispositionDataWrapper.cs b/src/WireMock.Net.MimePart/Models/ContentDispositionDataWrapper.cs new file mode 100644 index 000000000..375b3ec75 --- /dev/null +++ b/src/WireMock.Net.MimePart/Models/ContentDispositionDataWrapper.cs @@ -0,0 +1,59 @@ +// Copyright © WireMock.Net + +using System; +using MimeKit; +using Stef.Validation; +using WireMock.Models.Mime; + +namespace WireMock.Models; + +/// +/// A wrapper class that implements the IContentDispositionData interface +/// by wrapping a ContentDisposition object. +/// +/// +/// This class provides a simplified, read-only view of a ContentDisposition. +/// +public class ContentDispositionDataWrapper : IContentDispositionData +{ + private readonly ContentDisposition _contentDisposition; + + /// + /// Initializes a new instance of the class. + /// + /// The ContentDisposition to wrap. + public ContentDispositionDataWrapper(ContentDisposition contentDisposition) + { + _contentDisposition = Guard.NotNull(contentDisposition); + } + + /// + public string Disposition => _contentDisposition.Disposition; + + /// + public bool IsAttachment => _contentDisposition.IsAttachment; + + /// + public object Parameters => _contentDisposition.Parameters; + + /// + public string FileName => _contentDisposition.FileName; + + /// + public DateTimeOffset? CreationDate => _contentDisposition.CreationDate; + + /// + public DateTimeOffset? ModificationDate => _contentDisposition.ModificationDate; + + /// + public DateTimeOffset? ReadDate => _contentDisposition.ReadDate; + + /// + public long? Size => _contentDisposition.Size; + + /// + public override string ToString() + { + return _contentDisposition.ToString(); + } +} diff --git a/src/WireMock.Net.MimePart/Models/ContentTypeDataWrapper.cs b/src/WireMock.Net.MimePart/Models/ContentTypeDataWrapper.cs new file mode 100644 index 000000000..b68e0e2c1 --- /dev/null +++ b/src/WireMock.Net.MimePart/Models/ContentTypeDataWrapper.cs @@ -0,0 +1,65 @@ +// Copyright © WireMock.Net + +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MimeKit; +using Stef.Validation; +using WireMock.Models.Mime; + +namespace WireMock.Models; + +/// +/// A wrapper class that implements the interface by wrapping a object. +/// +/// +/// This class provides a simplified, read-only view of a . +/// +public class ContentTypeDataWrapper : IContentTypeData +{ + private readonly ContentType _contentType; + + /// + /// Initializes a new instance of the class. + /// + /// The ContentType to wrap. + public ContentTypeDataWrapper(ContentType contentType) + { + _contentType = Guard.NotNull(contentType); + + Parameters = _contentType.Parameters.Select(p => p.ToString()).ToList(); + } + + /// + public string MediaType => _contentType.MediaType; + + /// + public string MediaSubtype => _contentType.MediaSubtype; + + /// + public IList Parameters { get; private set; } + + /// + public string Boundary => _contentType.Boundary; + + /// + public string Charset => _contentType.Charset; + + /// + public Encoding CharsetEncoding => _contentType.CharsetEncoding; + + /// + public string Format => _contentType.Format; + + /// + public string MimeType => _contentType.MimeType; + + /// + public string Name => _contentType.Name; + + /// + public override string ToString() + { + return _contentType.ToString(); + } +} \ No newline at end of file diff --git a/src/WireMock.Net.MimePart/Models/MimeEntityDataWrapper.cs b/src/WireMock.Net.MimePart/Models/MimeEntityDataWrapper.cs index 01082e81b..38d3a00c6 100644 --- a/src/WireMock.Net.MimePart/Models/MimeEntityDataWrapper.cs +++ b/src/WireMock.Net.MimePart/Models/MimeEntityDataWrapper.cs @@ -5,6 +5,7 @@ using System.Linq; using MimeKit; using Stef.Validation; +using WireMock.Models.Mime; namespace WireMock.Models; @@ -26,6 +27,8 @@ public MimeEntityDataWrapper(IMimeEntity entity) { _entity = Guard.NotNull(entity); + ContentDisposition = _entity.ContentDisposition != null ? new ContentDispositionDataWrapper(_entity.ContentDisposition) : null; + ContentType = _entity.ContentType != null ? new ContentTypeDataWrapper(_entity.ContentType) : null; Headers = _entity.Headers.Select(h => h.ToString()).ToList(); } @@ -33,10 +36,10 @@ public MimeEntityDataWrapper(IMimeEntity entity) public IList Headers { get; private set; } /// - public string ContentDisposition => _entity.ContentDisposition.ToString(); + public IContentDispositionData? ContentDisposition { get; private set; } /// - public string ContentType => _entity.ContentType.ToString(); + public IContentTypeData? ContentType { get; private set; } /// public Uri ContentBase => _entity.ContentBase; @@ -49,4 +52,10 @@ public MimeEntityDataWrapper(IMimeEntity entity) /// public bool IsAttachment => _entity.IsAttachment; + + /// + public override string ToString() + { + return _entity.ToString()!; + } } diff --git a/src/WireMock.Net.MimePart/Models/MimeMessageDataWrapper.cs b/src/WireMock.Net.MimePart/Models/MimeMessageDataWrapper.cs index 154f61192..0f8e615ad 100644 --- a/src/WireMock.Net.MimePart/Models/MimeMessageDataWrapper.cs +++ b/src/WireMock.Net.MimePart/Models/MimeMessageDataWrapper.cs @@ -5,6 +5,7 @@ using System.Linq; using MimeKit; using Stef.Validation; +using WireMock.Models.Mime; namespace WireMock.Models; @@ -130,4 +131,10 @@ public MimeMessageDataWrapper(IMimeMessage message) /// public IList Attachments { get; private set; } + + /// + public override string ToString() + { + return _message.ToString(); + } } \ No newline at end of file diff --git a/src/WireMock.Net.MimePart/Models/MimePartDataWrapper.cs b/src/WireMock.Net.MimePart/Models/MimePartDataWrapper.cs index 00cc7dcf6..5541c107e 100644 --- a/src/WireMock.Net.MimePart/Models/MimePartDataWrapper.cs +++ b/src/WireMock.Net.MimePart/Models/MimePartDataWrapper.cs @@ -4,6 +4,7 @@ using System.IO; using MimeKit; using Stef.Validation; +using WireMock.Models.Mime; namespace WireMock.Models; @@ -39,7 +40,7 @@ public MimePartDataWrapper(IMimePart part) : base(part) public string ContentMd5 => _part.ContentMd5; /// - public int ContentTransferEncoding => (int)_part.ContentTransferEncoding; + public string ContentTransferEncoding => _part.ContentTransferEncoding.ToString(); /// public string FileName => _part.FileName; @@ -54,4 +55,10 @@ public MimePartDataWrapper(IMimePart part) : base(part) /// public Stream Open() => _part.Content.Open(); + + /// + public override string ToString() + { + return _part.ToString()!; + } } \ No newline at end of file diff --git a/src/WireMock.Net.MimePart/Util/MimeKitUtils.cs b/src/WireMock.Net.MimePart/Util/MimeKitUtils.cs index e855ef283..6bc3204b0 100644 --- a/src/WireMock.Net.MimePart/Util/MimeKitUtils.cs +++ b/src/WireMock.Net.MimePart/Util/MimeKitUtils.cs @@ -10,6 +10,7 @@ using Stef.Validation; using WireMock.Http; using WireMock.Models; +using WireMock.Models.Mime; using WireMock.Types; namespace WireMock.Util; diff --git a/src/WireMock.Net.Shared/Matchers/IMimePartMatcher.cs b/src/WireMock.Net.Shared/Matchers/IMimePartMatcher.cs index 2aa263cff..1eff8bd9a 100644 --- a/src/WireMock.Net.Shared/Matchers/IMimePartMatcher.cs +++ b/src/WireMock.Net.Shared/Matchers/IMimePartMatcher.cs @@ -1,6 +1,6 @@ // Copyright © WireMock.Net -using WireMock.Models; +using WireMock.Models.Mime; namespace WireMock.Matchers; diff --git a/src/WireMock.Net.Shared/Util/IMimeKitUtils.cs b/src/WireMock.Net.Shared/Util/IMimeKitUtils.cs index 9625c3ce0..fe296d9a6 100644 --- a/src/WireMock.Net.Shared/Util/IMimeKitUtils.cs +++ b/src/WireMock.Net.Shared/Util/IMimeKitUtils.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.IO; -using WireMock.Models; +using WireMock.Models.Mime; namespace WireMock.Util; From 6ecd979ae810d8f851e4e0cb7d72a6a53573bfe2 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Fri, 11 Jul 2025 16:40:44 +0200 Subject: [PATCH 09/18] if (Array.TrueForAll(_funcs, func => func(value).IsPerfect())) --- src/WireMock.Net.MimePart/Matchers/MimePartMatcher.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WireMock.Net.MimePart/Matchers/MimePartMatcher.cs b/src/WireMock.Net.MimePart/Matchers/MimePartMatcher.cs index ae89a172a..bf4f8c04a 100644 --- a/src/WireMock.Net.MimePart/Matchers/MimePartMatcher.cs +++ b/src/WireMock.Net.MimePart/Matchers/MimePartMatcher.cs @@ -67,7 +67,7 @@ public MatchResult IsMatch(IMimePartData value) try { - if (value is IMimePartData mimePart && Array.TrueForAll(_funcs, func => func(mimePart).IsPerfect())) + if (Array.TrueForAll(_funcs, func => func(value).IsPerfect())) { score = MatchScores.Perfect; } From 7e9e00f6a9794bc5eef9d5c7533cb4e1f9c7c8ef Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Fri, 11 Jul 2025 17:45:22 +0200 Subject: [PATCH 10/18] Update src/WireMock.Net.Shared/Util/IMimeKitUtils.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/WireMock.Net.Shared/Util/IMimeKitUtils.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/WireMock.Net.Shared/Util/IMimeKitUtils.cs b/src/WireMock.Net.Shared/Util/IMimeKitUtils.cs index fe296d9a6..bfe7d67f1 100644 --- a/src/WireMock.Net.Shared/Util/IMimeKitUtils.cs +++ b/src/WireMock.Net.Shared/Util/IMimeKitUtils.cs @@ -27,10 +27,5 @@ public interface IMimeKitUtils /// true when parsed correctly, else false bool TryGetMimeMessage(IRequestMessage requestMessage, [NotNullWhen(true)] out IMimeMessageData? mimeMessageData); - ///// - ///// Gets the body parts from the MimeKit.MimeMessage. - ///// - ///// The MimeKit.MimeMessage. - ///// A list of MimeParts. - //IReadOnlyList GetBodyParts(IMimeMessageData mimeMessageData); +// Removed commented-out method signature and XML documentation for GetBodyParts. } \ No newline at end of file From b0a63f54c416469a195ec5c176bf2a3dcdee1516 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Fri, 11 Jul 2025 17:45:37 +0200 Subject: [PATCH 11/18] Update src/WireMock.Net.Minimal/Matchers/Request/RequestMessageMultiPartMatcher.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../Matchers/Request/RequestMessageMultiPartMatcher.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/WireMock.Net.Minimal/Matchers/Request/RequestMessageMultiPartMatcher.cs b/src/WireMock.Net.Minimal/Matchers/Request/RequestMessageMultiPartMatcher.cs index f93fa2452..84a23ce74 100644 --- a/src/WireMock.Net.Minimal/Matchers/Request/RequestMessageMultiPartMatcher.cs +++ b/src/WireMock.Net.Minimal/Matchers/Request/RequestMessageMultiPartMatcher.cs @@ -73,7 +73,6 @@ public double GetMatchingScore(IRequestMessage requestMessage, IRequestMatchResu { score = MatchScores.Mismatch; - //foreach (var mimeBodyPart in MimeKitUtils.GetBodyParts(message)) foreach (var mimeBodyPart in message.BodyParts) { var matchResult = mimePartMatcher.IsMatch(mimeBodyPart); From 7e00fd9d4e4e3bde4a982ecc6f4a19909bea9161 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Fri, 11 Jul 2025 17:45:43 +0200 Subject: [PATCH 12/18] Update src/WireMock.Net.MimePart/Models/MimeEntityDataWrapper.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/WireMock.Net.MimePart/Models/MimeEntityDataWrapper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WireMock.Net.MimePart/Models/MimeEntityDataWrapper.cs b/src/WireMock.Net.MimePart/Models/MimeEntityDataWrapper.cs index 38d3a00c6..d7a52a04a 100644 --- a/src/WireMock.Net.MimePart/Models/MimeEntityDataWrapper.cs +++ b/src/WireMock.Net.MimePart/Models/MimeEntityDataWrapper.cs @@ -10,7 +10,7 @@ namespace WireMock.Models; /// -/// A wrapper class that implements the > interface by wrapping an interface. +/// A wrapper class that implements the interface by wrapping an interface. /// /// /// This class provides a simplified, read-only view of an . From 9bccfe936d8e2bf463b611393a69411b3904e990 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Fri, 11 Jul 2025 20:22:00 +0200 Subject: [PATCH 13/18] Models.Mime.IMimeMessageData? BodyAsMimeMessage { get; } --- src/WireMock.Net.Abstractions/IRequestMessage.cs | 2 +- src/WireMock.Net.Minimal/RequestMessage.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/WireMock.Net.Abstractions/IRequestMessage.cs b/src/WireMock.Net.Abstractions/IRequestMessage.cs index 63a52a6e6..c2e7144a9 100644 --- a/src/WireMock.Net.Abstractions/IRequestMessage.cs +++ b/src/WireMock.Net.Abstractions/IRequestMessage.cs @@ -123,7 +123,7 @@ public interface IRequestMessage /// The original body as MimeMessage. /// Convenience getter for Handlebars and WireMockAssertions. /// - object? BodyAsMimeMessage { get; } + Models.Mime.IMimeMessageData? BodyAsMimeMessage { get; } #endif /// diff --git a/src/WireMock.Net.Minimal/RequestMessage.cs b/src/WireMock.Net.Minimal/RequestMessage.cs index aa93b6829..e7fd8a706 100644 --- a/src/WireMock.Net.Minimal/RequestMessage.cs +++ b/src/WireMock.Net.Minimal/RequestMessage.cs @@ -85,7 +85,7 @@ public class RequestMessage : IRequestMessage #if MIMEKIT /// [Newtonsoft.Json.JsonIgnore] // Issue 1001 - public object? BodyAsMimeMessage { get; } + public Models.Mime.IMimeMessageData? BodyAsMimeMessage { get; } #endif /// From 1db8f15b2b0604df1acb3b6611ed18ad72137e5a Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Sat, 12 Jul 2025 09:11:31 +0200 Subject: [PATCH 14/18] Update src/WireMock.Net.MimePart/Util/MimeKitUtils.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/WireMock.Net.MimePart/Util/MimeKitUtils.cs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/WireMock.Net.MimePart/Util/MimeKitUtils.cs b/src/WireMock.Net.MimePart/Util/MimeKitUtils.cs index 6bc3204b0..f97d9232f 100644 --- a/src/WireMock.Net.MimePart/Util/MimeKitUtils.cs +++ b/src/WireMock.Net.MimePart/Util/MimeKitUtils.cs @@ -54,18 +54,6 @@ public bool TryGetMimeMessage(IRequestMessage requestMessage, [NotNullWhen(true) return false; } - ///// - //public IReadOnlyList GetBodyParts(IMimeMessageData mimeMessageData) - //{ - // if (mimeMessageData is not MimeMessageDataWrapper wrapper) - // { - // throw new ArgumentException($"The mimeMessageData must be of type {nameof(MimeMessageDataWrapper)}", nameof(mimeMessageData)); - // } - - // return wrapper.Message.BodyParts - // .OfType() - // .ToArray(); - //} private static bool StartsWithMultiPart(WireMockList contentTypeHeader) { From 69f143bd83e7ae374f9ef5c938c147464faf84dc Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Sat, 12 Jul 2025 09:12:13 +0200 Subject: [PATCH 15/18] Update src/WireMock.Net.MimePart/Models/MimePartDataWrapper.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/WireMock.Net.MimePart/Models/MimePartDataWrapper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WireMock.Net.MimePart/Models/MimePartDataWrapper.cs b/src/WireMock.Net.MimePart/Models/MimePartDataWrapper.cs index 5541c107e..cdcc4175c 100644 --- a/src/WireMock.Net.MimePart/Models/MimePartDataWrapper.cs +++ b/src/WireMock.Net.MimePart/Models/MimePartDataWrapper.cs @@ -9,7 +9,7 @@ namespace WireMock.Models; /// -/// A wrapper class that implements the > interface by wrapping an interface. +/// A wrapper class that implements the interface by wrapping an interface. /// /// /// This class provides a simplified, read-only view of an . From e5cd84102c2589ed9212f49a5cac1d6f1f7fff0d Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Sat, 12 Jul 2025 09:12:19 +0200 Subject: [PATCH 16/18] Update src/WireMock.Net.MimePart/Models/MimeMessageDataWrapper.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/WireMock.Net.MimePart/Models/MimeMessageDataWrapper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WireMock.Net.MimePart/Models/MimeMessageDataWrapper.cs b/src/WireMock.Net.MimePart/Models/MimeMessageDataWrapper.cs index 0f8e615ad..a4463f207 100644 --- a/src/WireMock.Net.MimePart/Models/MimeMessageDataWrapper.cs +++ b/src/WireMock.Net.MimePart/Models/MimeMessageDataWrapper.cs @@ -10,7 +10,7 @@ namespace WireMock.Models; /// -/// A wrapper class that implements the > interface by wrapping an interface. +/// A wrapper class that implements the interface by wrapping an interface. /// /// /// This class provides a simplified, read-only view of an . From 62b081d1de046050cee73cb21450532dada089ec Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Sat, 12 Jul 2025 09:13:11 +0200 Subject: [PATCH 17/18] Update src/WireMock.Net.Shared/Util/IMimeKitUtils.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/WireMock.Net.Shared/Util/IMimeKitUtils.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/WireMock.Net.Shared/Util/IMimeKitUtils.cs b/src/WireMock.Net.Shared/Util/IMimeKitUtils.cs index bfe7d67f1..2d4dba67a 100644 --- a/src/WireMock.Net.Shared/Util/IMimeKitUtils.cs +++ b/src/WireMock.Net.Shared/Util/IMimeKitUtils.cs @@ -27,5 +27,4 @@ public interface IMimeKitUtils /// true when parsed correctly, else false bool TryGetMimeMessage(IRequestMessage requestMessage, [NotNullWhen(true)] out IMimeMessageData? mimeMessageData); -// Removed commented-out method signature and XML documentation for GetBodyParts. } \ No newline at end of file From c5be10dc65e8ce96e3aec466512a3c254b06d624 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Sat, 12 Jul 2025 09:23:40 +0200 Subject: [PATCH 18/18] . --- .../Models/Mime/IContentDispositionData.cs | 3 ++- src/WireMock.Net.MimePart/Matchers/MimePartMatcher.cs | 3 +-- .../Models/ContentDispositionDataWrapper.cs | 6 +++++- src/WireMock.Net.Shared/Util/IMimeKitUtils.cs | 7 ++----- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/WireMock.Net.Abstractions/Models/Mime/IContentDispositionData.cs b/src/WireMock.Net.Abstractions/Models/Mime/IContentDispositionData.cs index 735e3cd2d..396639eef 100644 --- a/src/WireMock.Net.Abstractions/Models/Mime/IContentDispositionData.cs +++ b/src/WireMock.Net.Abstractions/Models/Mime/IContentDispositionData.cs @@ -1,6 +1,7 @@ // Copyright © WireMock.Net using System; +using System.Collections.Generic; namespace WireMock.Models.Mime; @@ -25,7 +26,7 @@ public interface IContentDispositionData /// Get the list of parameters on the ContentDisposition. /// /// The parameters. - object Parameters { get; } + public IList Parameters { get; } /// /// Get the name of the file. diff --git a/src/WireMock.Net.MimePart/Matchers/MimePartMatcher.cs b/src/WireMock.Net.MimePart/Matchers/MimePartMatcher.cs index bf4f8c04a..fe17cdd47 100644 --- a/src/WireMock.Net.MimePart/Matchers/MimePartMatcher.cs +++ b/src/WireMock.Net.MimePart/Matchers/MimePartMatcher.cs @@ -1,7 +1,6 @@ // Copyright © WireMock.Net using System; -using MimeKit; using WireMock.Matchers.Helpers; using WireMock.Models.Mime; using WireMock.Util; @@ -98,7 +97,7 @@ private MatchResult MatchOnContent(IMimePartData mimePart) Stream = mimePart.Open(), ContentType = GetContentTypeAsString(mimePart.ContentType), DeserializeJson = true, - ContentEncoding = null, // mimePart.ContentType.CharsetEncoding.ToString(), + ContentEncoding = null, // mimePart.ContentType?.CharsetEncoding.ToString(), DecompressGZipAndDeflate = true }; diff --git a/src/WireMock.Net.MimePart/Models/ContentDispositionDataWrapper.cs b/src/WireMock.Net.MimePart/Models/ContentDispositionDataWrapper.cs index 375b3ec75..a663f7e31 100644 --- a/src/WireMock.Net.MimePart/Models/ContentDispositionDataWrapper.cs +++ b/src/WireMock.Net.MimePart/Models/ContentDispositionDataWrapper.cs @@ -1,6 +1,8 @@ // Copyright © WireMock.Net using System; +using System.Collections.Generic; +using System.Linq; using MimeKit; using Stef.Validation; using WireMock.Models.Mime; @@ -25,6 +27,8 @@ public class ContentDispositionDataWrapper : IContentDispositionData public ContentDispositionDataWrapper(ContentDisposition contentDisposition) { _contentDisposition = Guard.NotNull(contentDisposition); + + Parameters = _contentDisposition.Parameters.Select(p => p.ToString()).ToList(); } /// @@ -34,7 +38,7 @@ public ContentDispositionDataWrapper(ContentDisposition contentDisposition) public bool IsAttachment => _contentDisposition.IsAttachment; /// - public object Parameters => _contentDisposition.Parameters; + public IList Parameters { get; private set; } /// public string FileName => _contentDisposition.FileName; diff --git a/src/WireMock.Net.Shared/Util/IMimeKitUtils.cs b/src/WireMock.Net.Shared/Util/IMimeKitUtils.cs index 2d4dba67a..2d2a739f6 100644 --- a/src/WireMock.Net.Shared/Util/IMimeKitUtils.cs +++ b/src/WireMock.Net.Shared/Util/IMimeKitUtils.cs @@ -1,6 +1,5 @@ // Copyright © WireMock.Net -using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.IO; using WireMock.Models.Mime; @@ -13,18 +12,16 @@ namespace WireMock.Util; public interface IMimeKitUtils { /// - /// Loads the MimeKit.MimeMessage from the stream. + /// Loads the from the stream. /// /// The stream - /// MimeKit.MimeMessage IMimeMessageData LoadFromStream(Stream stream); /// - /// Tries to get the MimeKit.MimeMessage from the request message. + /// Tries to get the from the request message. /// /// The request message. /// A class MimeMessageDataWrapper which wraps a MimeKit.MimeMessage. /// true when parsed correctly, else false bool TryGetMimeMessage(IRequestMessage requestMessage, [NotNullWhen(true)] out IMimeMessageData? mimeMessageData); - } \ No newline at end of file