1
1
using System ;
2
2
using System . Collections . Generic ;
3
3
using System . Linq ;
4
+ using MimeKit ;
4
5
using Stef . Validation ;
5
6
using WireMock . Util ;
6
7
@@ -9,23 +10,21 @@ namespace WireMock.Matchers.Request;
9
10
/// <summary>
10
11
/// The request body MultiPart matcher.
11
12
/// </summary>
12
- public class RequestMessageMultiPartMatcher : IRequestMatcher
13
+ public class RequestMessageMultiPartMatcher : IRequestMessageMultiPartMatcher
13
14
{
14
- /// <summary>
15
- /// The matchers.
16
- /// </summary>
15
+ /// <inheritdoc />
17
16
public IMatcher [ ] ? Matchers { get ; }
18
17
19
- /// <summary>
20
- /// The <see cref="MatchOperator"/>
21
- /// </summary>
18
+ /// <inheritdoc />
22
19
public MatchOperator MatchOperator { get ; } = MatchOperator . Or ;
23
20
24
21
/// <summary>
25
22
/// The <see cref="MatchBehaviour"/>
26
23
/// </summary>
27
24
public MatchBehaviour MatchBehaviour { get ; }
28
25
26
+ private readonly MimeKitUtils _mimeKitUtils = new ( ) ;
27
+
29
28
/// <summary>
30
29
/// Initializes a new instance of the <see cref="RequestMessageMultiPartMatcher"/> class.
31
30
/// </summary>
@@ -51,9 +50,6 @@ public RequestMessageMultiPartMatcher(MatchBehaviour matchBehaviour, MatchOperat
51
50
/// <inheritdoc />
52
51
public double GetMatchingScore ( IRequestMessage requestMessage , IRequestMatchResult requestMatchResult )
53
52
{
54
- #if ! MIMEKIT
55
- throw new System . NotSupportedException ( "The MultiPartMatcher can not be used for .NETStandard1.3 or .NET Framework 4.6.1 or lower." ) ;
56
- #else
57
53
var score = MatchScores . Mismatch ;
58
54
Exception ? exception = null ;
59
55
@@ -62,7 +58,7 @@ public double GetMatchingScore(IRequestMessage requestMessage, IRequestMatchResu
62
58
return requestMatchResult . AddScore ( GetType ( ) , score , null ) ;
63
59
}
64
60
65
- if ( ! MimeKitUtils . TryGetMimeMessage ( requestMessage , out var message ) )
61
+ if ( ! _mimeKitUtils . TryGetMimeMessage ( requestMessage , out MimeMessage ? message ) )
66
62
{
67
63
return requestMatchResult . AddScore ( GetType ( ) , score , null ) ;
68
64
}
@@ -71,7 +67,7 @@ public double GetMatchingScore(IRequestMessage requestMessage, IRequestMatchResu
71
67
{
72
68
var mimePartMatchers = Matchers . OfType < MimePartMatcher > ( ) . ToArray ( ) ;
73
69
74
- foreach ( var mimePart in message . BodyParts . OfType < MimeKit . MimePart > ( ) )
70
+ foreach ( var mimePart in message . BodyParts . OfType < MimePart > ( ) )
75
71
{
76
72
var matchesForMimePart = new List < MatchResult > { default } ;
77
73
matchesForMimePart . AddRange ( mimePartMatchers . Select ( matcher => matcher . IsMatch ( mimePart ) ) ) ;
@@ -98,6 +94,5 @@ public double GetMatchingScore(IRequestMessage requestMessage, IRequestMatchResu
98
94
}
99
95
100
96
return requestMatchResult . AddScore ( GetType ( ) , score , exception ) ;
101
- #endif
102
97
}
103
98
}
0 commit comments