A concrete implementation of a IConfigurationReader that reads from the application configuration.
Inheritance: IConfigurationReader
コード例 #1
0
        public void Read_Returns_DateRange_Toggles_If_Dates_Have_Been_Specified()
        {
            var reader = new ApplicationConfigurationReader();
            List<IFeatureToggle> features = reader.GetFeatures().ToList();

            var feature = features.Single(x => x.Name == "testDateRange") as DateRangeToggle;

            Assert.IsNotNull(feature);

            Assert.IsNotNull(feature.EnabledFromDate);
            Assert.AreEqual(2012, feature.EnabledFromDate.Value.Year);
            Assert.AreEqual(11, feature.EnabledFromDate.Value.Month);
            Assert.AreEqual(1, feature.EnabledFromDate.Value.Day);

            Assert.IsNotNull(feature.EnabledToDate);
            Assert.AreEqual(2012, feature.EnabledToDate.Value.Year);
            Assert.AreEqual(11, feature.EnabledToDate.Value.Month);
            Assert.AreEqual(2, feature.EnabledToDate.Value.Day);
        }
コード例 #2
0
        public void Read_Allows_For_Whitespace_In_Dependency_Configuration()
        {
            var reader = new ApplicationConfigurationReader(() => new DummyToggleConfig
                {
                    Toggles = new FeatureToggleCollection
                        {
                            new ToggleConfig
                                {
                                    Name = "a",
                                    Dependencies = "b, c"
                                },
                            new ToggleConfig
                                {
                                    Name = "b"
                                },
                            new ToggleConfig
                                {
                                    Name = "c"
                                },
                        }
                });

            Assert.AreEqual(3, reader.GetFeatures().Count());
        }
コード例 #3
0
        public void Read_Throws_CircularDependecy_Exception_For_Circular_Dependencies()
        {
            var reader = new ApplicationConfigurationReader(() => new DummyToggleConfig
                {
                    Toggles = new FeatureToggleCollection
                        {
                            new ToggleConfig
                                {
                                    Name = "a",
                                    Dependencies = "b,d"
                                },
                            new ToggleConfig
                                {
                                    Name = "b"
                                },
                            new ToggleConfig
                                {
                                    Name = "c"
                                },
                            new ToggleConfig
                                {
                                    Name = "d",
                                    Dependencies = "b, a"
                                },
                        }
                });

            var configuration = new FeatureConfiguration();
            var features = reader.GetFeatures().ToList();

            Assert.Throws<CircularDependencyException>(() =>
                {
                    foreach (var feature in features)
                    {
                        configuration.Add(feature);
                    }
                });
        }
コード例 #4
0
        public void Read_Throws_Configuration_Exception_For_Unknown_Tasks_In_Dependencies()
        {
            var reader = new ApplicationConfigurationReader(() => new DummyToggleConfig
                {
                    Toggles = new FeatureToggleCollection
                        {
                            new ToggleConfig
                                {
                                    Name = "a",
                                    Dependencies = "b,d"
                                },
                            new ToggleConfig
                                {
                                    Name = "b"
                                },
                            new ToggleConfig
                                {
                                    Name = "c"
                                },
                        }
                });

            // ReSharper disable ReturnValueOfPureMethodIsNotUsed
            Assert.Throws<ConfigurationErrorsException>(() => reader.GetFeatures().ToList());
            // ReSharper restore ReturnValueOfPureMethodIsNotUsed
        }
コード例 #5
0
        public void Read_Sets_Dependency_Toggle_Dependencies_To_The_Wrapped_DependencyToggle()
        {
            var reader = new ApplicationConfigurationReader(() => new DummyToggleConfig
                {
                    Toggles = new FeatureToggleCollection
                        {
                            new ToggleConfig
                                {
                                    Name = "a",
                                    Dependencies = "b"
                                },
                            new ToggleConfig
                                {
                                    Name = "b",
                                    Dependencies = "c"
                                },
                            new ToggleConfig
                                {
                                    Name = "c"
                                },
                        }
                });

            var features = reader.GetFeatures().ToList();

            Assert.IsInstanceOf<DependencyToggle>(features.OfType<DependencyToggle>().Single(x => x.Name == "a").Dependencies.Single());
        }
コード例 #6
0
        public void Read_Returns_Simple_Boolean_Toggles()
        {
            var reader = new ApplicationConfigurationReader();
            List<IFeatureToggle> features = reader.GetFeatures().ToList();

            var feature1 = features.Single(x => x.Name == "testSimpleEnabled");
            var feature2 = features.Single(x => x.Name == "testSimpleDisabled");

            Assert.IsTrue(feature1.IsEnabled());
            Assert.IsFalse(feature2.IsEnabled());
        }
コード例 #7
0
        public void Read_Returns_No_Elements_If_Configuration_Section_Not_Found()
        {
            var reader = new ApplicationConfigurationReader(() => null);
            var features = reader.GetFeatures();

            Assert.IsNotNull(features);
            CollectionAssert.IsEmpty(features);
        }
コード例 #8
0
        public void Read_Returns_Established_Toggle_If_Feature_Is_Established()
        {
            var reader = new ApplicationConfigurationReader();
            List<IFeatureToggle> features = reader.GetFeatures().ToList();

            var feature = features.Single(x => x.Name == "testEstablished") as EstablishedFeatureToggle;

            Assert.IsNotNull(feature);
        }
コード例 #9
0
        public void Read_Returns_Dependency_Toggles()
        {
            var reader = new ApplicationConfigurationReader();

            List<IFeatureToggle> features = reader.GetFeatures().ToList();
            var feature = features.Single(x => x.Name == "testDependencies") as DependencyToggle;

            Assert.IsNotNull(feature);

            IEnumerable<IFeatureToggle> dependencies = feature.Dependencies.ToList();

            Assert.AreEqual(2, dependencies.Count());
            Assert.IsTrue(dependencies.Any(x => x.Name == "testSimpleEnabled"));
            Assert.IsTrue(dependencies.Any(x => x.Name == "testSimpleDisabled"));
        }