public void Write_PreservesNullParameters() { // Arrange var converter = new OpenIddictConverter(); using var stream = new MemoryStream(); using var reader = new StreamReader(stream); using var writer = new Utf8JsonWriter(stream); var message = new OpenIddictMessage(); message.AddParameter("string", new OpenIddictParameter((string)null)); message.AddParameter("bool", new OpenIddictParameter((bool?)null)); message.AddParameter("long", new OpenIddictParameter((long?)null)); message.AddParameter("array", new OpenIddictParameter((JsonElement?)null)); message.AddParameter("object", new OpenIddictParameter((JsonElement?)null)); // Act converter.Write(writer, value: message, options: null); // Assert writer.Flush(); stream.Seek(0L, SeekOrigin.Begin); Assert.Equal(@"{""string"":null,""bool"":null,""long"":null,""array"":null,""object"":null}", reader.ReadToEnd()); }
public void Write_ThrowsAnExceptionForNullValue() { // Arrange var converter = new OpenIddictConverter(); // Act and assert var exception = Assert.Throws <ArgumentNullException>(() => { converter.Write(writer: new Utf8JsonWriter(Stream.Null), value: null, options: null); }); Assert.Equal("value", exception.ParamName); }
public void Write_WritesEmptyPayloadForEmptyMessages() { // Arrange var message = new OpenIddictMessage(); var converter = new OpenIddictConverter(); using var stream = new MemoryStream(); using var reader = new StreamReader(stream); using var writer = new Utf8JsonWriter(stream); // Act converter.Write(writer, value: message, options: null); // Assert writer.Flush(); stream.Seek(0L, SeekOrigin.Begin); Assert.Equal("{}", reader.ReadToEnd()); }
public void Write_WritesExpectedPayload() { // Arrange var converter = new OpenIddictConverter(); using var stream = new MemoryStream(); using var reader = new StreamReader(stream); using var writer = new Utf8JsonWriter(stream); var message = new OpenIddictMessage(); message.AddParameter("string", "value"); message.AddParameter("array", new[] { "value" }); // Act converter.Write(writer, value: message, options: null); // Assert writer.Flush(); stream.Seek(0L, SeekOrigin.Begin); Assert.Equal(@"{""string"":""value"",""array"":[""value""]}", reader.ReadToEnd()); }
public void Write_PreservesEmptyParameters() { // Arrange var converter = new OpenIddictConverter(); using var stream = new MemoryStream(); using var reader = new StreamReader(stream); using var writer = new Utf8JsonWriter(stream); var message = new OpenIddictMessage(); message.AddParameter("string", new OpenIddictParameter(string.Empty)); message.AddParameter("array", new OpenIddictParameter(JsonSerializer.Deserialize <JsonElement>("[]"))); message.AddParameter("object", new OpenIddictParameter(JsonSerializer.Deserialize <JsonElement>("{}"))); // Act converter.Write(writer, value: message, options: null); // Assert writer.Flush(); stream.Seek(0L, SeekOrigin.Begin); Assert.Equal(@"{""string"":"""",""array"":[],""object"":{}}", reader.ReadToEnd()); }