public void Write() { // Arrange var value = new[] { new KeyValuePair <string, string>("key1", "value1"), new KeyValuePair <string, string>("key2", "value2") }; var ms = new MemoryStream(); var jsonWriter = new Utf8JsonWriter(ms); var options = new JsonSerializerOptions(); var converter = new KeyValuePairEnumerationConverter(); // Act converter.Write(jsonWriter, value, options); jsonWriter.Flush(); ms.Position = 0; var sr = new StreamReader(ms); var result = sr.ReadToEnd(); // Assert result.ShouldBe("{\"key1\":\"value1\",\"key2\":\"value2\"}"); }
public void Write_null() { // Arrange var value = (KeyValuePair <string, string>[])null; var ms = new MemoryStream(); var jsonWriter = new Utf8JsonWriter(ms); var options = new JsonSerializerOptions(); var converter = new KeyValuePairEnumerationConverter(); // Act converter.Write(jsonWriter, value, options); jsonWriter.Flush(); ms.Position = 0; var sr = new StreamReader(ms); var result = sr.ReadToEnd(); // Assert result.ShouldBeEmpty(); }