Exemplo n.º 1
0
        public void CanSerializeDeserializeEnumJson()
        {
            var options = new JsonSerializerOptions
            {
                PropertyNameCaseInsensitive = true,
                IgnoreNullValues            = true,
            };

            options.Converters.Add(new JsonEnumConverterFactory());

            var expected = new MixedContentIssueDetails
            {
                InsecureURL = "http://testing.domain/index.html",
                Frame       = new AffectedFrame
                {
                    FrameId = "123"
                },
                ResourceType = MixedContentResourceType.CSPReport
            };

            var serialize = JsonSerializer.Serialize(expected, options);
            var actual    = JsonSerializer.Deserialize <MixedContentIssueDetails>(serialize, options);

            Assert.Equal(expected.InsecureURL, actual.InsecureURL);
            Assert.Equal(expected.ResourceType, actual.ResourceType);
            Assert.Equal(expected.Frame.FrameId, actual.Frame.FrameId);
        }
Exemplo n.º 2
0
        public void CanConvertNullableEnumToJsonStringNotNull()
        {
            var options = new JsonSerializerOptions
            {
                PropertyNameCaseInsensitive = true,
                IgnoreNullValues            = true,
            };

            options.Converters.Add(new JsonEnumConverterFactory());

            var model = new MixedContentIssueDetails
            {
                InsecureURL  = "Testing",
                ResourceType = MixedContentResourceType.CSPReport
            };

            var expected = "{\"resourceType\":\"CSPReport\",\"resolutionStatus\":\"MixedContentBlocked\",\"insecureURL\":\"Testing\"}";
            var actual   = JsonSerializer.Serialize(model, options);

            Assert.Equal(expected, actual);
        }