public void Parse_returns_expected(string text, string expectedId, bool expectedState)
        {
            var sut = FeatureToggleValue.Parse(text);

            Assert.AreEqual(expectedId, sut.Id);
            Assert.AreEqual(expectedState, sut.IsEnabled);
        }
        public void IsEnabled_is_expected(bool expectedState)
        {
            const string dummyId = "dummy id";
            var          sut     = new FeatureToggleValue(dummyId, expectedState);

            Assert.AreEqual(expectedState, sut.IsEnabled);
        }
Example #3
0
        public FeatureToggleValue AddOrEditFeatureToggleValue(Guid featureToggleId, bool isEnabled)
        {
            var featureToggleValue = FeatureToggleValues.FirstOrDefault(x => x.FeatureToggleId == featureToggleId);

            if (featureToggleValue == null)
            {
                featureToggleValue = FeatureToggleValue.NewValue(isEnabled, Id, featureToggleId);
                FeatureToggleValues.Add(featureToggleValue);
            }
            else
            {
                if (isEnabled)
                {
                    featureToggleValue.Enable();
                }
                else
                {
                    featureToggleValue.Disable();
                }
            }

            LastUpdateAt = DateTime.UtcNow;

            return(featureToggleValue);
        }
Example #4
0
        public FeatureToggleValue AddOrEditFeatureToggleValue(string key, string description, bool isEnabled)
        {
            var application = Application;
            var toggle      = application.FeatureToggles.FirstOrDefault(x => x.Key == key);

            if (toggle == null)
            {
                toggle = application.AddNewFeatureToggle(key, description);
            }

            var featureValue = FeatureToggleValues.FirstOrDefault(x => x.FeatureToggleId == toggle.Id);

            if (featureValue == null)
            {
                featureValue = FeatureToggleValue.NewValue(isEnabled, Id, toggle.Id);
                FeatureToggleValues.Add(featureValue);
            }
            else
            {
                if (isEnabled)
                {
                    featureValue.Enable();
                }
                else
                {
                    featureValue.Disable();
                }
            }
            LastUpdateAt = DateTime.UtcNow;

            return(featureValue);
        }
        public void Has_Id_ignores_the_words_FeatureToggle_in_the_id(string id, string otherId)
        {
            const bool dummyState = true;

            var sut    = new FeatureToggleValue(id, dummyState);
            var result = sut.HasId(otherId);

            Assert.IsTrue(result);
        }
        public void Id_is_expected()
        {
            string     id = Guid.NewGuid().ToString();
            const bool dummyEnabledState = true;

            var sut = new FeatureToggleValue(id, dummyEnabledState);

            Assert.AreEqual(id, sut.Id);
        }
        public void HasId_ignores_case()
        {
            const string id         = "TestFeatureToggle";
            const bool   dummyState = true;

            var sut    = new FeatureToggleValue(id, dummyState);
            var result = sut.HasId("TESTFEATURETOGGLE");

            Assert.IsTrue(result);
        }
        public void HasId_returns_true_if_direct_match()
        {
            const string id         = "TestFeatureToggle";
            const bool   dummyState = true;

            var sut    = new FeatureToggleValue(id, dummyState);
            var result = sut.HasId(id);

            Assert.IsTrue(result);
        }
Example #9
0
        public FeatureToggleValueProviderBuilder WithFeatureToggle(string id, bool isEnabled)
        {
            var toggleValue = new FeatureToggleValue(id, isEnabled);

            if (_toggles.ContainsKey(id))
            {
                _toggles[id] = toggleValue;
            }
            else
            {
                _toggles.Add(id, toggleValue);
            }

            return(this);
        }
Example #10
0
        private async Task <IDictionary <string, bool> > GetFeaturesValues(Guid environmentId, Guid applicationId)
        {
            var result   = new Dictionary <string, bool>();
            var features = unitOfWork.Repository <FeatureToggle, Guid>();
            var values   = unitOfWork.Repository <FeatureToggleValue, Guid>();

            var appFeatures = await features.GetAsync(FeatureToggle.WithApplication(applicationId));

            appFeatures.ToList().ForEach(x => result.Add(x.Key, false));

            var appValues = await values.GetAsync(FeatureToggleValue.WithEnvironment(environmentId), "FeatureToggle");

            appValues.ToList().ForEach(x => result[x.FeatureToggle.Key] = x.IsEnabled);

            return(result);
        }
 public void Parse_throws_exception_if_text_is_illegal(string illegalText)
 {
     Assert.Throws <ArgumentException>(() => FeatureToggleValue.Parse(illegalText));
 }
 public void Parse_throws_exception_if_text_is_in_wrong_format(string text)
 {
     Assert.Throws <FormatException>(() => FeatureToggleValue.Parse(text));
 }
Example #13
0
        public async Task ImportToggles(Guid environmentId, string format, MemoryStream stream)
        {
            var userId = authService.CurrentUserId();

            Guard.IsTrue(await hasEnvironmentPermission.ToRead(userId, environmentId), "Invalid permissions for read this environment");

            var environments = unitOfWork.Repository <ApplicationEnvironment, Guid>();
            var environment  = await environments.GetById(environmentId, "Application.FeatureToggles,FeatureToggleValues");

            var values = importer.Parse(stream, format);

            foreach (var entry in values)
            {
                environment.AddOrEditFeatureToggleValue(entry.Key, description: null, FeatureToggleValue.Parse(entry.Value).IsEnabled);
            }
            await unitOfWork.SaveAsync();
        }