From 13ab37dd3e072321797436c3009427e5160d6639 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Tue, 25 Feb 2020 22:17:15 +0100 Subject: [PATCH] LinqMatcher (#431) --- src/WireMock.Net/Util/JsonUtils.cs | 2 +- test/WireMock.Net.Tests/Matchers/LinqMatcherTests.cs | 5 +++-- test/WireMock.Net.Tests/Util/JsonUtilsTests.cs | 11 ++++++----- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/WireMock.Net/Util/JsonUtils.cs b/src/WireMock.Net/Util/JsonUtils.cs index 09beeafb..d3ef7f3b 100644 --- a/src/WireMock.Net/Util/JsonUtils.cs +++ b/src/WireMock.Net/Util/JsonUtils.cs @@ -151,7 +151,7 @@ namespace WireMock.Util break; case JTokenType.Integer: - castText = $"int({path})"; + castText = $"long({path})"; break; case JTokenType.Null: diff --git a/test/WireMock.Net.Tests/Matchers/LinqMatcherTests.cs b/test/WireMock.Net.Tests/Matchers/LinqMatcherTests.cs index f023acf1..85549ae6 100644 --- a/test/WireMock.Net.Tests/Matchers/LinqMatcherTests.cs +++ b/test/WireMock.Net.Tests/Matchers/LinqMatcherTests.cs @@ -70,12 +70,13 @@ namespace WireMock.Net.Tests.Matchers // Assign var input = new JObject { - { "Id", new JValue(9) }, + { "IntegerId", new JValue(9) }, + { "LongId", new JValue(long.MaxValue) }, { "Name", new JValue("Test") } }; // Act - var matcher = new LinqMatcher("Id > 1 AND Name == \"Test\""); + var matcher = new LinqMatcher("IntegerId > 1 AND LongId > 1 && Name == \"Test\""); double match = matcher.IsMatch(input); // Assert diff --git a/test/WireMock.Net.Tests/Util/JsonUtilsTests.cs b/test/WireMock.Net.Tests/Util/JsonUtilsTests.cs index fa748026..29631f7a 100644 --- a/test/WireMock.Net.Tests/Util/JsonUtilsTests.cs +++ b/test/WireMock.Net.Tests/Util/JsonUtilsTests.cs @@ -52,7 +52,7 @@ namespace WireMock.Net.Tests.Util {"Flt", new JValue(10.0f)}, {"Dbl", new JValue(Math.PI)}, {"Check", new JValue(true)}, - {"Items", new JArray(new[] {new JValue(4), new JValue(8)})}, + {"Items", new JArray(new[] { new JValue(4), new JValue(8) })}, { "Child", new JObject { @@ -61,7 +61,8 @@ namespace WireMock.Net.Tests.Util {"TS", new JValue(TimeSpan.FromMilliseconds(999))} } }, - {"Id", new JValue(9)}, + {"I", new JValue(9)}, + {"L", new JValue(long.MaxValue)}, {"Name", new JValue("Test")} }; @@ -70,10 +71,10 @@ namespace WireMock.Net.Tests.Util // Assert var queryable = new[] { j }.AsQueryable().Select(line); - bool result = queryable.Any("Id > 4"); + bool result = queryable.Any("I > 1 && L > 1"); Check.That(result).IsTrue(); - Check.That(line).IsEqualTo("new (Uri(U) as U, null as N, Guid(G) as G, double(Flt) as Flt, double(Dbl) as Dbl, bool(Check) as Check, (new [] { int(Items[0]), int(Items[1])}) as Items, new (int(Child.ChildId) as ChildId, DateTime(Child.ChildDateTime) as ChildDateTime, TimeSpan(Child.TS) as TS) as Child, int(Id) as Id, string(Name) as Name)"); + Check.That(line).IsEqualTo("new (Uri(U) as U, null as N, Guid(G) as G, double(Flt) as Flt, double(Dbl) as Dbl, bool(Check) as Check, (new [] { long(Items[0]), long(Items[1])}) as Items, new (long(Child.ChildId) as ChildId, DateTime(Child.ChildDateTime) as ChildDateTime, TimeSpan(Child.TS) as TS) as Child, long(I) as I, long(L) as L, string(Name) as Name)"); } [Fact] @@ -82,7 +83,7 @@ namespace WireMock.Net.Tests.Util // Assign var j = new JObject { - {"B", new JValue(new byte[] {48, 49})} + { "B", new JValue(new byte[] {48, 49}) } }; // Act and Assert