mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-16 16:36:46 +01:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b5795713b1 | ||
|
|
a8c17ce311 | ||
|
|
7678e8fb70 | ||
|
|
8ae0abb023 | ||
|
|
b3c2af0c22 | ||
|
|
2dd30b4f14 | ||
|
|
45d8c0cc27 |
12
CHANGELOG.md
12
CHANGELOG.md
@@ -1,3 +1,15 @@
|
||||
# 1.0.42.0 (15 December 2019)
|
||||
- [#391](https://github.com/WireMock-Net/WireMock.Net/pull/391) - Correctly support DateTime pattern as string in ExactMatcher [bug] contributed by [StefH](https://github.com/StefH)
|
||||
- [#383](https://github.com/WireMock-Net/WireMock.Net/issues/383) - ExactMatcher does not accept ISO8601 DateTime? [bug]
|
||||
|
||||
# 1.0.41.0 (14 December 2019)
|
||||
- [#392](https://github.com/WireMock-Net/WireMock.Net/pull/392) - Fix array in JsonMatcher [bug] contributed by [StefH](https://github.com/StefH)
|
||||
- [#390](https://github.com/WireMock-Net/WireMock.Net/issues/390) - JsonMatcher does not match a body containing an array of strings [bug]
|
||||
|
||||
# 1.0.40.0 (09 December 2019)
|
||||
- [#389](https://github.com/WireMock-Net/WireMock.Net/pull/389) - Fix QueryStringParser [bug] contributed by [StefH](https://github.com/StefH)
|
||||
- [#387](https://github.com/WireMock-Net/WireMock.Net/issues/387) - Query string parameter value which contains %26 does not work with ExactMatcher [bug]
|
||||
|
||||
# 1.0.39.0 (07 December 2019)
|
||||
- [#370](https://github.com/WireMock-Net/WireMock.Net/pull/370) - Add WebProxySettings (use when proxying requests) [feature] contributed by [StefH](https://github.com/StefH)
|
||||
- [#388](https://github.com/WireMock-Net/WireMock.Net/pull/388) - Transform body as file [bug] contributed by [StefH](https://github.com/StefH)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<VersionPrefix>1.0.39</VersionPrefix>
|
||||
<VersionPrefix>1.0.42</VersionPrefix>
|
||||
</PropertyGroup>
|
||||
|
||||
<Choose>
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
https://github.com/StefH/GitHubReleaseNotes
|
||||
|
||||
GitHubReleaseNotes.exe --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc --version 1.0.39.0
|
||||
GitHubReleaseNotes.exe --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc --version 1.0.42.0
|
||||
@@ -1,6 +1,7 @@
|
||||
using JetBrains.Annotations;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using WireMock.Util;
|
||||
using WireMock.Validation;
|
||||
@@ -85,7 +86,7 @@ namespace WireMock.Matchers
|
||||
// Check if JToken or object
|
||||
JToken jtokenInput = input is JToken tokenInput ? tokenInput : JObject.FromObject(input);
|
||||
|
||||
// Check if JToken or string or object
|
||||
// Check if JToken, string, IEnumerable or object
|
||||
JToken jtokenValue;
|
||||
switch (Value)
|
||||
{
|
||||
@@ -97,6 +98,10 @@ namespace WireMock.Matchers
|
||||
jtokenValue = JsonUtils.Parse(stringValue);
|
||||
break;
|
||||
|
||||
case IEnumerable enumerableValue:
|
||||
jtokenValue = JArray.FromObject(enumerableValue);
|
||||
break;
|
||||
|
||||
default:
|
||||
jtokenValue = JObject.FromObject(Value);
|
||||
break;
|
||||
|
||||
@@ -170,7 +170,7 @@ namespace WireMock
|
||||
|
||||
Headers = headers?.ToDictionary(header => header.Key, header => new WireMockList<string>(header.Value));
|
||||
Cookies = cookies;
|
||||
RawQuery = WebUtility.UrlDecode(urlDetails.Url.Query);
|
||||
RawQuery = urlDetails.Url.Query;
|
||||
Query = QueryStringParser.Parse(RawQuery);
|
||||
}
|
||||
|
||||
|
||||
@@ -252,7 +252,7 @@ namespace WireMock.ResponseBuilders
|
||||
|
||||
case BodyDestinationFormat.Json:
|
||||
ResponseMessage.BodyData.DetectedBodyType = BodyType.Json;
|
||||
ResponseMessage.BodyData.BodyAsJson = JsonConvert.DeserializeObject(body);
|
||||
ResponseMessage.BodyData.BodyAsJson = JsonUtils.DeserializeObject(body);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
using JetBrains.Annotations;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@@ -5,9 +8,6 @@ using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using JetBrains.Annotations;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using WireMock.Admin.Mappings;
|
||||
using WireMock.Admin.Scenarios;
|
||||
using WireMock.Admin.Settings;
|
||||
@@ -179,8 +179,10 @@ namespace WireMock.Server
|
||||
|
||||
_settings.Logger.Info($"Watching folder '{folder}'{includeSubdirectoriesText} for new, updated and deleted MappingFiles.");
|
||||
|
||||
var watcher = new EnhancedFileSystemWatcher(folder, "*.json", EnhancedFileSystemWatcherTimeoutMs);
|
||||
watcher.IncludeSubdirectories = includeSubdirectories;
|
||||
var watcher = new EnhancedFileSystemWatcher(folder, "*.json", EnhancedFileSystemWatcherTimeoutMs)
|
||||
{
|
||||
IncludeSubdirectories = includeSubdirectories
|
||||
};
|
||||
|
||||
watcher.Created += (sender, args) =>
|
||||
{
|
||||
@@ -229,7 +231,7 @@ namespace WireMock.Server
|
||||
|
||||
if (FileHelper.TryReadMappingFileWithRetryAndDelay(_settings.FileSystemHandler, path, out string value))
|
||||
{
|
||||
var mappingModels = DeserializeObjectToArray<MappingModel>(JsonConvert.DeserializeObject(value));
|
||||
var mappingModels = DeserializeObjectToArray<MappingModel>(JsonUtils.DeserializeObject(value));
|
||||
foreach (var mappingModel in mappingModels)
|
||||
{
|
||||
if (mappingModels.Length == 1 && Guid.TryParse(filenameWithoutExtension, out Guid guidFromFilename))
|
||||
@@ -882,7 +884,7 @@ namespace WireMock.Server
|
||||
{
|
||||
if (requestMessage?.BodyData?.DetectedBodyType == BodyType.String)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<T>(requestMessage.BodyData.BodyAsString);
|
||||
return JsonUtils.DeserializeObject<T>(requestMessage.BodyData.BodyAsString);
|
||||
}
|
||||
|
||||
if (requestMessage?.BodyData?.DetectedBodyType == BodyType.Json)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using WireMock.Util;
|
||||
using WireMock.Validation;
|
||||
@@ -14,7 +15,7 @@ namespace WireMock.Transformers
|
||||
{
|
||||
handlebarsContext.RegisterHelper("JsonPath.SelectToken", (writer, context, arguments) =>
|
||||
{
|
||||
(JObject valueToProcess, string jsonPath) = ParseArguments(arguments);
|
||||
(JToken valueToProcess, string jsonPath) = ParseArguments(arguments);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -29,7 +30,7 @@ namespace WireMock.Transformers
|
||||
|
||||
handlebarsContext.RegisterHelper("JsonPath.SelectTokens", (writer, options, context, arguments) =>
|
||||
{
|
||||
(JObject valueToProcess, string jsonPath) = ParseArguments(arguments);
|
||||
(JToken valueToProcess, string jsonPath) = ParseArguments(arguments);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -46,22 +47,26 @@ namespace WireMock.Transformers
|
||||
});
|
||||
}
|
||||
|
||||
private static (JObject valueToProcess, string jsonpath) ParseArguments(object[] arguments)
|
||||
private static (JToken valueToProcess, string jsonpath) ParseArguments(object[] arguments)
|
||||
{
|
||||
Check.Condition(arguments, args => args.Length == 2, nameof(arguments));
|
||||
Check.NotNull(arguments[0], "arguments[0]");
|
||||
Check.NotNullOrEmpty(arguments[1] as string, "arguments[1]");
|
||||
|
||||
JObject valueToProcess;
|
||||
JToken valueToProcess;
|
||||
|
||||
switch (arguments[0])
|
||||
{
|
||||
case string jsonAsString:
|
||||
valueToProcess = JsonUtils.Parse(jsonAsString);
|
||||
case JToken tokenValue:
|
||||
valueToProcess = tokenValue;
|
||||
break;
|
||||
|
||||
case JObject jsonAsJObject:
|
||||
valueToProcess = jsonAsJObject;
|
||||
case string stringValue:
|
||||
valueToProcess = JsonUtils.Parse(stringValue);
|
||||
break;
|
||||
|
||||
case IEnumerable enumerableValue:
|
||||
valueToProcess = JArray.FromObject(enumerableValue);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
@@ -57,8 +57,6 @@ namespace WireMock.Util
|
||||
new WildcardMatcher("application/x-www-form-urlencoded", true)
|
||||
};
|
||||
|
||||
private static readonly JsonSerializerSettings JsonSerializerSettings = new JsonSerializerSettings { DateParseHandling = DateParseHandling.None };
|
||||
|
||||
public static bool ShouldParseBody([CanBeNull] string httpMethod, bool allowBodyForAllHttpMethods)
|
||||
{
|
||||
if (string.IsNullOrEmpty(httpMethod))
|
||||
@@ -147,7 +145,7 @@ namespace WireMock.Util
|
||||
{
|
||||
try
|
||||
{
|
||||
data.BodyAsJson = JsonConvert.DeserializeObject(data.BodyAsString, JsonSerializerSettings);
|
||||
data.BodyAsJson = JsonUtils.DeserializeObject(data.BodyAsString);
|
||||
data.DetectedBodyType = BodyType.Json;
|
||||
}
|
||||
catch
|
||||
|
||||
@@ -19,10 +19,32 @@ namespace WireMock.Util
|
||||
/// Using : DateParseHandling = DateParseHandling.None
|
||||
/// </summary>
|
||||
/// <param name="json">A System.String that contains JSON.</param>
|
||||
/// <returns>A Newtonsoft.Json.Linq.JObject populated from the string that contains JSON.</returns>
|
||||
public static JObject Parse(string json)
|
||||
/// <returns>A Newtonsoft.Json.Linq.JToken populated from the string that contains JSON.</returns>
|
||||
public static JToken Parse(string json)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<JObject>(json, JsonSerializerSettings);
|
||||
return JsonConvert.DeserializeObject<JToken>(json, JsonSerializerSettings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes the JSON to a .NET object.
|
||||
/// Using : DateParseHandling = DateParseHandling.None
|
||||
/// </summary>
|
||||
/// <param name="json">A System.String that contains JSON.</param>
|
||||
/// <returns>The deserialized object from the JSON string.</returns>
|
||||
public static object DeserializeObject(string json)
|
||||
{
|
||||
return JsonConvert.DeserializeObject(json, JsonSerializerSettings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes the JSON to the specified .NET type.
|
||||
/// Using : DateParseHandling = DateParseHandling.None
|
||||
/// </summary>
|
||||
/// <param name="json">A System.String that contains JSON.</param>
|
||||
/// <returns>The deserialized object from the JSON string.</returns>
|
||||
public static T DeserializeObject<T>(string json)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<T>(json, JsonSerializerSettings);
|
||||
}
|
||||
|
||||
public static T ParseJTokenToObject<T>(object value)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
|
||||
namespace WireMock.Util
|
||||
{
|
||||
@@ -30,7 +31,7 @@ namespace WireMock.Util
|
||||
.Split(new[] { '&', ';' }, StringSplitOptions.RemoveEmptyEntries) // Support "?key=value;key=anotherValue" and "?key=value&key=anotherValue"
|
||||
.Select(parameter => parameter.Split(new[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries))
|
||||
.GroupBy(parts => parts[0], JoinParts)
|
||||
.ToDictionary(grouping => grouping.Key, grouping => new WireMockList<string>(grouping.SelectMany(x => x)));
|
||||
.ToDictionary(grouping => grouping.Key, grouping => new WireMockList<string>(grouping.SelectMany(x => x).Select(WebUtility.UrlDecode)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,6 +75,24 @@ namespace WireMock.Net.Tests.Matchers
|
||||
Check.That(match).IsEqualTo(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonMatcher_IsMatch_JArray()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonMatcher(new[] { "x", "y" });
|
||||
|
||||
// Act
|
||||
var jArray = new JArray
|
||||
{
|
||||
"x",
|
||||
"y"
|
||||
};
|
||||
double match = matcher.IsMatch(jArray);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonMatcher_IsMatch_JObject()
|
||||
{
|
||||
@@ -139,6 +157,24 @@ namespace WireMock.Net.Tests.Matchers
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonMatcher_IsMatch_JArrayAsString()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonMatcher("[ \"x\", \"y\" ]");
|
||||
|
||||
// Act
|
||||
var jArray = new JArray
|
||||
{
|
||||
"x",
|
||||
"y"
|
||||
};
|
||||
double match = matcher.IsMatch(jArray);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonMatcher_IsMatch_JObjectAsString()
|
||||
{
|
||||
|
||||
@@ -188,6 +188,34 @@ namespace WireMock.Net.Tests.Util
|
||||
result["key"].Should().Equal(new WireMockList<string>(new[] { "1", "2", "3" }));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_With1ParamContainingEscapedAnd()
|
||||
{
|
||||
// Assign
|
||||
string query = "?winkel=C%26A";
|
||||
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
|
||||
// Assert
|
||||
result.Count.Should().Be(1);
|
||||
result["winkel"].Should().Equal(new WireMockList<string>(new[] { "C&A" }));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_With1ParamContainingParentheses()
|
||||
{
|
||||
// Assign
|
||||
string query = "?Transaction=(123)";
|
||||
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
|
||||
// Assert
|
||||
result.Count.Should().Be(1);
|
||||
result["Transaction"].Should().Equal(new WireMockList<string>(new[] { "(123)" }));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_WithMultipleParamWithSameKey()
|
||||
{
|
||||
@@ -227,12 +255,12 @@ namespace WireMock.Net.Tests.Util
|
||||
|
||||
// Assert
|
||||
result.Count.Should().Be(6);
|
||||
result["q"].Should().Equal(new WireMockList<string>("energy+edge"));
|
||||
result["q"].Should().Equal(new WireMockList<string>("energy edge"));
|
||||
result["rls"].Should().Equal(new WireMockList<string>("com.microsoft:en-au"));
|
||||
result["ie"].Should().Equal(new WireMockList<string>("UTF-8"));
|
||||
result["oe"].Should().Equal(new WireMockList<string>("UTF-8"));
|
||||
result["startIndex"].Should().Equal(new WireMockList<string>());
|
||||
result["startPage"].Should().Equal(new WireMockList<string>("1%22"));
|
||||
result["startPage"].Should().Equal(new WireMockList<string>("1\""));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user