コード例 #1
0
        public void DoIt()
        {
            IFeatureConfiguration features = new FeatureConfiguration
                {
                    new BooleanToggle("Feature1", true),
                    new DateRangeToggle(
                        "Feature2",
                        true,
                        DateTime.Now.AddDays(-2),
                        DateTime.Now.AddDays(3)),
                    new EstablishedFeatureToggle("establishedFeature")
                };

            var mainFeature = new BooleanToggle("mainFeature", true);
            var subFeature1 = new BooleanToggle("subFeature1", true);
            var subFeature2 = new BooleanToggle("subFeature2", true);

            var dependency1 = new DependencyToggle(subFeature1, mainFeature);
            var dependency2 = new DependencyToggle(subFeature2, mainFeature);
            features.Add(dependency1);
            features.Add(dependency2);

            features.Add(new EstablishedFeatureToggle("establishedFeature"));

            Console.WriteLine(features.WhatDoIHave());
        }
コード例 #2
0
        public void DoIt()
        {
            IFeatureConfiguration features = new FeatureConfiguration
            {
                new BooleanToggle("Feature1", true),
                new DateRangeToggle(
                    "Feature2",
                    true,
                    DateTime.Now.AddDays(-2),
                    DateTime.Now.AddDays(3)),
                new EstablishedFeatureToggle("establishedFeature")
            };

            var mainFeature = new BooleanToggle("mainFeature", true);
            var subFeature1 = new BooleanToggle("subFeature1", true);
            var subFeature2 = new BooleanToggle("subFeature2", true);

            var dependency1 = new DependencyToggle(subFeature1, mainFeature);
            var dependency2 = new DependencyToggle(subFeature2, mainFeature);

            features.Add(dependency1);
            features.Add(dependency2);

            features.Add(new EstablishedFeatureToggle("establishedFeature"));

            Console.WriteLine(features.WhatDoIHave());
        }
コード例 #3
0
        public void Count_Represents_Number_Of_Configured_Items()
        {
            var configuration = new FeatureConfiguration();

            Assert.AreEqual(0, configuration.Count);

            configuration.Add(new BooleanToggle("f1", true));
            Assert.AreEqual(1, configuration.Count);

            configuration.Add(new BooleanToggle("f2", true));
            Assert.AreEqual(2, configuration.Count);
        }
コード例 #4
0
        public void Add_Replaces_Feature_With_Name()
        {
            var configuration = new FeatureConfiguration();

            var original = new BooleanToggle(TestFeatureName, false);
            var expected = new BooleanToggle(TestFeatureName, true);

            configuration.Add(original);
            configuration.Add(expected);

            var actual = configuration.Get(TestFeatureName);

            Assert.AreSame(expected, actual);
        }
コード例 #5
0
        public void Add_Replaces_Feature_With_Name()
        {
            var configuration = new FeatureConfiguration();

            var original = new BooleanToggle(TestFeatureName, false);
            var expected = new BooleanToggle(TestFeatureName, true);

            configuration.Add(original);
            configuration.Add(expected);

            var actual = configuration.Get(TestFeatureName);

            Assert.AreSame(expected, actual);
        }
コード例 #6
0
        public void Can_Enumerate_Over_Feature_Toggles()
        {
            var configuration = new FeatureConfiguration();

            var f1 = new BooleanToggle("f1", true);

            configuration.Add(f1);

            var f2 = new BooleanToggle("f2", true);

            configuration.Add(f2);

            Assert.IsTrue(configuration.Any(x => x == f1));
            Assert.IsTrue(configuration.Any(x => x == f2));
        }
コード例 #7
0
        public void Can_Enumerate_Over_Feature_Toggles_Via_Base_IEnumerable_Interface()
        {
            var configuration = new FeatureConfiguration();

            var f1 = new BooleanToggle("f1", true);

            configuration.Add(f1);

            var f2 = new BooleanToggle("f2", true);

            configuration.Add(f2);

            IEnumerable baseConfiguration = configuration;
            var         enumerator        = baseConfiguration.GetEnumerator();

            Assert.IsTrue(enumerator.MoveNext());
        }
コード例 #8
0
        public void Add_Adds_Feature_By_Name()
        {
            var configuration = new FeatureConfiguration();
            var expected      = new BooleanToggle(TestFeatureName, true);

            configuration.Add(expected);

            var actual = configuration.Get(TestFeatureName);

            Assert.AreSame(expected, actual);
        }
コード例 #9
0
        public void Add_Adds_Feature_By_Name()
        {
            var configuration = new FeatureConfiguration();
            var expected = new BooleanToggle(TestFeatureName, true);

            configuration.Add(expected);

            var actual = configuration.Get(TestFeatureName);

            Assert.AreSame(expected, actual);
        }
コード例 #10
0
        public void WhatDoIHave_Returns_Diagnostic_String_On_Feature_Toggle_Instances()
        {
            var configuration = new FeatureConfiguration();

            var f1 = new BooleanToggle("f1", true);

            configuration.Add(f1);

            var f2 = new BooleanToggle("f2", false);

            configuration.Add(f2);

            string diagnostics = configuration.WhatDoIHave();

            StringAssert.Contains("f1", diagnostics);
            StringAssert.Contains(bool.TrueString, diagnostics);

            StringAssert.Contains("f2", diagnostics);
            StringAssert.Contains(bool.FalseString, diagnostics);
        }
コード例 #11
0
        public void Add_Verifies_And_Freezes_Toggle()
        {
            var configuration = new FeatureConfiguration();
            var toggle        = new Mock <IFeatureToggle>();

            toggle.Setup(x => x.AssertConfigurationIsValid());
            toggle.Setup(x => x.Freeze());
            toggle.Setup(x => x.Name).Returns("name");

            configuration.Add(toggle.Object);
            toggle.VerifyAll();
        }
コード例 #12
0
        public void IsEnabled_Returns_False_For_Enabled_Features()
        {
            var configuration = new FeatureConfiguration();

            const bool expected = false;

            var feature = new BooleanToggle(TestFeatureName, expected);

            configuration.Add(feature);

            var actual = configuration.IsEnabled(TestFeatureName);

            Assert.AreEqual(expected, actual);
        }
コード例 #13
0
        public void Clear_Clears_Features_From_Configuration()
        {
            var configuration = new FeatureConfiguration();

            const bool expected = false;

            var feature = new BooleanToggle(TestFeatureName, expected);

            configuration.Add(feature);

            configuration.Clear();

            Assert.IsNull(configuration.Get(TestFeatureName));
            Assert.AreEqual(0, configuration.Count);
        }
コード例 #14
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);
                }
            });
        }
コード例 #15
0
        public void Add_Verifies_And_Freezes_Toggle()
        {
            var configuration = new FeatureConfiguration();
            var toggle = new Mock<IFeatureToggle>();
            toggle.Setup(x => x.AssertConfigurationIsValid());
            toggle.Setup(x => x.Freeze());
            toggle.Setup(x => x.Name).Returns("name");

            configuration.Add(toggle.Object);
            toggle.VerifyAll();
        }
コード例 #16
0
 public void Add_Throws_For_Null_Toggles()
 {
     var configuration = new FeatureConfiguration();
     Assert.Throws<ArgumentNullException>(() => configuration.Add(null));
 }
コード例 #17
0
        public void WhatDoIHave_Returns_Diagnostic_String_On_Feature_Toggle_Instances()
        {
            var configuration = new FeatureConfiguration();

            var f1 = new BooleanToggle("f1", true);
            configuration.Add(f1);

            var f2 = new BooleanToggle("f2", false);
            configuration.Add(f2);

            string diagnostics = configuration.WhatDoIHave();

            StringAssert.Contains("f1", diagnostics);
            StringAssert.Contains(bool.TrueString, diagnostics);

            StringAssert.Contains("f2", diagnostics);
            StringAssert.Contains(bool.FalseString, diagnostics);
        }
コード例 #18
0
        public void IsEnabled_Returns_True_For_Enabled_Features()
        {
            var configuration = new FeatureConfiguration();

            const bool expected = true;

            var feature = new BooleanToggle(TestFeatureName, expected);
            configuration.Add(feature);

            var actual = configuration.IsEnabled(TestFeatureName);

            Assert.AreEqual(expected, actual);
        }
コード例 #19
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);
                    }
                });
        }
コード例 #20
0
        public void Count_Represents_Number_Of_Configured_Items()
        {
            var configuration = new FeatureConfiguration();
            Assert.AreEqual(0, configuration.Count);

            configuration.Add(new BooleanToggle("f1", true));
            Assert.AreEqual(1, configuration.Count);

            configuration.Add(new BooleanToggle("f2", true));
            Assert.AreEqual(2, configuration.Count);
        }
コード例 #21
0
        public void Clear_Clears_Features_From_Configuration()
        {
            var configuration = new FeatureConfiguration();

            const bool expected = false;

            var feature = new BooleanToggle(TestFeatureName, expected);
            configuration.Add(feature);

            configuration.Clear();

            Assert.IsNull(configuration.Get(TestFeatureName));
            Assert.AreEqual(0, configuration.Count);
        }
コード例 #22
0
        public void Can_Enumerate_Over_Feature_Toggles_Via_Base_IEnumerable_Interface()
        {
            var configuration = new FeatureConfiguration();

            var f1 = new BooleanToggle("f1", true);
            configuration.Add(f1);

            var f2 = new BooleanToggle("f2", true);
            configuration.Add(f2);

            IEnumerable baseConfiguration = configuration;
            var enumerator = baseConfiguration.GetEnumerator();

            Assert.IsTrue(enumerator.MoveNext());
        }
コード例 #23
0
        public void Can_Enumerate_Over_Feature_Toggles()
        {
            var configuration = new FeatureConfiguration();

            var f1 = new BooleanToggle("f1", true);
            configuration.Add(f1);

            var f2 = new BooleanToggle("f2", true);
            configuration.Add(f2);

            Assert.IsTrue(configuration.Any(x => x == f1));
            Assert.IsTrue(configuration.Any(x => x == f2));
        }
コード例 #24
0
        public void Add_Throws_For_Null_Toggles()
        {
            var configuration = new FeatureConfiguration();

            Assert.Throws <ArgumentNullException>(() => configuration.Add(null));
        }