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); }
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); }