Skip to content

Commit 82aba9a

Browse files
Newtonsoft.Json -> System.Text.Json (#605)
1 parent 9068bca commit 82aba9a

22 files changed

+210
-91
lines changed

net/DevExtreme.AspNet.Data.Tests.Common/DevExtreme.AspNet.Data.Tests.Common.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net452;net6.0</TargetFrameworks>
4+
<TargetFrameworks>net461;net6.0</TargetFrameworks>
55
<RootNamespace>DevExtreme.AspNet.Data.Tests</RootNamespace>
66
<IsTestProject>False</IsTestProject>
77
</PropertyGroup>

net/DevExtreme.AspNet.Data.Tests.NET4/DevExtreme.AspNet.Data.Tests.NET4.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
<TargetFramework>net472</TargetFramework>
55
<RootNamespace>DevExtreme.AspNet.Data.Tests</RootNamespace>
66
<AssemblyName>DevExtreme.AspNet.Data.Tests</AssemblyName>
7-
<DefineConstants>NET4</DefineConstants>
7+
<DefineConstants>NET4;NEWTONSOFT_TESTS</DefineConstants>
88
</PropertyGroup>
99

1010
<ItemGroup>
1111
<Reference Include="Microsoft.CSharp" />
1212
<Reference Include="System.ComponentModel.DataAnnotations" />
1313
<Reference Include="System.Web.Extensions" />
1414

15-
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
15+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
1616
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.3.3" />
1717
<PackageReference Include="xunit" Version="2.4.2" />
1818
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />

net/DevExtreme.AspNet.Data.Tests/CustomFilterCompilersTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
using DevExtreme.AspNet.Data.Helpers;
2-
using Newtonsoft.Json;
2+
33
using System;
44
using System.Collections;
55
using System.Collections.Generic;
66
using System.Linq;
77
using System.Linq.Expressions;
8+
using System.Text.Json;
89
using Xunit;
910

1011
namespace DevExtreme.AspNet.Data.Tests {
@@ -34,7 +35,8 @@ public void OneToManyContains() {
3435
var source = new[] { new Category(), new Category() };
3536
source[0].Products.Add(new Product { Name = "Chai" });
3637

37-
var filter = JsonConvert.DeserializeObject<IList>(@"[ ""Products"", ""Contains"", ""ch"" ]");
38+
var deserializedList = JsonSerializer.Deserialize<IList>(@"[ ""Products"", ""Contains"", ""ch"" ]");
39+
var filter = Compatibility.UnwrapList(deserializedList);
3840

3941
var loadOptions = new SampleLoadOptions {
4042
Filter = filter,

net/DevExtreme.AspNet.Data.Tests/DataSourceLoadOptionsParserTests.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
using DevExtreme.AspNet.Data.Helpers;
2-
using System;
2+
33
using System.Collections.Generic;
44
using System.Linq;
5-
using System.Threading.Tasks;
65
using Xunit;
76

87
namespace DevExtreme.AspNet.Data.Tests {
@@ -60,6 +59,21 @@ public void MustNotParseDates() {
6059
Assert.IsType<string>(opts.Filter[1]);
6160
}
6261

62+
[Fact]
63+
public void MustParseNumericAsString() {
64+
var opts = new SampleLoadOptions();
65+
66+
DataSourceLoadOptionsParser.Parse(opts, key => {
67+
if(key == DataSourceLoadOptionsParser.KEY_GROUP)
68+
return @"[{""selector"":""freight"",""groupInterval"":100,""isExpanded"":false}]";
69+
return null;
70+
});
71+
72+
Assert.Equal("freight", opts.Group[0].Selector);
73+
Assert.Equal("100", opts.Group[0].GroupInterval);
74+
Assert.False(opts.Group[0].IsExpanded);
75+
}
76+
6377
}
6478

6579
}

net/DevExtreme.AspNet.Data.Tests/DevExtreme.AspNet.Data.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFrameworks>net6.0</TargetFrameworks>
5+
<DefineConstants>NEWTONSOFT_TESTS</DefineConstants>
56
</PropertyGroup>
67

78
<ItemGroup>

net/DevExtreme.AspNet.Data.Tests/DynamicBindingTests.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
using DevExtreme.AspNet.Data.ResponseModel;
2-
using Newtonsoft.Json;
3-
using Newtonsoft.Json.Linq;
2+
43
using System;
54
using System.Collections;
65
using System.Collections.Generic;
76
using System.Dynamic;
87
using System.Linq;
9-
using System.Text;
108
using Xunit;
119

10+
#if NEWTONSOFT_TESTS
11+
using Newtonsoft.Json;
12+
using Newtonsoft.Json.Linq;
13+
#endif
14+
1215
namespace DevExtreme.AspNet.Data.Tests {
1316

1417
public class DynamicBindingTests {
@@ -70,6 +73,7 @@ public void Filter() {
7073
Assert.Equal(2d, expandoResult[0][P1]);
7174
}
7275

76+
#if NEWTONSOFT_TESTS
7377
[Fact]
7478
public void Filter_JValueNull() {
7579
var result = ToDictArray(DataSourceLoader.Load(
@@ -83,6 +87,7 @@ public void Filter_JValueNull() {
8387

8488
Assert.Single(result);
8589
}
90+
#endif
8691

8792
[Fact]
8893
public void Filter_Null() {
@@ -147,6 +152,7 @@ public void Grouping() {
147152
Assert.Equal(4m, expandoResult[1].summary[0]);
148153
}
149154

155+
#if NEWTONSOFT_TESTS
150156
[Fact]
151157
public void JArray() {
152158
var sourceData = JsonConvert.DeserializeObject<JArray>(@"[
@@ -167,6 +173,7 @@ public void JArray() {
167173

168174
Assert.Equal(4m, result.summary[0]);
169175
}
176+
#endif
170177

171178
[Fact]
172179
public void T598818() {
@@ -213,6 +220,7 @@ public void Issue227() {
213220
Assert.Single(loadResult.data);
214221
}
215222

223+
#if NEWTONSOFT_TESTS
216224
[Fact]
217225
public void NoToStringForNumbers() {
218226
var compiler = new FilterExpressionCompiler(typeof(object), false);
@@ -229,6 +237,7 @@ void Case(IList clientFilter, string expectedExpr, object trueTestValue) {
229237
10
230238
);
231239
}
240+
#endif
232241

233242
[Fact]
234243
public void T714342() {

net/DevExtreme.AspNet.Data.Tests/FilterExpressionCompilerTests.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
using Newtonsoft.Json;
2-
using System;
1+
using System;
32
using System.Collections;
43
using System.Collections.Generic;
54
using System.Linq;
65
using System.Linq.Expressions;
7-
using System.Threading.Tasks;
6+
using System.Text.Json;
87
using Xunit;
98

109
namespace DevExtreme.AspNet.Data.Tests {
@@ -144,7 +143,8 @@ public void Not() {
144143

145144
[Fact]
146145
public void IsUnaryWithJsonCriteria() {
147-
var crit = JsonConvert.DeserializeObject<IList>("[\"!\", []]");
146+
var deserializedList = JsonSerializer.Deserialize<IList>("[\"!\", []]");
147+
var crit = Compatibility.UnwrapList(deserializedList);
148148
var compiler = new FilterExpressionCompiler(typeof(object), false);
149149
Assert.True(compiler.IsUnary(crit));
150150
}
@@ -241,7 +241,8 @@ public void T105740() {
241241

242242
[Fact]
243243
public void JsonObjects() {
244-
var crit = (IList)JsonConvert.DeserializeObject(@"[ [ ""StringProp"", ""abc"" ], [ ""NullableProp"", null ] ]");
244+
var deserializedList = JsonSerializer.Deserialize<IList>(@"[ [ ""StringProp"", ""abc"" ], [ ""NullableProp"", null ] ]");
245+
var crit = Compatibility.UnwrapList(deserializedList);
245246
var expr = Compile<DataItem1>(crit);
246247
Assert.Equal(@"((obj.StringProp == ""abc"") AndAlso (obj.NullableProp == null))", expr.Body.ToString());
247248
}

net/DevExtreme.AspNet.Data.Tests/FilterExpressionCompilerTypeConversionTests.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
using Newtonsoft.Json;
2-
using System;
3-
using System.Collections;
4-
using System.Collections.Generic;
5-
using System.Linq;
6-
using System.Threading.Tasks;
1+
using System;
72
using Xunit;
83

4+
#if NEWTONSOFT_TESTS
5+
using System.Collections;
6+
using Newtonsoft.Json;
7+
#endif
8+
99
namespace DevExtreme.AspNet.Data.Tests {
1010

1111
public class FilterExpressionCompilerTypeConversionTests {
@@ -225,11 +225,15 @@ public void StringFuncOnTimeSpan() {
225225
AssertEvaluation(obj, new[] { "NullableTime", "contains", "23" });
226226
}
227227

228+
#if NEWTONSOFT_TESTS
228229
[Theory]
229230
[InlineData(DateParseHandling.None)]
230231
[InlineData(DateParseHandling.DateTime)]
231232
[InlineData(DateParseHandling.DateTimeOffset)]
232233
public void Issue477(DateParseHandling dateParseHandling) {
234+
//https://github.com/DevExpress/DevExtreme.AspNet.Data/pull/478
235+
//https://github.com/DevExpress/DevExtreme.AspNet.Data/issues/477
236+
233237
var date = new DateTimeOffset(2021, 1, 1, 0, 0, 0, TimeSpan.Zero);
234238
var filterJSON = JsonConvert.SerializeObject(new object[] { "this", date });
235239
var deserializedFilter = JsonConvert.DeserializeObject<IList>(filterJSON, new JsonSerializerSettings {
@@ -243,6 +247,7 @@ public void Issue477(DateParseHandling dateParseHandling) {
243247
var loadResult = DataSourceLoader.Load(new[] { date }, loadOptions);
244248
Assert.Single(loadResult.data);
245249
}
250+
#endif
246251
}
247252

248253
}

net/DevExtreme.AspNet.Data.Tests/GroupHelperTests.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
using DevExtreme.AspNet.Data.Helpers;
22
using DevExtreme.AspNet.Data.ResponseModel;
3-
using Newtonsoft.Json;
43
using System;
54
using System.Collections.Generic;
6-
using System.Linq;
7-
using System.Threading.Tasks;
85
using Xunit;
96

107
namespace DevExtreme.AspNet.Data.Tests {

net/DevExtreme.AspNet.Data.Tests/PaginateViaPrimaryKeyTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using Newtonsoft.Json;
2-
using System;
1+
using System;
32
using System.Linq;
3+
using System.Text.Json;
44
using Xunit;
55

66
namespace DevExtreme.AspNet.Data.Tests {
@@ -133,7 +133,7 @@ public void Bug349() {
133133
}
134134

135135
static string DataToString(object data) {
136-
return JsonConvert.SerializeObject(data).Replace("\"", "");
136+
return JsonSerializer.Serialize(data).Replace("\"", "");
137137
}
138138

139139
}

0 commit comments

Comments
 (0)