コード例 #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();
        }
コード例 #2
0
        public void MissingComplexSettingThrowsException()
        {
            var options = ConfigurationOptions.Create();

            options.MissingConfigurationStratergy = MissingConfigurationStratergy.ThrowException;

            _configurationFactory = ConfigurationFactoryCreator.Create(options);

            Should.Throw <ConfigurationSettingMissingException>(() =>
            {
                _configurationFactory.CreateConfigurationSetting(typeof(SomeUnresolvedComplexSetting));
            });
        }
コード例 #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();
        }
コード例 #4
0
 public ComplexTypeSettingTests()
 {
     _configurationFactory = ConfigurationFactoryCreator.Create();
 }
コード例 #5
0
 public GenericTypeSettingTests()
 {
     _configurationFactory = ConfigurationFactoryCreator.Create();
 }