Inheritance: ISettingLoader
Beispiel #1
0
        public void AppSettings_Load_DevConnectionStringsOverrides()
        {
            string csName   = "OptionalSetting";
            string expected = "dev";

            string csName2   = "cs2";
            string expected2 = "value2";

            var devLoader = new SettingLoaderMock();

            devLoader.ConnectionStrings.Add(csName, expected);

            var prodLoader = new SettingLoaderMock();

            prodLoader.ConnectionStrings.Add(csName, "prod");
            prodLoader.ConnectionStrings.Add(csName2, expected2);

            var settings = new SettingsConnectionStrings();

            AppSettingsLoader.DevSettings = devLoader;
            Assert.IsTrue(AppSettingsLoader.Load(prodLoader, ref settings), "Load returned false");

            Assert.AreEqual(2, settings.ConnectionStrings.Count);
            Assert.AreEqual(settings.ConnectionStrings[csName], expected);
            Assert.AreEqual(settings.ConnectionStrings[csName2], expected2);
        }
Beispiel #2
0
        public void AppSettingsLoader_Load_CollectionHandlesTypes()
        {
            var mockSettingsLoader = new SettingLoaderMock();

            mockSettingsLoader.Settings.Add("StringCollection", "string1,string2,string3");
            mockSettingsLoader.Settings.Add("IntCollection", "1,2,3");
            mockSettingsLoader.Settings.Add("EnumCollection", "Option0,Option1,Option2");

            var settings = new SettingsCollections();

            Assert.IsTrue(AppSettingsLoader.Load(mockSettingsLoader, ref settings), "Load returned false");

            CollectionAssert.AreEqual(
                mockSettingsLoader.Settings["StringCollection"].Split(','),
                settings.StringCollection.ToArray(),
                "String collection not set");

            CollectionAssert.AreEqual(
                mockSettingsLoader.Settings["IntCollection"].Split(',').Select(i => Int32.Parse(i)).ToArray(),
                settings.IntCollection.ToArray(),
                "Int collection not set");

            CollectionAssert.AreEqual(
                mockSettingsLoader.Settings["EnumCollection"].Split(',').Select(e => Enum.Parse(typeof(Option), e, false)).ToArray(),
                settings.EnumCollection.ToArray(),
                "Enum collection not set");
        }
Beispiel #3
0
        public void AppSettingsLoader_Load_CollectionHandlesTypes()
        {
            var mockSettingsLoader = new SettingLoaderMock();

            mockSettingsLoader.Settings.Add("StringCollection", "string1,string2,string3");
            mockSettingsLoader.Settings.Add("IntCollection", "1,2,3");
            mockSettingsLoader.Settings.Add("EnumCollection", "Option0,Option1,Option2");

            var settings = new SettingsCollections();

            Assert.IsTrue(AppSettingsLoader.Load(mockSettingsLoader, ref settings), "Load returned false");

            CollectionAssert.AreEqual(
                mockSettingsLoader.Settings["StringCollection"].Split(','),
                settings.StringCollection.ToArray(),
                "String collection not set");

            CollectionAssert.AreEqual(
                mockSettingsLoader.Settings["IntCollection"].Split(',').Select(i => Int32.Parse(i)).ToArray(),
                settings.IntCollection.ToArray(),
                "Int collection not set");

            CollectionAssert.AreEqual(
                mockSettingsLoader.Settings["EnumCollection"].Split(',').Select(e => Enum.Parse(typeof(Option), e, false)).ToArray(),
                settings.EnumCollection.ToArray(),
                "Enum collection not set");
        }
Beispiel #4
0
        public void AppSettingsLoader_Load_NoExceptionIfHasOptionalSettingOnClass()
        {
            var mockSettingsLoader = new SettingLoaderMock();

            var settings = new SettingsOptionalClass();

            AppSettingsLoader.Load(mockSettingsLoader, ref settings);
        }
Beispiel #5
0
        public void AppSettingsLoader_Load_ExceptionIfRequiredSettingDoesNotExist()
        {
            var mockSettingsLoader = new SettingLoaderMock();

            var settings3 = new Settings3();

            AppSettingsLoader.Load(mockSettingsLoader, ref settings3);
        }
Beispiel #6
0
        public void AppSettingsLoader_Load_ExceptionIfRequiredSettingDoesNotExist()
        {
            var mockSettingsLoader = new SettingLoaderMock();

            var settings = new SettingsOptional();

            AppSettingsLoader.Load(mockSettingsLoader, ref settings);
        }
Beispiel #7
0
        public void AppSettingsLoader_Load_NoExceptionWhenClassOptional()
        {
            var mockSettingsLoader = new SettingLoaderMock();
            var settings           = new SettingsOptionalConnectionString();

            // Should not throw an exception
            AppSettingsLoader.Load(mockSettingsLoader, ref settings);
            Assert.IsNull(settings.ConnectionString);
        }
Beispiel #8
0
        public void AppSettingsLoader_Load_LoadsBool()
        {
            var mockSettingsLoader = new SettingLoaderMock();

            mockSettingsLoader.Settings.Add("IsTrue", "true");

            var settings = new Settings();

            Assert.IsTrue(AppSettingsLoader.Load(mockSettingsLoader, ref settings), "Load returned false");
            Assert.IsTrue(settings.IsTrue, "Boolean setting not set to true");
        }
Beispiel #9
0
        public void AppSettingsLoader_Load_LoadsUndecoratedPropertyWhenClassIsDecorated()
        {
            var mockSettingsLoader = new SettingLoaderMock();

            mockSettingsLoader.Settings.Add("Is42", "42");

            var settings2 = new Settings2();

            Assert.IsTrue(AppSettingsLoader.Load(mockSettingsLoader, ref settings2), "Load returned false");
            Assert.AreEqual(42, settings2.Is42, "Int setting not set");
        }
Beispiel #10
0
        public void AppSettingsLoader_Load_UsesKeyOverride()
        {
            var mockSettingsLoader = new SettingLoaderMock();

            mockSettingsLoader.Settings.Add("IsFooBar", "Foobar");

            var settings2 = new Settings2();

            Assert.IsTrue(AppSettingsLoader.Load(mockSettingsLoader, ref settings2), "Load returned false");
            Assert.AreEqual("Foobar", settings2.IsFoo, "String setting not set");
        }
Beispiel #11
0
        public void AppSettingsLoader_Load_NoExceptionIfOptionalSettingDoesNotExist()
        {
            var mockSettingsLoader = new SettingLoaderMock();

            // Set the required setting to avoid the exception, but don't set the optional setting
            mockSettingsLoader.Settings.Add("RequiredSetting", "Exists");

            var settings3 = new Settings3();

            AppSettingsLoader.Load(mockSettingsLoader, ref settings3);
        }
Beispiel #12
0
        public void AppSettingsLoader_Load_LoadsInt()
        {
            var mockSettingsLoader = new SettingLoaderMock();

            mockSettingsLoader.Settings.Add("Is42", "42");

            var settings = new Settings();

            Assert.IsTrue(AppSettingsLoader.Load(mockSettingsLoader, ref settings), "Load returned false");
            Assert.AreEqual(42, settings.Is42, "Int setting not set");
        }
Beispiel #13
0
        public void AppSettingsLoader_Load_LoadsString()
        {
            var mockSettingsLoader = new SettingLoaderMock();

            mockSettingsLoader.Settings.Add("IsFoobar", "Foobar");

            var settings = new Settings();

            Assert.IsTrue(AppSettingsLoader.Load(mockSettingsLoader, ref settings), "Load returned false");
            Assert.AreEqual("Foobar", settings.IsFoobar, "String setting not set");
        }
Beispiel #14
0
        public void AppSettingsLoader_Load_LoadsEnumByValue()
        {
            var    mockSettingsLoader = new SettingLoaderMock();
            Option option             = Option.Option2;

            mockSettingsLoader.Settings.Add("IsOption2", ((int)option).ToString());

            var settings = new Settings();

            Assert.IsTrue(AppSettingsLoader.Load(mockSettingsLoader, ref settings), "Load returned false");
            Assert.AreEqual(option, settings.IsOption2, "Enum setting not set");
        }
Beispiel #15
0
        public void AppSettingsLoader_Load_LoadsGuid()
        {
            var  mockSettingsLoader = new SettingLoaderMock();
            Guid guid = Guid.NewGuid();

            mockSettingsLoader.Settings.Add("IsGuid", guid.ToString());

            var settings = new Settings();

            Assert.IsTrue(AppSettingsLoader.Load(mockSettingsLoader, ref settings), "Load returned false");
            Assert.AreEqual(guid, settings.IsGuid, "Guid setting not set");
        }
Beispiel #16
0
        public void AppSettingsLoader_Load_LoadsDateTime()
        {
            var      mockSettingsLoader = new SettingLoaderMock();
            DateTime today = DateTime.Today;

            mockSettingsLoader.Settings.Add("IsToday", today.ToString());

            var settings = new Settings();

            Assert.IsTrue(AppSettingsLoader.Load(mockSettingsLoader, ref settings), "Load returned false");
            Assert.AreEqual(today, settings.IsToday, "DateTime setting not set");
        }
Beispiel #17
0
        public void AppSetingsLoader_Load_LoadsAConnectionString()
        {
            var connectionStringName = "SingleConnectionString";
            var connectionStringValue = "ConnectionStringValue";
            var mockSettingLoader = new SettingLoaderMock();

            mockSettingLoader.ConnectionStrings.Add(connectionStringName, connectionStringValue);

            var settings = new Settings();

            Assert.IsTrue(AppSettingsLoader.Load(mockSettingLoader, ref settings), "Load returned flase");
            Assert.AreEqual(connectionStringValue, settings.SingleConnectionString);
        }
Beispiel #18
0
        public void AppSetingsLoader_Load_LoadsAConnectionString()
        {
            var connectionStringName  = "SingleConnectionString";
            var connectionStringValue = "ConnectionStringValue";
            var mockSettingLoader     = new SettingLoaderMock();

            mockSettingLoader.ConnectionStrings.Add(connectionStringName, connectionStringValue);

            var settings = new Settings();

            Assert.IsTrue(AppSettingsLoader.Load(mockSettingLoader, ref settings), "Load returned flase");
            Assert.AreEqual(connectionStringValue, settings.SingleConnectionString);
        }
Beispiel #19
0
        public void AppSetingsLoader_Load_LoadsConnectionStringsWhenPropertyIsDecoratedWithConnectionString()
        {
            var connectionStringName  = "Name";
            var connectionStringValue = "Value";
            var mockSettingLoader     = new SettingLoaderMock();

            mockSettingLoader.ConnectionStrings.Add(connectionStringName, connectionStringValue);

            var settings = new Settings();

            Assert.IsTrue(AppSettingsLoader.Load(mockSettingLoader, ref settings), "Load returned flase");
            Assert.IsTrue(settings.ConnectionStrings.ContainsKey(connectionStringName));
        }
Beispiel #20
0
        public void AppSetingsLoader_Load_LoadsConnectionStringsWhenPropertyIsDecoratedWithConnectionString()
        {
            var connectionStringName = "Name";
            var connectionStringValue = "Value";
            var mockSettingLoader = new SettingLoaderMock();

            mockSettingLoader.ConnectionStrings.Add(connectionStringName, connectionStringValue);

            var settings = new Settings();

            Assert.IsTrue(AppSettingsLoader.Load(mockSettingLoader, ref settings), "Load returned flase");
            Assert.IsTrue(settings.ConnectionStrings.ContainsKey(connectionStringName));
        }
Beispiel #21
0
        public void AppSettings_Load_CollectionHandlesSpaces()
        {
            string[] values             = new[] { "one", "two", "three" };
            var      mockSettingsLoader = new SettingLoaderMock();

            mockSettingsLoader.Settings.Add("Values", String.Join(", ", values));

            var settings = new ListVarieties();

            Assert.IsTrue(AppSettingsLoader.Load(mockSettingsLoader, ref settings), "Load returned false");

            CollectionAssert.AreEqual(values, settings.Values);
        }
Beispiel #22
0
        public void AppSettings_Load_NoDevSettingPresentLoadsAsNormal()
        {
            string settingName = "OptionalSetting";
            string prodSetting = "prod";

            var devLoader = new SettingLoaderMock();

            var prodLoader = new SettingLoaderMock();

            prodLoader.Settings.Add(settingName, prodSetting);

            var settings = new SettingsOptionalClass();

            AppSettingsLoader.DevSettings = devLoader;
            Assert.IsTrue(AppSettingsLoader.Load(prodLoader, ref settings), "Load returned false");

            Assert.AreEqual(prodSetting, settings.OptionalSetting);
        }
Beispiel #23
0
        public void AppSettings_Load_DevSettingOverrides()
        {
            string settingName = "OptionalSetting";
            string devSetting  = "dev";

            var devLoader = new SettingLoaderMock();

            devLoader.Settings.Add(settingName, devSetting);

            var prodLoader = new SettingLoaderMock();

            prodLoader.Settings.Add(settingName, "prod");

            var settings = new SettingsOptionalClass();

            AppSettingsLoader.DevSettings = devLoader;
            Assert.IsTrue(AppSettingsLoader.Load(prodLoader, ref settings), "Load returned false");

            Assert.AreEqual(devSetting, settings.OptionalSetting);
        }
Beispiel #24
0
        public void AppSettingsLoader_Load_ExceptionOnFailToParse()
        {
            var mockSettingsLoader = new SettingLoaderMock();
            mockSettingsLoader.Settings.Add("Is42", "fourty-two");

            var settings = new SettingsPrimitives();

            bool exceptionCaught = false;

            try
            {
                AppSettingsLoader.Load(mockSettingsLoader, ref settings);
            }
            catch (AggregateException aggEx)
            {
                exceptionCaught = true;
                Assert.AreEqual(1, aggEx.InnerExceptions.Count);
            }

            Assert.IsTrue(exceptionCaught, "An exception was not thrown");
        }
Beispiel #25
0
        public void AppSettingsLoader_Load_ExceptionOnFailToParse()
        {
            var mockSettingsLoader = new SettingLoaderMock();

            mockSettingsLoader.Settings.Add("Is42", "fourty-two");

            var settings = new Settings();

            bool exceptionCaught = false;

            try
            {
                AppSettingsLoader.Load(mockSettingsLoader, ref settings);
            }
            catch (AggregateException aggEx)
            {
                exceptionCaught = true;
                Assert.AreEqual(1, aggEx.InnerExceptions.Count);
            }

            Assert.IsTrue(exceptionCaught, "An exception was not thrown");
        }
Beispiel #26
0
        public void AppSettingsLoader_Load_LoadsString()
        {
            var mockSettingsLoader = new SettingLoaderMock();
            mockSettingsLoader.Settings.Add("IsFoobar", "Foobar");

            var settings = new SettingsPrimitives();

            Assert.IsTrue(AppSettingsLoader.Load(mockSettingsLoader, ref settings), "Load returned false");
            Assert.AreEqual("Foobar", settings.IsFoobar, "String setting not set");
        }
Beispiel #27
0
        public void AppSettingsLoader_Load_UsesKeyOverride()
        {
            var mockSettingsLoader = new SettingLoaderMock();
            mockSettingsLoader.Settings.Add("IsFooBar", "Foobar");

            var settings = new SettingsOverride();

            Assert.IsTrue(AppSettingsLoader.Load(mockSettingsLoader, ref settings), "Load returned false");
            Assert.AreEqual("Foobar", settings.IsFoo, "String setting not set");
        }
Beispiel #28
0
        public void AppSettingsLoader_Load_LoadsBool()
        {
            var mockSettingsLoader = new SettingLoaderMock();
            mockSettingsLoader.Settings.Add("IsTrue", "true");

            var settings = new SettingsPrimitives();

            Assert.IsTrue(AppSettingsLoader.Load(mockSettingsLoader, ref settings), "Load returned false");
            Assert.IsTrue(settings.IsTrue, "Boolean setting not set to true");
        }
Beispiel #29
0
        public void AppSettingsLoader_Load_LoadsEnumByValue()
        {
            var mockSettingsLoader = new SettingLoaderMock();
            Option option = Option.Option2;

            mockSettingsLoader.Settings.Add("IsOption2", ((int)option).ToString());

            var settings = new SettingsPrimitives();

            Assert.IsTrue(AppSettingsLoader.Load(mockSettingsLoader, ref settings), "Load returned false");
            Assert.AreEqual(option, settings.IsOption2, "Enum setting not set");
        }
Beispiel #30
0
        public void AppSettingsLoader_Load_NoExceptionIfHasOptionalSettingOnClass()
        {
            var mockSettingsLoader = new SettingLoaderMock();

            var settings = new SettingsOptionalClass();

            AppSettingsLoader.Load(mockSettingsLoader, ref settings);
        }
Beispiel #31
0
        public void AppSettingsLoader_Load_NoExceptionWhenClassOptional()
        {
            var mockSettingsLoader = new SettingLoaderMock();
            var settings = new SettingsOptionalConnectionString();

            // Should not throw an exception
            AppSettingsLoader.Load(mockSettingsLoader, ref settings);
            Assert.IsNull(settings.ConnectionString);
        }
Beispiel #32
0
        public void AppSettingsLoader_Load_LoadsInt()
        {
            var mockSettingsLoader = new SettingLoaderMock();
            mockSettingsLoader.Settings.Add("Is42", "42");

            var settings = new SettingsPrimitives();

            Assert.IsTrue(AppSettingsLoader.Load(mockSettingsLoader, ref settings), "Load returned false");
            Assert.AreEqual(42, settings.Is42, "Int setting not set");
        }
Beispiel #33
0
        public void AppSettingsLoader_Load_LoadsGuid()
        {
            var mockSettingsLoader = new SettingLoaderMock();
            Guid guid = Guid.NewGuid();

            mockSettingsLoader.Settings.Add("IsGuid", guid.ToString());

            var settings = new SettingsPrimitives();

            Assert.IsTrue(AppSettingsLoader.Load(mockSettingsLoader, ref settings), "Load returned false");
            Assert.AreEqual(guid, settings.IsGuid, "Guid setting not set");
        }
Beispiel #34
0
        public void AppSettings_Load_DevSettingOverrides()
        {
            string settingName = "OptionalSetting";
            string devSetting = "dev";

            var devLoader = new SettingLoaderMock();
            devLoader.Settings.Add(settingName, devSetting);

            var prodLoader = new SettingLoaderMock();
            prodLoader.Settings.Add(settingName, "prod");

            var settings = new SettingsOptionalClass();
            AppSettingsLoader.DevSettings = devLoader;
            Assert.IsTrue(AppSettingsLoader.Load(prodLoader, ref settings), "Load returned false");

            Assert.AreEqual(devSetting, settings.OptionalSetting);
        }
Beispiel #35
0
        public void AppSettingsLoader_Load_LoadsDateTime()
        {
            var mockSettingsLoader = new SettingLoaderMock();
            DateTime today = DateTime.Today;

            mockSettingsLoader.Settings.Add("IsToday", today.ToString());

            var settings = new SettingsPrimitives();

            Assert.IsTrue(AppSettingsLoader.Load(mockSettingsLoader, ref settings), "Load returned false");
            Assert.AreEqual(today, settings.IsToday, "DateTime setting not set");
        }
Beispiel #36
0
        public void AppSettings_Load_DevConnectionStringsOverrides()
        {
            string csName = "OptionalSetting";
            string expected = "dev";

            string csName2 = "cs2";
            string expected2 = "value2";

            var devLoader = new SettingLoaderMock();
            devLoader.ConnectionStrings.Add(csName, expected);

            var prodLoader = new SettingLoaderMock();
            prodLoader.ConnectionStrings.Add(csName, "prod");
            prodLoader.ConnectionStrings.Add(csName2, expected2);

            var settings = new SettingsConnectionStrings();
            AppSettingsLoader.DevSettings = devLoader;
            Assert.IsTrue(AppSettingsLoader.Load(prodLoader, ref settings), "Load returned false");

            Assert.AreEqual(2, settings.ConnectionStrings.Count);
            Assert.AreEqual(settings.ConnectionStrings[csName], expected);
            Assert.AreEqual(settings.ConnectionStrings[csName2], expected2);
        }
Beispiel #37
0
        public void AppSettingsLoader_Load_NoExceptionIfHasOptionalSetting()
        {
            var mockSettingsLoader = new SettingLoaderMock();
            // Set the required setting to avoid the exception, but don't set the optional setting
            mockSettingsLoader.Settings.Add("RequiredSetting", "Exists");

            var settings = new SettingsOptional();

            AppSettingsLoader.Load(mockSettingsLoader, ref settings);
        }
Beispiel #38
0
        public void AppSettings_Load_NoDevSettingPresentLoadsAsNormal()
        {
            string settingName = "OptionalSetting";
            string prodSetting = "prod";

            var devLoader = new SettingLoaderMock();

            var prodLoader = new SettingLoaderMock();
            prodLoader.Settings.Add(settingName, prodSetting);

            var settings = new SettingsOptionalClass();
            AppSettingsLoader.DevSettings = devLoader;
            Assert.IsTrue(AppSettingsLoader.Load(prodLoader, ref settings), "Load returned false");

            Assert.AreEqual(prodSetting, settings.OptionalSetting);
        }
Beispiel #39
0
        public void AppSettingsLoader_Load_LoadsUndecoratedPropertyWhenClassIsDecorated()
        {
            var mockSettingsLoader = new SettingLoaderMock();
            mockSettingsLoader.Settings.Add("Is42", "42");

            var settings = new SettingsUndecoratedProperties();

            Assert.IsTrue(AppSettingsLoader.Load(mockSettingsLoader, ref settings), "Load returned false");
            Assert.AreEqual(42, settings.Is42, "Int setting not set");
        }
Beispiel #40
0
        public void AppSettings_Load_CollectionSplitsSemiColons()
        {
            string[] values = new[] { "one", "two", "three" };
            var mockSettingsLoader = new SettingLoaderMock();
            mockSettingsLoader.Settings.Add("Values", String.Join(";", values));

            var settings = new ListVarieties();
            Assert.IsTrue(AppSettingsLoader.Load(mockSettingsLoader, ref settings), "Load returned false");

            CollectionAssert.AreEqual(values, settings.Values);
        }