@@ -9,10 +9,8 @@ namespace GraphQL.Client.Serializer.Tests;
9
9
10
10
public class ConsistencyTests
11
11
{
12
- [ Fact ]
13
- public void MapConvertersShouldBehaveConsistent ( )
14
- {
15
- const string json = @"{
12
+ [ Theory ]
13
+ [ InlineData ( @"{
16
14
""array"": [
17
15
""some stuff"",
18
16
""something else""
@@ -27,7 +25,26 @@ public void MapConvertersShouldBehaveConsistent()
27
25
{""number"": 1234.567},
28
26
{""number"": 567.8}
29
27
]
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
+ // }";
31
48
32
49
var newtonsoftSerializer = new NewtonsoftJsonSerializer ( ) ;
33
50
var systemTextJsonSerializer = new SystemTextJsonSerializer ( ) ;
@@ -45,16 +62,33 @@ public void MapConvertersShouldBehaveConsistent()
45
62
. RespectingRuntimeTypes ( ) ) ;
46
63
}
47
64
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 ( )
49
70
{
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
+ }
59
93
}
60
94
}
0 commit comments