@@ -307,6 +307,66 @@ public void Reformats_raw_json_string_with_unquoted_keys()
307307 output . Should ( ) . Be ( minifiedExpectedJson ) ;
308308 }
309309
310+ [ TestMethod ]
311+ [ DeploymentItem ( @"Data\NullResourceResult.json" ) ]
312+ public void Serializes_null_resource_properly ( )
313+ {
314+ // Arrange
315+ var modelManager = new ModelManager ( new PluralizationService ( ) ) ;
316+ modelManager . RegisterResourceType ( typeof ( Comment ) ) ;
317+ var formatter = new JsonApiFormatter ( modelManager ) ;
318+ MemoryStream stream = new MemoryStream ( ) ;
319+
320+ // Act
321+ formatter . WriteToStreamAsync ( typeof ( Comment ) , null , stream , null , null ) ;
322+
323+ // Assert
324+ var minifiedExpectedJson = JsonHelpers . MinifyJson ( File . ReadAllText ( "NullResourceResult.json" ) ) ;
325+ string output = System . Text . Encoding . ASCII . GetString ( stream . ToArray ( ) ) ;
326+ Trace . WriteLine ( output ) ;
327+ output . Should ( ) . Be ( minifiedExpectedJson ) ;
328+ }
329+
330+ [ TestMethod ]
331+ [ DeploymentItem ( @"Data\EmptyArrayResult.json" ) ]
332+ public void Serializes_null_resource_array_as_empty_array ( )
333+ {
334+ // Arrange
335+ var modelManager = new ModelManager ( new PluralizationService ( ) ) ;
336+ modelManager . RegisterResourceType ( typeof ( Comment ) ) ;
337+ var formatter = new JsonApiFormatter ( modelManager ) ;
338+ MemoryStream stream = new MemoryStream ( ) ;
339+
340+ // Act
341+ formatter . WriteToStreamAsync ( typeof ( Comment [ ] ) , null , stream , null , null ) ;
342+
343+ // Assert
344+ var minifiedExpectedJson = JsonHelpers . MinifyJson ( File . ReadAllText ( "EmptyArrayResult.json" ) ) ;
345+ string output = System . Text . Encoding . ASCII . GetString ( stream . ToArray ( ) ) ;
346+ Trace . WriteLine ( output ) ;
347+ output . Should ( ) . Be ( minifiedExpectedJson ) ;
348+ }
349+
350+ [ TestMethod ]
351+ [ DeploymentItem ( @"Data\EmptyArrayResult.json" ) ]
352+ public void Serializes_null_list_as_empty_array ( )
353+ {
354+ // Arrange
355+ var modelManager = new ModelManager ( new PluralizationService ( ) ) ;
356+ modelManager . RegisterResourceType ( typeof ( Comment ) ) ;
357+ var formatter = new JsonApiFormatter ( modelManager ) ;
358+ MemoryStream stream = new MemoryStream ( ) ;
359+
360+ // Act
361+ formatter . WriteToStreamAsync ( typeof ( List < Comment > ) , null , stream , null , null ) ;
362+
363+ // Assert
364+ var minifiedExpectedJson = JsonHelpers . MinifyJson ( File . ReadAllText ( "EmptyArrayResult.json" ) ) ;
365+ string output = System . Text . Encoding . ASCII . GetString ( stream . ToArray ( ) ) ;
366+ Trace . WriteLine ( output ) ;
367+ output . Should ( ) . Be ( minifiedExpectedJson ) ;
368+ }
369+
310370 [ TestMethod ]
311371 [ DeploymentItem ( @"Data\MalformedRawJsonString.json" ) ]
312372 public void Does_not_serialize_malformed_raw_json_string ( )
0 commit comments