Esempio n. 1
0
        public void ReturnsNullOnPropertyThatCannotBeParsed()
        {
            var configSet = new TestConfigurationSet
            {
                ConfigOne = new Config <TestConfigOne>(new TestConfigOne {
                    IntProperty = 2
                }),
                ConfigTwo = new Config <TestConfigTwo>(new TestConfigTwo {
                    StringProperty = "Test"
                })
            };
            var jsonOne = JsonConvert.SerializeObject(configSet.ConfigOne.Value);
            var json    = $"{{\"ConfigOne\":{jsonOne},\"ConfigTwo\":{jsonOne}}}";

            var result = target.MapConfigurationSetUpload(json, model).ToDictionary(k => k.Key, v => v.Value);

            Assert.Equal(2, result.Count);
            var configOne = result[nameof(TestConfigurationSet.ConfigOne)] as TestConfigOne;

            Assert.NotNull(configOne);
            Assert.Equal(configSet.ConfigOne.Value.IntProperty, configOne.IntProperty);
            var configTwo = result[nameof(TestConfigurationSet.ConfigTwo)] as TestConfigTwo;

            Assert.Null(configTwo);
        }
        public void CanParseFullConfigurationSet()
        {
            var configSet = new TestConfigurationSet
            {
                ConfigOne = new TestConfigOne {
                    IntProperty = 2
                },
                ConfigTwo = new TestConfigTwo {
                    StringProperty = "Test"
                }
            };
            var json    = JsonConvert.SerializeObject(configSet);
            var jObject = JObject.Parse(json);
            var result  = target.MapConfigurationSetUpload(jObject, model).ToDictionary(k => k.Key, v => v.Value);

            Assert.Equal(2, result.Count);
            var configOne = result[nameof(TestConfigurationSet.ConfigOne)] as TestConfigOne;

            Assert.NotNull(configOne);
            Assert.Equal(configSet.ConfigOne.IntProperty, configOne.IntProperty);
            var configTwo = result[nameof(TestConfigurationSet.ConfigTwo)] as TestConfigTwo;

            Assert.NotNull(configTwo);
            Assert.Equal(configSet.ConfigTwo.StringProperty, configTwo.StringProperty);
        }
Esempio n. 3
0
        public void DoesNotReturnNullIfPropertyWasNotFound()
        {
            var configSet = new TestConfigurationSet
            {
                ConfigOne = new Config <TestConfigOne>(new TestConfigOne {
                    IntProperty = 2
                }),
                ConfigTwo = new Config <TestConfigTwo>(new TestConfigTwo {
                    StringProperty = "Test"
                })
            };
            var jsonOne = JsonConvert.SerializeObject(configSet.ConfigOne.Value);
            var json    = $"{{\"ConfigOne\":{jsonOne}}}";

            var result = target.MapConfigurationSetUpload(json, model).ToDictionary(k => k.Key, v => v.Value);

            Assert.Single(result);
            var configOne = result[nameof(TestConfigurationSet.ConfigOne)] as TestConfigOne;

            Assert.NotNull(configOne);
            Assert.Equal(configSet.ConfigOne.Value.IntProperty, configOne.IntProperty);
        }
        public void IgnorePropertiesNotInConfigSet()
        {
            var configSet = new TestConfigurationSet
            {
                ConfigOne = new Config <TestConfigOne>(new TestConfigOne {
                    IntProperty = 2
                }),
                ConfigTwo = new Config <TestConfigTwo>(new TestConfigTwo {
                    StringProperty = "Test"
                })
            };
            var jsonOne = JsonConvert.SerializeObject(configSet.ConfigOne.Value);
            var json    = $"{{\"ConfigOne\":{jsonOne},\"Meta\":{jsonOne}}}";

            var jObject = JObject.Parse(json);
            var result  = target.MapConfigurationSetUpload(jObject, model).ToDictionary(k => k.Key, v => v.Value);

            Assert.Equal(1, result.Count);
            var configOne = result[nameof(TestConfigurationSet.ConfigOne)] as TestConfigOne;

            Assert.NotNull(configOne);
            Assert.Equal(configSet.ConfigOne.Value.IntProperty, configOne.IntProperty);
        }