コード例 #1
0
        public void Should_configure_long_property_given_a_valid_configuration_setting()
        {
            var configurer = new TestConfigurer <SimpleTestTarget>(new List <ConfigurationSetting>
            {
                new ConfigurationSetting("SimpleTestTarget.LongProperty", "1")
            });

            var testTarget = new SimpleTestTarget();

            configurer.Configure(testTarget);

            Assert.AreEqual(testTarget.LongProperty, 1);
        }
コード例 #2
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);
        }
コード例 #3
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"));
        }
コード例 #4
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);
        }
コード例 #5
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);
        }
コード例 #6
0
        public void Should_configure_nullable_double_property_given_a_valid_configuration_setting()
        {
            var configurer =
                new TestConfigurer <SimpleTestTarget>(new List <ConfigurationSetting>
            {
                new ConfigurationSetting("SimpleTestTarget.NullableDoubleProperty", "1.0")
            });

            var testTarget = new SimpleTestTarget();

            configurer.Configure(testTarget);

            Assert.IsNotNull(testTarget.NullableDoubleProperty);
            Assert.AreEqual(testTarget.NullableDoubleProperty, 1.0);
        }
コード例 #7
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));
        }
コード例 #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_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);
        }
コード例 #10
0
        public void Should_configure_property_with_custom_setting_name()
        {
            const string testString  = "Test";
            const string settingName = "CustomSettingNameProperty";

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

            var testTarget = new SimpleTestTarget();

            configurer.Configure(testTarget);

            Assert.IsNotNull(testTarget.CustomSettingNameProperty);
            Assert.AreEqual(testTarget.CustomSettingNameProperty, testString);
        }