@@ -9,10 +9,8 @@ namespace GraphQL.Client.Serializer.Tests;
99
1010public class ConsistencyTests
1111{
12- [ Fact ]
13- public void MapConvertersShouldBehaveConsistent ( )
14- {
15- const string json = @"{
12+ [ Theory ]
13+ [ InlineData ( @"{
1614 ""array"": [
1715 ""some stuff"",
1816 ""something else""
@@ -27,7 +25,26 @@ public void MapConvertersShouldBehaveConsistent()
2725 {""number"": 1234.567},
2826 {""number"": 567.8}
2927 ]
30- }" ;
28+ }" ) ]
29+ [ InlineData ( "null" ) ]
30+ public void MapConvertersShouldBehaveConsistent ( string json )
31+ {
32+ //const string json = @"{
33+ // ""array"": [
34+ // ""some stuff"",
35+ // ""something else""
36+ // ],
37+ // ""string"": ""this is a string"",
38+ // ""boolean"": true,
39+ // ""number"": 1234.567,
40+ // ""nested object"": {
41+ // ""prop1"": false
42+ // },
43+ // ""arrayOfObjects"": [
44+ // {""number"": 1234.567},
45+ // {""number"": 567.8}
46+ // ]
47+ // }";
3148
3249 var newtonsoftSerializer = new NewtonsoftJsonSerializer ( ) ;
3350 var systemTextJsonSerializer = new SystemTextJsonSerializer ( ) ;
@@ -45,16 +62,33 @@ public void MapConvertersShouldBehaveConsistent()
4562 . RespectingRuntimeTypes ( ) ) ;
4663 }
4764
48- private void CompareMaps ( Dictionary < string , object > first , Dictionary < string , object > second )
65+ /// <summary>
66+ /// Regression test for https://github.com/graphql-dotnet/graphql-client/issues/601
67+ /// </summary>
68+ [ Fact ]
69+ public void MapConvertersShouldBeAbleToDeserializeNullValues ( )
4970 {
50- foreach ( var keyValuePair in first )
51- {
52- second . Should ( ) . ContainKey ( keyValuePair . Key ) ;
53- second [ keyValuePair . Key ] . Should ( ) . BeOfType ( keyValuePair . Value . GetType ( ) ) ;
54- if ( keyValuePair . Value is Dictionary < string , object > map )
55- CompareMaps ( map , ( Dictionary < string , object > ) second [ keyValuePair . Key ] ) ;
56- else
57- keyValuePair . Value . Should ( ) . BeEquivalentTo ( second [ keyValuePair . Key ] ) ;
58- }
71+ var newtonsoftSerializer = new NewtonsoftJsonSerializer ( ) ;
72+ var systemTextJsonSerializer = new SystemTextJsonSerializer ( ) ;
73+ string json = "null" ;
74+
75+ JsonConvert . DeserializeObject < Map > ( json , newtonsoftSerializer . JsonSerializerSettings ) . Should ( ) . BeNull ( ) ;
76+ System . Text . Json . JsonSerializer . Deserialize < Map > ( json , systemTextJsonSerializer . Options ) . Should ( ) . BeNull ( ) ;
77+ }
78+
79+ private void CompareMaps ( Dictionary < string , object > ? first , Dictionary < string , object > ? second )
80+ {
81+ if ( first is null )
82+ second . Should ( ) . BeNull ( ) ;
83+ else
84+ foreach ( var keyValuePair in first )
85+ {
86+ second . Should ( ) . ContainKey ( keyValuePair . Key ) ;
87+ second [ keyValuePair . Key ] . Should ( ) . BeOfType ( keyValuePair . Value . GetType ( ) ) ;
88+ if ( keyValuePair . Value is Dictionary < string , object > map )
89+ CompareMaps ( map , ( Dictionary < string , object > ) second [ keyValuePair . Key ] ) ;
90+ else
91+ keyValuePair . Value . Should ( ) . BeEquivalentTo ( second [ keyValuePair . Key ] ) ;
92+ }
5993 }
6094}
0 commit comments