示例#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"));
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#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));
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }