Пример #1
0
        public void ToJson_Serialisation_Default_ContractResolver()
        {
            var c = new SerialisableClass
            {
                Prop1 = "Property 1",
                Prop2 = "Property 2",
                Prop3 = "Property 3"
            };

            var result = c.ToJson();

            result.Should().NotBeEmpty();
            result.Should().Contain("Property 1");
            result.Should().Contain("Property 2");
            result.Should().Contain("Property 3");
        }
Пример #2
0
        public void ToJson_Serialisation_Default_SpecificContract()
        {
            var c = new SerialisableClass
            {
                Prop1 = "Property 1",
                Prop2 = "Property 2",
                Prop3 = "Property 3"
            };

            var result = c.ToJson(new JsonSerializerSettings
            {
                ContractResolver = new JsonSerialisationContractResolver(new AntiProp2Contract())
            });

            result.Should().NotBeEmpty();
            result.Should().Contain("Property 1");
            result.Should().NotContain("Property 2");
            result.Should().Contain("Property 3");
        }