コード例 #1
0
        private static SettingsFiller GetBasicSettingsFiller()
        {
            var converterChooser    = new SettingsConverterChooser(new[] { new StringToFrameworkTypesConverter() });
            var rawSettingsProvider = new FromFuncProvider(key => key.ToString().Last().ToString());
            var settingsFiller      = new SettingsFiller(converterChooser, rawSettingsProvider);

            return(settingsFiller);
        }
コード例 #2
0
        public void SettingConverterChooserTest_StringToItsInterface()
        {
            var settingConverterChooser = new SettingsConverterChooser(new[] { new StringToFrameworkTypesConverter() });

            var strVal = settingConverterChooser.ChooseAndConvert <string, IConvertible>("123");

            Assert.AreEqual("123", strVal);
        }
コード例 #3
0
        public void NotInvariantCultureTest()
        {
            var converterChooser    = new SettingsConverterChooser(new[] { new StringToFrameworkTypesConverter() });
            var rawSettingsProvider = new FromFuncProvider(_ => "1 000,1");
            var settingsFiller      = new SettingsFiller(converterChooser, rawSettingsProvider);

            Assert.ThrowsException <RapidSettingsException>(() => settingsFiller.CreateWithSettings <NonInvariantDoubleSettings>());
        }
コード例 #4
0
        public void SettingConverterChooserTest_TToCovariance()
        {
            var settingConverterChooser = new SettingsConverterChooser(new[] { new SuperConverter() });

            var cInstance = new C();
            var bInstance = settingConverterChooser.ChooseAndConvert <C, B>(cInstance);

            Assert.AreSame(cInstance, bInstance);
        }
コード例 #5
0
        public void SettingConverterChooserTest_TFromCovariance()
        {
            var settingConverterChooser = new SettingsConverterChooser(new[] { new SuperConverter() });

            var bInstance = new B();
            var aInstance = settingConverterChooser.ChooseAndConvert <B, A>(bInstance);

            Assert.AreSame(bInstance, aInstance);
        }
コード例 #6
0
        public void SettingsFillerTest_NoProvider()
        {
            var converterChooser = new SettingsConverterChooser(new[] { new StringToFrameworkTypesConverter() });
            var settingsFiller   = new SettingsFiller(converterChooser, null);

            foreach (var settingsProviderWithKey in SettingsFillerStaticDefaults.DefaultRawSettingsProviders)
            {
                Assert.IsTrue(settingsFiller.RawSettingsProvidersByNames.ContainsKey(settingsProviderWithKey.Key));
                Assert.AreEqual(settingsFiller.RawSettingsProvidersByNames[settingsProviderWithKey.Key], settingsProviderWithKey.Value);
            }
        }
コード例 #7
0
        private static SettingsFiller GetAdvancedSettingsFiller()
        {
            var converterChooser     = new SettingsConverterChooser(new IRawSettingsConverter[] { new StringToFrameworkTypesConverter(), new SuperConverter() });
            var funcSettingsProvider = new FromFuncProvider(key => new C());
            var envSettingsProvider  = new FromEnvironmentProvider();
            var settingsFiller       = new SettingsFiller(converterChooser, new Dictionary <string, IRawSettingsProvider> {
                { "func", funcSettingsProvider }, { "env", envSettingsProvider }
            }, funcSettingsProvider);

            return(settingsFiller);
        }
コード例 #8
0
        public void SettingConverterChooserTest_ChooseProperConverter()
        {
            var settingConverterChooser = new SettingsConverterChooser(new IRawSettingsConverter[] { new SuperConverter(), new StringToFrameworkTypesConverter() });

            var bInstance = new B();
            var aInstance = settingConverterChooser.ChooseAndConvert <B, A>(bInstance);
            var strVal    = settingConverterChooser.ChooseAndConvert <string, IConvertible>("123");

            Assert.AreSame(bInstance, aInstance);
            Assert.AreEqual("123", strVal);
        }
コード例 #9
0
        public void NonNumericSimpleFrameworkStructsTest()
        {
            var converterChooser    = new SettingsConverterChooser(new[] { new StringToFrameworkTypesConverter() });
            var rawSettingsProvider = new FromFuncProvider(key =>
            {
                switch (key)
                {
                case string x when x.EndsWith(typeof(Guid).Name, StringComparison.InvariantCultureIgnoreCase):
                    return(Guid.NewGuid().ToString());

                case string x when x.EndsWith(typeof(bool).Name, StringComparison.InvariantCultureIgnoreCase):
                    return(bool.TrueString);

                case string x when x.EndsWith(typeof(string).Name, StringComparison.InvariantCultureIgnoreCase):
                    return("asdf");

                case string x when x.EndsWith(typeof(TimeSpan).Name, StringComparison.InvariantCultureIgnoreCase):
                    return("12:13:14");

                case string x when x.EndsWith(typeof(DateTime).Name, StringComparison.InvariantCultureIgnoreCase):
                    return("2000-01-01");

                case string x when x.EndsWith(typeof(DateTimeOffset).Name, StringComparison.InvariantCultureIgnoreCase):
                    return("2000-01-01");

                case string x when x.EndsWith(typeof(Uri).Name, StringComparison.InvariantCultureIgnoreCase):
                    return("https://nuget.org");

                case string x when x.EndsWith(typeof(DirectoryInfo).Name, StringComparison.InvariantCultureIgnoreCase):
                    return("D:\\SomeFolder");

                case string x when x.EndsWith(typeof(FileInfo).Name, StringComparison.InvariantCultureIgnoreCase):
                    return("filename.txt");

                default:
                    throw new ArgumentOutOfRangeException($"{nameof(key)} with value {key} is out of range of handled keys!");
                }
            });

            var settingsFiller = new SettingsFiller(converterChooser, rawSettingsProvider);

            var settings = settingsFiller.CreateWithSettings <NonNumericFrameworkTypesSettings>();

            Assert.AreEqual(true, settings.SomeBoolean);
            Assert.IsTrue(settings.SomeGuid != default(Guid));
            Assert.AreEqual("asdf", settings.SomeString);
            Assert.AreEqual(TimeSpan.Parse("12:13:14", CultureInfo.InvariantCulture), settings.SomeTimeSpan);
            Assert.AreEqual(DateTime.Parse("2000-01-01", CultureInfo.InvariantCulture), settings.SomeDateTime);
            Assert.AreEqual(DateTimeOffset.Parse("2000-01-01", CultureInfo.InvariantCulture), settings.SomeDateTimeOffset);
            Assert.AreEqual(new Uri("https://nuget.org"), settings.SomeUri);
            Assert.AreEqual(new DirectoryInfo("D:\\SomeFolder").FullName, settings.SomeDirectoryInfo.FullName);
            Assert.AreEqual(new FileInfo("filename.txt").FullName, settings.SomeFileInfo.FullName);
        }
コード例 #10
0
 public void SettingsFillerTest_NoProviders()
 {
     var converterChooser = new SettingsConverterChooser(new[] { new StringToFrameworkTypesConverter() });
     var settingsFiller   = new SettingsFiller(converterChooser, (IDictionary <string, IRawSettingsProvider>)null);
 }
コード例 #11
0
        public void SettingConverterChooserTest_NoSuitableConverter()
        {
            var settingConverterChooser = new SettingsConverterChooser(new[] { new SuperConverter() });

            settingConverterChooser.ChooseAndConvert <int, string>(3);
        }