Beispiel #1
0
        public void Should_configure_Date_Time_property_given_a_valid_configuration_setting()
        {
            var configurer =
                new TestConfigurer<SimpleTestTarget>(new List<ConfigurationSetting>
                {
                    new ConfigurationSetting("SimpleTestTarget.DateTimeProperty", "1/11/1981")
                });

            var testTarget = new SimpleTestTarget();

            configurer.Configure(testTarget);

            Assert.AreEqual(testTarget.DateTimeProperty, DateTime.Parse("1/11/1981"));
        }
Beispiel #2
0
        public void Should_configure_double_property_given_a_valid_configuration_setting()
        {
            var configurer =
                new TestConfigurer<SimpleTestTarget>(new List<ConfigurationSetting>
                {
                    new ConfigurationSetting("SimpleTestTarget.DoubleProperty", "1.0")
                });

            var testTarget = new SimpleTestTarget();

            configurer.Configure(testTarget);

            Assert.AreEqual(testTarget.DoubleProperty, 1.0);
        }
Beispiel #3
0
        public void Should_configure_boolean_property_given_a_valid_configuration_setting()
        {
            var configurer =
                new TestConfigurer<SimpleTestTarget>(new List<ConfigurationSetting>
                {
                    new ConfigurationSetting("SimpleTestTarget.BooleanProperty", "true")
                });

            var testTarget = new SimpleTestTarget();

            configurer.Configure(testTarget);

            Assert.IsTrue(testTarget.BooleanProperty);
        }
Beispiel #4
0
        public void Should_configure_Guid_property_given_a_valid_configuration_setting()
        {
            var testGuid = Guid.NewGuid();
            var configurer =
                new TestConfigurer<SimpleTestTarget>(new List<ConfigurationSetting>
                {
                    new ConfigurationSetting("SimpleTestTarget.GuidProperty", testGuid.ToString())
                });

            var testTarget = new SimpleTestTarget();

            configurer.Configure(testTarget);

            Assert.AreEqual(testTarget.GuidProperty, testGuid);
        }
Beispiel #5
0
        public void Should_throw_ConfigurationErrorsException_if_long_property_configuration_setting_can_not_be_parsed()
        {
            const string propertyName = "LongProperty";
            const string settingName = "SimpleTestTarget.LongProperty";
            const string settingValue = "Invalid";

            var configurer =
                new TestConfigurer<SimpleTestTarget>(new List<ConfigurationSetting>
                {
                    new ConfigurationSetting(settingName, settingValue)
                });

            var testTarget = new SimpleTestTarget();

            Assert.Throws<ConfigurationErrorsException>(() => configurer.Configure(testTarget));
        }
Beispiel #6
0
        public void Should_set_nullable_long_property_to_null_given_invalid_configuration_setting()
        {
            var configurer =
                new TestConfigurer<SimpleTestTarget>(new List<ConfigurationSetting>
                {
                    new ConfigurationSetting("SimpleTestTarget.NullableLongProperty", "Invalid")
                });

            var testTarget = new SimpleTestTarget();

            configurer.Configure(testTarget);

            Assert.IsNull(testTarget.NullableLongProperty);
        }
Beispiel #7
0
        public void Should_follow_setting_naming_convention_when_configuring_property_on_named_instance()
        {
            const string targetName = "TestTarget";
            const string testString = "Test";

            var configurer =
                new TestConfigurer<SimpleTestTarget>(new List<ConfigurationSetting>
                {
                    new ConfigurationSetting(String.Format("{0}.SimpleTestTarget.StringProperty", targetName),
                                             testString)
                });

            var testTarget = new SimpleTestTarget();

            configurer.Configure(testTarget, targetName);

            Assert.AreEqual(testTarget.StringProperty, testString);
        }
Beispiel #8
0
        public void Should_configure_string_property_given_a_valid_configuration_setting()
        {
            const string testString = "Test";

            var configurer =
                new TestConfigurer<SimpleTestTarget>(new List<ConfigurationSetting>
                {
                    new ConfigurationSetting("SimpleTestTarget.StringProperty", testString)
                });

            var testTarget = new SimpleTestTarget();

            configurer.Configure(testTarget);

            Assert.AreEqual(testTarget.StringProperty, testString);
        }
Beispiel #9
0
        public void Should_configure_property_with_custom_setting_name_on_named_instance()
        {
            const string targetName = "Test";
            const string testString = "Test";
            const string settingName = "Test.CustomSettingNameProperty";

            var configurer =
                new TestConfigurer<SimpleTestTarget>(new List<ConfigurationSetting>
                {
                    new ConfigurationSetting(settingName, testString)
                });

            var testTarget = new SimpleTestTarget();

            configurer.Configure(testTarget, targetName);

            Assert.IsNotNull(testTarget.NamedTargetCustomSettingNameProperty);
            Assert.AreEqual(testTarget.NamedTargetCustomSettingNameProperty, testString);
        }
Beispiel #10
0
        public void Should_configure_nullable_long_property_given_a_valid_configuration_setting()
        {
            var configurer =
                new TestConfigurer<SimpleTestTarget>(new List<ConfigurationSetting>
                {
                    new ConfigurationSetting("SimpleTestTarget.NullableLongProperty", "1")
                });

            var testTarget = new SimpleTestTarget();

            configurer.Configure(testTarget);

            Assert.IsNotNull(testTarget.NullableLongProperty);
            Assert.AreEqual(testTarget.NullableLongProperty, 1);
        }