Beispiel #1
0
 public virtual Config Config(LoadableConfig settingsClasses)
 {
     return(Config.builder().withSettings(_configuration).withConfigClasses(Collections.singletonList(settingsClasses)).build());
 }
        public void ShouldSerializeLoadableWithUndefinedLoadTimeout()
        {
            string json = @"{
                '$type': 'Org.Brixen.Config.LoadableConfig, Org.Brixen.Config'
            }";

            JObject jsonObj = JObject.Parse(json);

            ILoadableConfig config = new LoadableConfig();

            string output = JsonConvert.SerializeObject(config, Formatting.Indented, settings);
            JObject result = JObject.Parse(output);

            Assert.AreEqual(jsonObj, result, "The serialized JSON of a loadable config with an undefined load " +
                "timeout is not correct");
            Assert.IsNull(result.SelectToken("LoadTimeout"), "There should be no load timeout token in the " +
                "serialized JSON for a loadable config with an undefined load timeout");
        }
        public void ShouldSerializeLoadableConfigWithAdditionalProperties()
        {
            string json = @"{
                '$type': 'Org.Brixen.Config.LoadableConfig, Org.Brixen.Config',
                'LoadTimeout': 50,
                'field1':'field1_val',
                'field2':false,
                'field3':50
            }";

            JObject jsonObj = JObject.Parse(json);

            ILoadableConfig config = new LoadableConfig();
            config.LoadTimeout = new Optional<int>(50);
            config.AdditionalProperties.Add("field1", "field1_val");
            config.AdditionalProperties.Add("field2", false);
            config.AdditionalProperties.Add("field3", 50);

            string output = JsonConvert.SerializeObject(config, Formatting.Indented, settings);
            JObject result = JObject.Parse(output);

            Assert.AreEqual(jsonObj, result, "The serialized JSON for a loadable config with custom properties is " +
                "not correct");
            Assert.AreEqual(50, result.SelectToken("LoadTimeout").Value<int>(), "The serialized JSON for a loadable " +
                "config with a non-null load timeout and some custom properties should contain the load timeout " +
                "from the config");

            string field1 = result ["field1"].Value<string>();
            bool field2 = result ["field2"].Value<bool>();
            int field3 = result ["field3"].Value<int>();

            Assert.AreEqual("field1_val", field1, "The value of the a custom property in the serialized JSON for a " +
                "loadable config with custom properties is not correct");
            Assert.AreEqual(false, field2, "The value of the a custom property in the serialized JSON for a " +
                "loadable config with custom properties is not correct");
            Assert.AreEqual(50, field3, "The value of the a custom property in the serialized JSON for a " +
                "loadable config with custom properties is not correct");
        }
        public void ShouldSerializeLoadableWithNullLoadTimeout()
        {
            string json = @"{
                '$type': 'Org.Brixen.Config.LoadableConfig, Org.Brixen.Config',
                'LoadTimeout': null
            }";

            JObject jsonObj = JObject.Parse(json);

            ILoadableConfig config = new LoadableConfig();
            config.LoadTimeout = null;

            string output = JsonConvert.SerializeObject(config, Formatting.Indented, settings);
            JObject result = JObject.Parse(output);

            Assert.AreEqual(jsonObj, result, "The serialized JSON of a loadable config with a null load timeout is " +
                "not correct");
            Assert.IsFalse(result.SelectToken("LoadTimeout").HasValues, "There should be a token in the serialized " +
                "JSON for a loadable config with a null load timeout, but it should not have a value");
        }
        public void ShouldSerializeLoadableConfig()
        {
            string json = @"{
                '$type': 'Org.Brixen.Config.LoadableConfig, Org.Brixen.Config',
                'LoadTimeout': 50
            }";

            JObject jsonObj = JObject.Parse(json);

            ILoadableConfig config = new LoadableConfig();
            config.LoadTimeout = new Optional<int>(50);

            string output = JsonConvert.SerializeObject(config, Formatting.Indented, settings);
            JObject result = JObject.Parse(output);

            Assert.AreEqual(jsonObj, result, "The serialized JSON of a loadable config with a non-null load timeout " +
                "is not correct");
            Assert.AreEqual(50, result.SelectToken("LoadTimeout").Value<int>(), "The serialized JSON for a loadable " +
                "with a non-null load timeout should contain the load timeout value from the config");

            Assert.IsNull(result["AdditionalProperties"], "The serialized JSON for a loadable config with no custom " +
                "properties should not have a token for the custom properties map");
        }