Exemplo n.º 1
0
        public static void JsonNameConflictOnCamelCasingFail()
        {
            {
                // Baseline comparison - no options set.
                IntPropertyNamesDifferentByCaseOnly_TestClass obj = JsonSerializer.Deserialize <IntPropertyNamesDifferentByCaseOnly_TestClass>("{}");
                JsonSerializer.Serialize(obj);
            }

            {
                var options = new JsonSerializerOptions();
                options.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;

                Assert.Throws <InvalidOperationException>(() => JsonSerializer.Deserialize <IntPropertyNamesDifferentByCaseOnly_TestClass>("{}", options));
                Assert.Throws <InvalidOperationException>(() => JsonSerializer.Serialize(new IntPropertyNamesDifferentByCaseOnly_TestClass(), options));
            }

            {
                // Baseline comparison - no options set.
                ObjectPropertyNamesDifferentByCaseOnly_TestClass obj = JsonSerializer.Deserialize <ObjectPropertyNamesDifferentByCaseOnly_TestClass>("{}");
                JsonSerializer.Serialize(obj);
            }

            {
                var options = new JsonSerializerOptions();
                options.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;

                Assert.Throws <InvalidOperationException>(() => JsonSerializer.Deserialize <ObjectPropertyNamesDifferentByCaseOnly_TestClass>("{}", options));
                Assert.Throws <InvalidOperationException>(() => JsonSerializer.Serialize(new ObjectPropertyNamesDifferentByCaseOnly_TestClass(), options));
            }
        }
Exemplo n.º 2
0
        public async Task JsonNameConflictOnCamelCasingFail()
        {
            {
                // Baseline comparison - no options set.
                IntPropertyNamesDifferentByCaseOnly_TestClass obj = await JsonSerializerWrapperForString.DeserializeWrapper <IntPropertyNamesDifferentByCaseOnly_TestClass>("{}");

                await JsonSerializerWrapperForString.SerializeWrapper(obj);
            }

            {
                var options = new JsonSerializerOptions();
                options.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;

                await Assert.ThrowsAsync <InvalidOperationException>(async() => await JsonSerializerWrapperForString.DeserializeWrapper <IntPropertyNamesDifferentByCaseOnly_TestClass>("{}", options));

                await Assert.ThrowsAsync <InvalidOperationException>(async() => await JsonSerializerWrapperForString.SerializeWrapper(new IntPropertyNamesDifferentByCaseOnly_TestClass(), options));
            }

            {
                // Baseline comparison - no options set.
                ObjectPropertyNamesDifferentByCaseOnly_TestClass obj = await JsonSerializerWrapperForString.DeserializeWrapper <ObjectPropertyNamesDifferentByCaseOnly_TestClass>("{}");

                await JsonSerializerWrapperForString.SerializeWrapper(obj);
            }

            {
                var options = new JsonSerializerOptions();
                options.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;

                await Assert.ThrowsAsync <InvalidOperationException>(async() => await JsonSerializerWrapperForString.DeserializeWrapper <ObjectPropertyNamesDifferentByCaseOnly_TestClass>("{}", options));

                await Assert.ThrowsAsync <InvalidOperationException>(async() => await JsonSerializerWrapperForString.SerializeWrapper(new ObjectPropertyNamesDifferentByCaseOnly_TestClass(), options));
            }
        }