Skip to content

Commit c6648b6

Browse files
committed
.
1 parent fd304fe commit c6648b6

File tree

3 files changed

+34
-36
lines changed

3 files changed

+34
-36
lines changed

src/WireMock.Net.FluentAssertions/Assertions/WireMockAssertions.WithBody.cs

+13-13
Original file line numberDiff line numberDiff line change
@@ -25,37 +25,37 @@ public AndConstraint<WireMockAssertions> WithBody(string body, string because =
2525
}
2626

2727
[CustomAssertion]
28-
public AndConstraint<WireMockAssertions> WithBodyAsJson(object body, string because = "", params object[] becauseArgs)
28+
public AndConstraint<WireMockAssertions> WithBody(IStringMatcher matcher, string because = "", params object[] becauseArgs)
2929
{
30-
return WithBodyAsJson(new JsonMatcher(body), because, becauseArgs);
30+
var (filter, condition) = BuildFilterAndCondition(r => r.Body, matcher);
31+
32+
return ExecuteAssertionWithBodyStringMatcher(matcher, because, becauseArgs, condition, filter, r => r.Body);
3133
}
3234

3335
[CustomAssertion]
34-
public AndConstraint<WireMockAssertions> WithBodyAsJson(string body, string because = "", params object[] becauseArgs)
36+
public AndConstraint<WireMockAssertions> WithBodyAsJson(object body, string because = "", params object[] becauseArgs)
3537
{
3638
return WithBodyAsJson(new JsonMatcher(body), because, becauseArgs);
3739
}
3840

3941
[CustomAssertion]
40-
public AndConstraint<WireMockAssertions> WithBodyAsBytes(byte[] body, string because = "", params object[] becauseArgs)
42+
public AndConstraint<WireMockAssertions> WithBodyAsJson(string body, string because = "", params object[] becauseArgs)
4143
{
42-
return WithBodyAsBytes(new ExactObjectMatcher(body), because, becauseArgs);
44+
return WithBodyAsJson(new JsonMatcher(body), because, becauseArgs);
4345
}
4446

4547
[CustomAssertion]
46-
public AndConstraint<WireMockAssertions> WithBody(IStringMatcher matcher, string because = "", params object[] becauseArgs)
48+
public AndConstraint<WireMockAssertions> WithBodyAsJson(IObjectMatcher matcher, string because = "", params object[] becauseArgs)
4749
{
48-
var (filter, condition) = BuildFilterAndCondition(r => r.Body, matcher);
50+
var (filter, condition) = BuildFilterAndCondition(r => r.BodyAsJson, matcher);
4951

50-
return ExecuteAssertionWithBodyStringMatcher(matcher, because, becauseArgs, condition, filter, r => r.Body);
52+
return ExecuteAssertionWithBodyAsIObjectMatcher(matcher, because, becauseArgs, condition, filter, r => r.BodyAsJson);
5153
}
5254

5355
[CustomAssertion]
54-
public AndConstraint<WireMockAssertions> WithBodyAsJson(IObjectMatcher matcher, string because = "", params object[] becauseArgs)
56+
public AndConstraint<WireMockAssertions> WithBodyAsBytes(byte[] body, string because = "", params object[] becauseArgs)
5557
{
56-
var (filter, condition) = BuildFilterAndCondition(r => r.BodyAsJson, matcher);
57-
58-
return ExecuteAssertionWithBodyAsIObjectMatcher(matcher, because, becauseArgs, condition, filter, r => r.BodyAsJson);
58+
return WithBodyAsBytes(new ExactObjectMatcher(body), because, becauseArgs);
5959
}
6060

6161
[CustomAssertion]
@@ -142,6 +142,6 @@ private AndConstraint<WireMockAssertions> ExecuteAssertionWithBodyAsIObjectMatch
142142
private static string? FormatBodies(IEnumerable<object?> bodies)
143143
{
144144
var valueAsArray = bodies as object[] ?? bodies.ToArray();
145-
return valueAsArray.Length == 1 ? FormatBody(valueAsArray.First()) : $"[ {string.Join(", ", valueAsArray.Select(FormatBody))} ]";
145+
return valueAsArray.Length == 1 ? FormatBody(valueAsArray[0]) : $"[ {string.Join(", ", valueAsArray.Select(FormatBody))} ]";
146146
}
147147
}

src/WireMock.Net.FluentAssertions/Assertions/WireMockAssertions.WithHeader.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright © WireMock.Net
22

33
#pragma warning disable CS1591
4-
using System.Collections.Generic;
5-
using WireMock.Types;
64

75
// ReSharper disable once CheckNamespace
86
namespace WireMock.FluentAssertions;
@@ -47,7 +45,7 @@ public AndConstraint<WireMockAssertions> WithHeader(string expectedKey, string[]
4745
{
4846
var (filter, condition) = BuildFilterAndCondition(request =>
4947
{
50-
var headers = request.Headers?.ToArray() ?? new KeyValuePair<string, WireMockList<string>>[0];
48+
var headers = request.Headers?.ToArray() ?? [];
5149

5250
var matchingHeaderValues = headers.Where(h => h.Key == expectedKey).SelectMany(h => h.Value.ToArray()).ToArray();
5351

@@ -121,7 +119,7 @@ public AndConstraint<WireMockAssertions> WithoutHeader(string unexpectedKey, str
121119
{
122120
var (filter, condition) = BuildFilterAndCondition(request =>
123121
{
124-
var headers = request.Headers?.ToArray() ?? new KeyValuePair<string, WireMockList<string>>[0];
122+
var headers = request.Headers?.ToArray() ?? [];
125123

126124
var matchingHeaderValues = headers.Where(h => h.Key == unexpectedKey).SelectMany(h => h.Value.ToArray()).ToArray();
127125

src/WireMock.Net.Matchers.CSharpCode/Matchers/CSharpCodeMatcher.cs

+19-19
Original file line numberDiff line numberDiff line change
@@ -146,24 +146,24 @@ private bool IsMatch(dynamic input, string pattern)
146146
}
147147
}
148148
#elif (NET46 || NET461)
149-
dynamic script;
150-
try
151-
{
152-
script = CSScriptLibrary.CSScript.Evaluator.CompileCode(source).CreateObject("*");
153-
}
154-
catch (Exception ex)
155-
{
156-
throw new WireMockException("CSharpCodeMatcher: Unable to create compiler for WireMock.CodeHelper", ex);
157-
}
158-
159-
try
160-
{
161-
result = script.IsMatch(inputValue);
162-
}
163-
catch (Exception ex)
164-
{
165-
throw new WireMockException("CSharpCodeMatcher: Problem calling method 'IsMatch' in WireMock.CodeHelper", ex);
166-
}
149+
dynamic script;
150+
try
151+
{
152+
script = CSScriptLibrary.CSScript.Evaluator.CompileCode(source).CreateObject("*");
153+
}
154+
catch (Exception ex)
155+
{
156+
throw new WireMockException("CSharpCodeMatcher: Unable to create compiler for WireMock.CodeHelper", ex);
157+
}
158+
159+
try
160+
{
161+
result = script.IsMatch(inputValue);
162+
}
163+
catch (Exception ex)
164+
{
165+
throw new WireMockException("CSharpCodeMatcher: Problem calling method 'IsMatch' in WireMock.CodeHelper", ex);
166+
}
167167

168168
#elif (NETSTANDARD2_0 || NETSTANDARD2_1 || NETCOREAPP3_1 || NET5_0_OR_GREATER)
169169
Assembly assembly;
@@ -195,7 +195,7 @@ private bool IsMatch(dynamic input, string pattern)
195195
throw new WireMockException("CSharpCodeMatcher: Problem calling method 'IsMatch' in WireMock.CodeHelper", ex);
196196
}
197197
#else
198-
throw new NotSupportedException("The 'CSharpCodeMatcher' cannot be used in netstandard 1.3");
198+
throw new NotSupportedException("The 'CSharpCodeMatcher' cannot be used in netstandard 1.3");
199199
#endif
200200
try
201201
{

0 commit comments

Comments
 (0)