public void ToggleEqualityTest() { Mock <IToggleDataProvider> dataProvider = new Mock <IToggleDataProvider>(MockBehavior.Strict); dataProvider.Setup(x => x.GetFlag("enabledFeature")) .Returns(new Toggle("enabledFeature", true)); dataProvider.Setup(x => x.GetFlag("disabledFeature")) .Returns(new Toggle("disabledFeature", false)); ToggleFactory factory = new ToggleFactory(GetEnabledConfiguration(), dataProvider.Object); Toggle t1 = factory.Get("enabledFeature"); Toggle t2 = factory.Get("disabledFeature"); Assert.IsFalse(t1 == t2); }
public void LoadToggleFromConfigTest() { ToggleFactory factory = new ToggleFactory(GetEnabledConfiguration(), new AppConfigDataProvider()); Toggle t1 = factory.Get("CacheInheritableDatasource"); Assert.IsTrue(t1 != Toggle.Empty); }
public void GetInvalidUserFlagTest() { ToggleFactory factory = new ToggleFactory(GetEnabledConfiguration(), new AppConfigDataProvider()); ToggleData data = new ToggleData("wibble", string.Empty); Toggle t1 = factory.Get("CacheInheritableDatasource", data); Assert.IsFalse(t1.IsEnabled); }
public void GetInvalidToggleDataBasedFlagTest() { ToggleFactory factory = new ToggleFactory(GetEnabledConfiguration(), new AppConfigDataProvider()); ToggleData data = new ToggleData("abcd", "128.0.0.2", "Staff"); Toggle t1 = factory.Get("CacheInheritableDatasource", data); Assert.IsFalse(t1.IsEnabled); }
public void GetValidRoleFlagTest() { ToggleFactory factory = new ToggleFactory(GetEnabledConfiguration(), new AppConfigDataProvider()); ToggleData data = new ToggleData("abcd", string.Empty, "Staff"); Toggle t1 = factory.Get("CacheInheritableDatasource", data); Assert.IsTrue(t1.IsEnabled); }
public void FromConfigTest() { ToggleFactory factory = new ToggleFactory(new AppConfigurationProvider(), new AppConfigDataProvider()); Toggle toggle = factory.Get <StrongToggleId>(); Assert.IsFalse(toggle == Toggle.Empty); Assert.IsFalse(Toggle.IsNullOrEmpty(toggle)); Assert.AreEqual("StrongToggleId", toggle.Name); Assert.IsTrue(toggle.IsEnabled); }
public void TestStrongToggleEnabled() { Mock <IToggleDataProvider> dataProvider = new Mock <IToggleDataProvider>(MockBehavior.Strict); dataProvider.Setup(x => x.GetFlag("StrongToggle")) .Returns(new Toggle("StrongToggle", true)); ToggleFactory factory = new ToggleFactory(GetEnabledConfiguration(), dataProvider.Object); Toggle t = factory.Get("StrongToggle"); Assert.IsFalse(t == Toggle.Empty); Assert.IsFalse(Toggle.IsNullOrEmpty(t)); Assert.AreEqual("StrongToggle", t.Name); Assert.IsTrue(t.IsEnabled); }
public void GetDefaultValueTest() { Mock <IToggleConfiguration> config = new Mock <IToggleConfiguration>(MockBehavior.Strict); config.SetupGet(x => x.SystemEnabled) .Returns(false); config.SetupGet(x => x.DefaultValue) .Returns(true); Mock <IToggleDataProvider> dataProvider = new Mock <IToggleDataProvider>(MockBehavior.Strict); dataProvider.Setup(x => x.GetFlag(It.IsAny <string>())) .Returns(new Toggle("test", false)); ToggleFactory factory = new ToggleFactory(config.Object, dataProvider.Object); Toggle t = factory.Get("test"); Assert.IsTrue(t.IsEnabled, "Toggle should return the default value of true"); }
public void GetMissingToggleTest() { Mock <IToggleConfiguration> config = new Mock <IToggleConfiguration>(MockBehavior.Strict); config.SetupGet(x => x.SystemEnabled) .Returns(true); config.SetupGet(x => x.DefaultValue) .Returns(false); Mock <IToggleDataProvider> dataProvider = new Mock <IToggleDataProvider>(MockBehavior.Strict); dataProvider.Setup(x => x.GetFlag(It.IsAny <string>())) .Returns((Toggle)null); ToggleFactory factory = new ToggleFactory(config.Object, dataProvider.Object); Toggle t = factory.Get("test"); Assert.IsNotNull(t, "Toggle should never be null"); Assert.IsTrue(Toggle.IsNullOrEmpty(t)); Assert.IsFalse(t.IsEnabled, "Toggle should return the configured value of true"); }