public void BuilderTest_FeatureWithWritableStrategy_FeatureCanDisable()
        {
            var builder   = new FeatureSetBuilder();
            var container = builder.Build(ctx =>
            {
                ctx.AddFeature <MyWritableFeatureSingleStrategy>();
                ctx.ForStrategy <WritableStrategy>().Use <WritableStrategyImpl>();
            });

            FeatureContext.Disable <MyWritableFeatureSingleStrategy>();

            Assert.False(container.IsEnabled <MyWritableFeatureSingleStrategy>());
        }
        public ActionResult Update(string name, string state)
        {
            if (state == "on")
            {
                FeatureContext.Enable(name);
            }
            else
            {
                FeatureContext.Disable(name);
            }

            return(RedirectToAction("Index"));
        }
Esempio n. 3
0
        protected void chkEnabled_OnCheckedChanged(object sender, EventArgs e)
        {
            var checkBox    = (CheckBox)sender;
            var featureName = checkBox.InputAttributes["value"];

            if (checkBox.Checked)
            {
                FeatureContext.Enable(featureName);
            }
            else
            {
                FeatureContext.Disable(featureName);
            }
        }
        public void BuilderTest_MultipleFeaturesSameStrategy_NoCollisionsInState()
        {
            var builder   = new FeatureSetBuilder();
            var container = builder.Build(ctx =>
            {
                ctx.AddFeature <MyWritableFeatureSingleStrategy>();
                ctx.AddFeature <MyWritableAnotherFeatureSingleStrategy>();
                ctx.ForStrategy <WritableStrategy>().Use <WritableStrategyImpl>();
            });

            FeatureContext.Enable <MyWritableAnotherFeatureSingleStrategy>();

            Assert.False(FeatureContext.IsEnabled <MyWritableFeatureSingleStrategy>());
            Assert.True(FeatureContext.IsEnabled <MyWritableAnotherFeatureSingleStrategy>());

            FeatureContext.Enable <MyWritableFeatureSingleStrategy>();
            FeatureContext.Disable <MyWritableAnotherFeatureSingleStrategy>();

            Assert.True(FeatureContext.IsEnabled <MyWritableFeatureSingleStrategy>());
            Assert.False(FeatureContext.IsEnabled <MyWritableAnotherFeatureSingleStrategy>());
        }
        public IResourceResult Execute(IResourceContext context)
        {
            var p = context.Parameters;

            string featureName;

            if (!p.TryGetValue("featurename", out featureName))
            {
                throw new ArgumentException("Missing name of the feature");
            }

            string value;

            if (!p.TryGetValue("val", out value))
            {
                throw new ArgumentException("Missing new value for the feature");
            }

            if (string.IsNullOrEmpty(featureName) || string.IsNullOrEmpty(value))
            {
                return(GenerateResponse());
            }

            var newValue = Boolean.Parse(value);

            if (newValue)
            {
                FeatureContext.Enable(featureName);
            }
            else
            {
                FeatureContext.Disable(featureName);
            }

            return(GenerateResponse());
        }