Ejemplo n.º 1
0
        private static void ShouldDeserializeJsonCorrectly(string json, HttpStatusCode statusCode, JsonNamingPolicy?namingPolicy = null)
        {
            var serializer  = new SystemTextJsonSerializerFactory().WithNamingPolicy(namingPolicy).CreateSerializer();
            var expectedDto = new Dto {
                StatusCode = statusCode
            };

            var dto = serializer.Deserialize <Dto>(json);

            dto.Should().BeEquivalentTo(expectedDto);
        }
Ejemplo n.º 2
0
            public void Should_override_naming_policy_for_particular_enum()
            {
                var serializer = new SystemTextJsonSerializerFactory()
                                 .WithNamingPolicy(new KebabCaseNamingPolicy())
                                 .IgnoreIndentation()
                                 .IgnoreNullValues(false)
                                 .SetCustomNamingPolicyForSerializationEnumOf <AnotherTestEnum>(JsonNamingPolicy.CamelCase)
                                 .CreateSerializer();

                ShouldSerializeDeserializeJsonCorrectly(
                    AnotherTestEnum.ManyWordsMember,
                    serializer,
                    "\"manyWordsMember\""
                    );
                ShouldSerializeDeserializeJsonCorrectly(
                    TestEnum.ManyWordsValue,
                    serializer,
                    nameof(TestEnum.ManyWordsValue).ToKebabCase().ToQuoted()
                    );
            }