Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ public void MustNotParseDates() {
Assert.IsType<string>(opts.Filter[1]);
}

[Fact]
public void MustParseNull() {
var opts = new SampleLoadOptions();

DataSourceLoadOptionsParser.Parse(opts, key => {
if(key == DataSourceLoadOptionsParser.KEY_FILTER)
return @"[ ""fieldName"", ""="", null ]";
return null;
});

Assert.Equal(new[] { "fieldName", "=", null }, opts.Filter.Cast<string>());
}

[Fact]
public void MustParseNumericAsString() {
var opts = new SampleLoadOptions();
Expand Down
21 changes: 21 additions & 0 deletions net/DevExtreme.AspNet.Data.Tests/DeserializeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Collections;
using System.Text.Json;
using Xunit;

namespace DevExtreme.AspNet.Data.Tests {

public class DeserializeTests {
static readonly JsonSerializerOptions TESTS_DEFAULT_SERIALIZER_OPTIONS = new JsonSerializerOptions(JsonSerializerDefaults.Web) {
Converters = { new ListConverter() }
};

[Theory]
[InlineData(@"[""fieldName"",""="",null]")]
[InlineData(@"[[""fieldName1"",""="",""""],""and"",[""fieldName2"",""="",null]]")]
public void FilterOperandValueCanBeNull(string rawJsonCriteria) {
var deserializedList = JsonSerializer.Deserialize<IList>(rawJsonCriteria, TESTS_DEFAULT_SERIALIZER_OPTIONS);
Assert.Equal(3, deserializedList.Count);
}
}

}
19 changes: 19 additions & 0 deletions net/DevExtreme.AspNet.Data.Tests/DeserializeTestsEx.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#if NEWTONSOFT_TESTS
using System.Collections;
using Newtonsoft.Json;
using Xunit;

namespace DevExtreme.AspNet.Data.Tests {

public class DeserializeTestsEx {
[Theory]
[InlineData(@"[""fieldName"",""="",null]")]
[InlineData(@"[[""fieldName1"",""="",""""],""and"",[""fieldName2"",""="",null]]")]
public void FilterOperandValueCanBeNull(string rawJsonCriteria) {
var deserializedList = JsonConvert.DeserializeObject<IList>(rawJsonCriteria);
Assert.Equal(3, deserializedList.Count);
}
}

}
#endif
3 changes: 3 additions & 0 deletions net/DevExtreme.AspNet.Data/Compatibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public static IList UnwrapList(IList deserializedList) {
}

static object UnwrapJsonElement(object deserializeObject) {
if(deserializeObject == null)
return null;

if(!(deserializeObject is JsonElement jsonElement))
throw new InvalidOperationException();

Expand Down