public void Write_WithNull_DictionaryKeyPolicy_Works()
        {
            // Arrange
            var options = BlueprintJsonOptions.CreateOptions();

            options.DictionaryKeyPolicy = null;

            var value = new ProblemDetails
            {
                Title      = "Not found",
                Type       = "https://tools.ietf.org/html/rfc7231#section-6.5.4",
                Status     = 404,
                Extensions = new Dictionary <string, object>
                {
                    ["Key1"] = "Value1",
                }
            };
            var expected  = $"{{\"type\":\"{JsonEncodedText.Encode(value.Type)}\",\"title\":\"{value.Title}\",\"status\":{value.Status},\"Key1\":\"Value1\"}}";
            var converter = new ProblemDetailsJsonConverter();
            var stream    = new MemoryStream();

            // Act
            using (var writer = new Utf8JsonWriter(stream))
            {
                converter.Write(writer, value, options);
            }

            // Assert
            var actual = Encoding.UTF8.GetString(stream.ToArray());

            actual.Should().Be(expected);
        }
示例#2
0
        public void Write_WithNull_DictionaryKeyPolicy_Works()
        {
            // Arrange
            var options = BlueprintJsonOptions.CreateOptions();

            options.DictionaryKeyPolicy = null;

            var value = new ProblemDetails
            {
                Title      = "Not found",
                Type       = "https://tools.ietf.org/html/rfc7231#section-6.5.4",
                Status     = 404,
                Extensions = new Dictionary <string, object>
                {
                    ["Key1"] = "Value1",
                }
            };
            var expected = $"{{\"type\":\"{JsonEncodedText.Encode(value.Type)}\",\"title\":\"{value.Title}\",\"status\":{value.Status},\"Key1\":\"Value1\"}}";

            // Act
            var writtenJson = Write(value, options);

            writtenJson.Should().Be(expected);
        }
示例#3
0
        public void Write_WithNull_PropertyNamingPolicy_Works()
        {
            // Arrange
            var options = BlueprintJsonOptions.CreateOptions();

            options.PropertyNamingPolicy = null;

            var value = new ValidationProblemDetails(new Dictionary <string, IEnumerable <string> >
            {
                ["Property1"] = new [] { "Error 1" },
            })
            {
                Title  = "Validation error",
                Type   = "https://tools.ietf.org/html/rfc7231#section-6.5.4",
                Status = 400,
            };
            var expected = $"{{\"type\":\"{JsonEncodedText.Encode(value.Type)}\",\"title\":\"{value.Title}\",\"status\":{value.Status},\"errors\":{{\"Property1\":[\"Error 1\"]}}}}";

            // Act
            var actual = Write(value, options);

            // Assert
            actual.Should().Be(expected);
        }