@@ -61,6 +61,16 @@ private void ValidateSchema(SqlDataReader reader)
61
61
}
62
62
}
63
63
64
+ private void ValidateNullJson ( SqlDataReader reader )
65
+ {
66
+ while ( reader . Read ( ) )
67
+ {
68
+ bool IsNull = reader . IsDBNull ( 0 ) ;
69
+ _output . WriteLine ( IsNull ? "null" : "not null" ) ;
70
+ Assert . True ( IsNull ) ;
71
+ }
72
+ }
73
+
64
74
[ ConditionalFact ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . IsJsonSupported ) ) ]
65
75
public void TestJsonWrite ( )
66
76
{
@@ -286,5 +296,40 @@ public async Task TestJsonReadAsync()
286
296
}
287
297
}
288
298
}
299
+
300
+ [ ConditionalFact ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . IsJsonSupported ) ) ]
301
+ public void TestNullJson ( )
302
+ {
303
+ string tableName = DataTestUtility . GetUniqueNameForSqlServer ( "Json_Test" ) ;
304
+
305
+ string tableCreate = "CREATE TABLE " + tableName + " (Data json)" ;
306
+ string tableInsert = "INSERT INTO " + tableName + " VALUES (@jsonData)" ;
307
+ string tableRead = "SELECT * FROM " + tableName ;
308
+
309
+ using ( SqlConnection connection = new SqlConnection ( DataTestUtility . TCPConnectionString ) )
310
+ {
311
+ connection . Open ( ) ;
312
+ using ( SqlCommand command = connection . CreateCommand ( ) )
313
+ {
314
+ //Create Table
315
+ command . CommandText = tableCreate ;
316
+ command . ExecuteNonQuery ( ) ;
317
+
318
+ //Insert Null value
319
+ command . CommandText = tableInsert ;
320
+ var parameter = new SqlParameter ( "@jsonData" , SqlDbTypeExtensions . Json ) ;
321
+ parameter . Value = DBNull . Value ;
322
+ command . Parameters . Add ( parameter ) ;
323
+ command . ExecuteNonQuery ( ) ;
324
+
325
+ //Query the table
326
+ command . CommandText = tableRead ;
327
+ var reader = command . ExecuteReader ( ) ;
328
+
329
+ ValidateNullJson ( reader ) ;
330
+ reader . Close ( ) ;
331
+ }
332
+ }
333
+ }
289
334
}
290
335
}
0 commit comments