Esempio n. 1
0
        public void Should_throw_ConfigurationErrorsException_if_required_property_is_not_configured()
        {
            var configurer = new TestConfigurer <RequiredTestTarget>(new List <ConfigurationSetting>());
            var testTarget = new RequiredTestTarget();

            Assert.Throws <ConfigurationErrorsException>(() => configurer.Configure(testTarget));
        }
Esempio n. 2
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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 5
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);
        }
Esempio n. 6
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"));
        }
Esempio n. 7
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);
        }
Esempio n. 8
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"));
        }
Esempio n. 9
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);
        }
Esempio n. 10
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);
        }
Esempio n. 11
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);
        }
Esempio n. 12
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);
        }
Esempio n. 13
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));
        }
Esempio n. 14
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);
        }
Esempio n. 15
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);
        }
Esempio n. 16
0
        public void Configurer_Test()
        {
            var configurer = new TestConfigurer();
            ICalculator calculator = new CalculatorFactory(configurer).createInstance();

            double result = calculator.Compute("~3.3");
            Assert.AreEqual(3d, result);

            result = calculator.Compute("~3.3+2.8");
            Assert.AreEqual(5.8d, result);

            result = calculator.Compute("3.3+2.8~");
            Assert.AreEqual(4.1d, result);

            result = calculator.Compute("3.3+2.8~*2");
            Assert.AreEqual(4.9d, result, 0.00001);
        }
Esempio n. 17
0
        public void Should_throw_ConfigurationErrorsException_if_required_property_is_not_configured()
        {
            var configurer = new TestConfigurer<RequiredTestTarget>(new List<ConfigurationSetting>());
            var testTarget = new RequiredTestTarget();

            Assert.Throws<ConfigurationErrorsException>(() => configurer.Configure(testTarget));
        }
Esempio n. 18
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));
        }
Esempio n. 19
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);
        }
Esempio n. 20
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);
        }
Esempio n. 21
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);
        }
Esempio n. 22
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);
        }
Esempio n. 23
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);
        }