public void BadUri()
        {
            var prefix     = "FooPrefix";
            var propPrefix = SettingsLoader.GetSettingKey(prefix, "foo");
            var settingKey = SettingsLoader.GetSettingKey(propPrefix, nameof(BadConversion.BadUri));
            var value      = "[]";

            var expectedMessage = string.Format(
                Resources.ConversionErrorSuffix,
                string.Format(
                    Resources.ConvertValueErrorFormat,
                    value,
                    typeof(Uri).FullName),
                settingKey);

            var settingsLoader = new SettingsLoader(new DictionaryValueProvider(new Dictionary <string, string>
            {
                { settingKey, "[]" },
            }));

            Assert.That(() => { settingsLoader.Create <BadConversion>(propPrefix); },
                        Throws
                        .Exception.TypeOf <SettingsException>()
                        .With.Message.EqualTo(expectedMessage)
                        );
        }
Example #2
0
        public void Test()
        {
            const string prefix = "Whatever";
            const string foo    = "My String foo";
            const string bar    = "My String bar";
            const string baz    = "My baz String";

            var settingsLoader = new SettingsLoader(new DictionaryValueProvider(new Dictionary <string, string>
            {
                { SettingsLoader.GetSettingKey(prefix, nameof(MultiLevel1.Foo)), foo },
                { SettingsLoader.GetSettingKey(prefix, nameof(MultiLevel1.Level2), nameof(MultiLevel2.Bar)), bar },
                { SettingsLoader.GetSettingKey(prefix, nameof(MultiLevel1.Level2), nameof(MultiLevel2.Level3), nameof(MultiLevel3.Baz)), baz },
            }));

            var setting = settingsLoader.Create <MultiLevel1>(prefix);

            var expected = new MultiLevel1()
            {
                Foo    = foo,
                Level2 = new MultiLevel2()
                {
                    Bar    = bar,
                    Level3 = new MultiLevel3()
                    {
                        Baz = baz
                    }
                }
            };

            Assert.That(setting, Is.Not.Null);
            Assert.That(setting, Is.DeepEqualTo(expected));
        }
Example #3
0
        public void Test()
        {
            const string @string = "My String foo";
            const string present = "World";
            var          nested  = new Nested {
                Foo = "Foo1", Bar = -15
            };
            var prefix = "Hello";
            var array  = new[] { " Mickey", "Mouse " };

            var settingsLoader = new SettingsLoader(new DictionaryValueProvider(new Dictionary <string, string>
            {
                { SettingsLoader.GetSettingKey(prefix, nameof(OptionalSettings.String)), @string },
                { SettingsLoader.GetSettingKey(prefix, nameof(OptionalSettings.OptionalPresent)), present },
                { SettingsLoader.GetSettingKey(prefix, nameof(OptionalSettings.OptionalNestedPresent), nameof(Nested.Foo)), nested.Foo },
                { SettingsLoader.GetSettingKey(prefix, nameof(OptionalSettings.OptionalNestedPresent), nameof(Nested.Bar)), nested.Bar.ToString() },
                { SettingsLoader.GetSettingKey(prefix, nameof(OptionalSettings.OptionalArrayPresent), "1"), array[0] },
                { SettingsLoader.GetSettingKey(prefix, nameof(OptionalSettings.OptionalArrayPresent), "2"), array[1] }
            }));

            var setting = settingsLoader.Create <OptionalSettings>(prefix);

            Assert.That(setting, Is.Not.Null);
            Assert.That(setting.String, Is.EqualTo(@string));
            Assert.That(setting.OptionalMissing, Is.Null);
            Assert.That(setting.OptionalPresent, Is.EqualTo(present));
            Assert.That(setting.OptionalNestedMissing, Is.Null);
            Assert.That(setting.OptionalNestedPresent, Is.DeepEqualTo(nested));
            Assert.That(setting.OptionalArrayMissing, Is.Null);
            Assert.That(setting.OptionalArrayPresent, Is.DeepEqualTo(array));
        }
Example #4
0
        public void BadTest()
        {
            const string foo = "Testing";
            const int    bar = 100;


            var prefix     = "MyPrefix";
            var propPrefix = SettingsLoader.GetSettingKey(prefix, nameof(InterfaceMapping.Prop));

            var settingsLoader = new SettingsLoader(new DictionaryValueProvider(new Dictionary <string, string>
            {
                { SettingsLoader.GetSettingKey(propPrefix, nameof(IMyInterface.Foo)), foo },
                { SettingsLoader.GetSettingKey(propPrefix, nameof(IMyInterface.Bar)), bar.ToString() },
            }));

            Assert.That(() => { settingsLoader.Create <BadInterfaceMapping>(prefix); }, Throws.Exception.TypeOf <ArgumentException>());
        }
        public void Test()
        {
            const string @string = "My String";
            var          prefix  = "Hello";

            var settingsLoader = new SettingsLoader(new DictionaryValueProvider(new Dictionary <string, string>
            {
                { SettingsLoader.GetSettingKey(prefix, nameof(IgnoreSettings.String)), @string },
            }));

            var setting = settingsLoader.Create <IgnoreSettings>(prefix);

            Assert.That(setting, Is.Not.Null);
            Assert.That(setting.String, Is.EqualTo(@string));
            Assert.That(setting.Ignored, Is.Null);
            Assert.That(setting.NestedIgnored, Is.Null);
            Assert.That(setting.TimeSpanIgnored, Is.Null);
        }
Example #6
0
        public void Test()
        {
            const string foo = "Testing";
            const int    bar = 100;


            var prefix     = "MyPrefix";
            var propPrefix = SettingsLoader.GetSettingKey(prefix, nameof(InterfaceMapping.Prop));

            var settingsLoader = new SettingsLoader(new DictionaryValueProvider(new Dictionary <string, string>
            {
                { SettingsLoader.GetSettingKey(propPrefix, nameof(IMyInterface.Foo)), foo },
                { SettingsLoader.GetSettingKey(propPrefix, nameof(IMyInterface.Bar)), bar.ToString() },
            }));

            var setting = settingsLoader.Create <InterfaceMapping>(prefix);

            Assert.That(setting, Is.Not.Null);
            Assert.That(setting.Prop, Is.Not.Null);
            Assert.That(setting.Prop.Foo, Is.EqualTo(foo));
            Assert.That(setting.Prop.Bar, Is.EqualTo(bar));
        }
        public void NoValueTest2()
        {
            var key = "Foo";

            // Pick any type to use as test type
            var someType = "";

            // Setup mock value provider with type
            var settingsLoader = new SettingsLoader(new DictionaryValueProvider(new Dictionary <string, string>
            {
                { key, someType }
            }));


            Assert.That(
                () => settingsLoader.Create <TypeSettings>(key),
                Throws.Exception.TypeOf <SettingsException>()
                .With.Message.EqualTo(string.Format(Resources.MissingValueFormat, typeof(Type).FullName, SettingsLoader.GetSettingKey(key, nameof(TypeSettings.MyType)))));
        }