Example #1
0
        public void CanResolveUsingCustomConstructors()
        {
            var count = 0;

            var options = ConfigurationOptions.Create();

            options.WithConstructor((type, constructor) =>
            {
                type.ShouldBe(typeof(SomeDecimalSetting));
                constructor.ShouldNotBeNull();
                count.ShouldBe(0);
                count++;
                return(constructor);
            });

            // Chaining multiple functions
            options.WithConstructor((type, constructor) =>
            {
                type.ShouldBe(typeof(SomeDecimalSetting));
                constructor.ShouldNotBeNull();
                count.ShouldBe(1);
                return(constructor);
            });

            var configurationFactory = ConfigurationFactoryCreator.Create(options);

            SomeDecimalSetting config = configurationFactory.CreateConfigurationSetting(typeof(SomeDecimalSetting));

            config.Value.ShouldBeOfType <decimal>();
            config.Value.Equals(decimal.Parse("1.2345")).ShouldBeTrue();
        }
        public void MissingComplexSettingThrowsException()
        {
            var options = ConfigurationOptions.Create();

            options.MissingConfigurationStratergy = MissingConfigurationStratergy.ThrowException;

            _configurationFactory = ConfigurationFactoryCreator.Create(options);

            Should.Throw <ConfigurationSettingMissingException>(() =>
            {
                _configurationFactory.CreateConfigurationSetting(typeof(SomeUnresolvedComplexSetting));
            });
        }
Example #3
0
        public void CanResolveSettingWithCustomName()
        {
            var options = ConfigurationOptions.Create();

            options.WithNamingScheme((type, name) =>
            {
                if (type == typeof(SomeDecimalSetting))
                {
                    return(new KeyName("SomeSection:", name.QualifiedKeyName));
                }

                return(name);
            });

            var configurationFactory = ConfigurationFactoryCreator.Create(options);

            SomeDecimalSetting config = configurationFactory.CreateConfigurationSetting(typeof(SomeDecimalSetting));

            config.Value.ShouldBeOfType <decimal>();
            config.Value.Equals(decimal.Parse("0.12345")).ShouldBeTrue();
        }
 public ComplexTypeSettingTests()
 {
     _configurationFactory = ConfigurationFactoryCreator.Create();
 }
 public GenericTypeSettingTests()
 {
     _configurationFactory = ConfigurationFactoryCreator.Create();
 }