Compare commits

..

2 Commits

Author SHA1 Message Date
Stef Heyenrath
7678e8fb70 1.0.41.0 2019-12-14 12:19:55 +01:00
Stef Heyenrath
8ae0abb023 . (#392) 2019-12-13 13:21:50 +01:00
7 changed files with 65 additions and 14 deletions

View File

@@ -1,5 +1,10 @@
# 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)

View File

@@ -4,7 +4,7 @@
</PropertyGroup>
<PropertyGroup>
<VersionPrefix>1.0.40</VersionPrefix>
<VersionPrefix>1.0.41</VersionPrefix>
</PropertyGroup>
<Choose>

View File

@@ -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.40.0
GitHubReleaseNotes.exe --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc --version 1.0.41.0

View File

@@ -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;

View File

@@ -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:

View File

@@ -19,10 +19,10 @@ 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);
}
public static T ParseJTokenToObject<T>(object value)

View File

@@ -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()
{