From df8183f1dd07fbc2ac66661a9ac04d45f7a2cb36 Mon Sep 17 00:00:00 2001 From: Mikhail Preyskurantov <5574159+mpreyskurantov@users.noreply.github.com> Date: Fri, 23 Aug 2024 20:24:52 +0300 Subject: [PATCH] single binary filter expression operand value can be object {} --- .../DataSourceLoadOptionsParserTests.cs | 14 ++++++++++++++ .../DeserializeTests.cs | 7 +++++++ .../DeserializeTestsEx.cs | 7 +++++++ net/DevExtreme.AspNet.Data/Compatibility.cs | 2 ++ 4 files changed, 30 insertions(+) diff --git a/net/DevExtreme.AspNet.Data.Tests/DataSourceLoadOptionsParserTests.cs b/net/DevExtreme.AspNet.Data.Tests/DataSourceLoadOptionsParserTests.cs index 81aec9a1..dcb8d768 100644 --- a/net/DevExtreme.AspNet.Data.Tests/DataSourceLoadOptionsParserTests.cs +++ b/net/DevExtreme.AspNet.Data.Tests/DataSourceLoadOptionsParserTests.cs @@ -72,6 +72,20 @@ public void MustParseNull() { Assert.Equal(new[] { "fieldName", "=", null }, opts.Filter.Cast()); } + [Fact] + public void MustParseObject() { + var opts = new SampleLoadOptions(); + + DataSourceLoadOptionsParser.Parse(opts, key => { + if(key == DataSourceLoadOptionsParser.KEY_FILTER) + return @"[ ""fieldName1"", ""="", {""Value"":0} ]"; + return null; + }); + + Assert.Equal(3, opts.Filter.Count); + Assert.Equal("{\"Value\":0}", opts.Filter[2].ToString()); + } + [Fact] public void MustParseNumericAsString() { var opts = new SampleLoadOptions(); diff --git a/net/DevExtreme.AspNet.Data.Tests/DeserializeTests.cs b/net/DevExtreme.AspNet.Data.Tests/DeserializeTests.cs index 512ddcd4..5f57da8d 100644 --- a/net/DevExtreme.AspNet.Data.Tests/DeserializeTests.cs +++ b/net/DevExtreme.AspNet.Data.Tests/DeserializeTests.cs @@ -16,6 +16,13 @@ public void FilterOperandValueCanBeNull(string rawJsonCriteria) { var deserializedList = JsonSerializer.Deserialize(rawJsonCriteria, TESTS_DEFAULT_SERIALIZER_OPTIONS); Assert.Equal(3, deserializedList.Count); } + + [Fact] + public void FilterOperandValueCanBeObject() { + var deserializedList = JsonSerializer.Deserialize(@"[""fieldName1"",""="",{""Value"":0}]", TESTS_DEFAULT_SERIALIZER_OPTIONS); + Assert.Equal(3, deserializedList.Count); + Assert.Equal("{\"Value\":0}", deserializedList[2].ToString()); + } } } diff --git a/net/DevExtreme.AspNet.Data.Tests/DeserializeTestsEx.cs b/net/DevExtreme.AspNet.Data.Tests/DeserializeTestsEx.cs index c88d702b..a4135cb4 100644 --- a/net/DevExtreme.AspNet.Data.Tests/DeserializeTestsEx.cs +++ b/net/DevExtreme.AspNet.Data.Tests/DeserializeTestsEx.cs @@ -13,6 +13,13 @@ public void FilterOperandValueCanBeNull(string rawJsonCriteria) { var deserializedList = JsonConvert.DeserializeObject(rawJsonCriteria); Assert.Equal(3, deserializedList.Count); } + + [Fact] + public void FilterOperandValueCanBeObject() { + var deserializedList = JsonConvert.DeserializeObject(@"[""fieldName1"",""="",{""Value"":0}]"); + Assert.Equal(3, deserializedList.Count); + Assert.Equal("{\r\n \"Value\": 0\r\n}", deserializedList[2].ToString()); + } } } diff --git a/net/DevExtreme.AspNet.Data/Compatibility.cs b/net/DevExtreme.AspNet.Data/Compatibility.cs index 9b6e0ec9..ecdc0c6f 100644 --- a/net/DevExtreme.AspNet.Data/Compatibility.cs +++ b/net/DevExtreme.AspNet.Data/Compatibility.cs @@ -43,6 +43,8 @@ static object UnwrapJsonElement(object deserializeObject) { if(jsonElement.TryGetDecimal(out var decimalValue)) return decimalValue; throw new NotImplementedException(); + case JsonValueKind.Object: + return jsonElement; default: throw new NotImplementedException(); }