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()); }
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); }
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); }
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)); }
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()); }
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); }
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); }
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(); }
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); }
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); }
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); } }); }
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(); }
public void Add_Throws_For_Null_Toggles() { var configuration = new FeatureConfiguration(); Assert.Throws<ArgumentNullException>(() => configuration.Add(null)); }
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); }
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); } }); }
public void Add_Throws_For_Null_Toggles() { var configuration = new FeatureConfiguration(); Assert.Throws <ArgumentNullException>(() => configuration.Add(null)); }