コード例 #1
0
        public void CheckIfActive_NotActive()
        {
            var toggler = new FeatureToggle();
            var feature = toggler.For("Feature1");

            Assert.That(feature.IsActive, Is.False);
        }
コード例 #2
0
    // This runs once for every property in our shader.
    private void ShaderPropertyImpl(Shader shader, int propertyIndex, FeatureToggle currentToggle)
    {
        string propertyDescription = ShaderUtil.GetPropertyDescription(shader, propertyIndex);

        // If current toggle is null, we only want to show properties that aren't already "owned" by a toggle,
        // so if it is owned by another toggle, then return.
        if (currentToggle == null)
        {
            for (int i = 0; i < Toggles.Count; i++)
            {
                if (!Toggles[i].SecondaryToggle && Regex.IsMatch(propertyDescription, Toggles[i].InspectorPropertyHideTag, RegexOptions.IgnoreCase))
                {
                    return;
                }
            }
        }
        // Only draw if we the current property is owned by the current toggle.
        else if (!Regex.IsMatch(propertyDescription, currentToggle.InspectorPropertyHideTag, RegexOptions.IgnoreCase))
        {
            return;
        }

        // And don't draw if it's owned by a secondary toggle
        for (int i = 0; i < Toggles.Count; i++)
        {
            if (Toggles[i].SecondaryToggle && !Toggles[i].Enabled && Regex.IsMatch(propertyDescription, Toggles[i].InspectorPropertyHideTag, RegexOptions.IgnoreCase))
            {
                return;
            }
        }
        // If we've gotten to this point, draw the shader property regulairly.
        ShaderProperty(shader, propertyIndex);
    }
コード例 #3
0
        public void SaveFeatureToggle(FeatureToggle serializedFeatureToggle)
        {
            var jsonContent = Serializer.Serialize(serializedFeatureToggle);
            var filePath    = GetFilePath(serializedFeatureToggle.FeatureName);

            File.WriteAllText(filePath, jsonContent);
        }
コード例 #4
0
 public FillFileHistory(ISessionAdapter sessionAdapter, IRepository api, ReviewRevision currentRevision, FeatureToggle features)
 {
     _sessionAdapter  = sessionAdapter;
     _api             = api;
     _currentRevision = currentRevision;
     _features        = features;
 }
コード例 #5
0
        public void ShouldReturnVariant2()
        {
            // Arrange
            var v1 = new VariantDefinition("a", 33, new Payload("string", "asd"), new Collection <VariantOverride>());
            var v2 = new VariantDefinition("b", 33);
            var v3 = new VariantDefinition("c", 34);

            var toggle = new FeatureToggle(
                "test.variants",
                "release",
                true,
                new List <ActivationStrategy> {
                defaultStrategy
            },
                new List <VariantDefinition> {
                v1, v2, v3
            });

            var context = new UnleashContext
            {
                UserId        = "163",
                SessionId     = "sessionId",
                RemoteAddress = "remoteAddress",
                Properties    = new Dictionary <string, string>()
            };

            // Act
            var variant = VariantUtils.SelectVariant(toggle, context, Variant.DISABLED_VARIANT);

            // Assert
            variant.Name.Should().Be(v2.Name);
        }
コード例 #6
0
        public void TestToggleParsedOutOfRangeExceptionIsReturnedWhenParsingAnItemThatIsToggledAsdf()
        {
            var configParser = new ToggleParser();
            IFeatureToggle <bool> featureToggle = new FeatureToggle <bool>();

            Assert.Throws <ToggleParsedOutOfRangeException>(() => featureToggle.GetToggleState(configParser, "asdf"));
        }
        public void Serialize()
        {
            // Assign
            var serializer = new JsonFeatureToggleSerializer();
            var condition  = Allow.Simple()
                             .Or(Allow.FromDateTime(new DateTime(2019, 05, 16, 15, 0, 0, DateTimeKind.Utc))
                                 .And(Allow.UntilDateTime(new DateTime(2019, 05, 17, 15, 0, 0, DateTimeKind.Utc)))
                                 .And(Restrict.DayOfWeek(DayOfWeek.Wednesday))
                                 .And(Restrict.Installation("SAMPLE_INSTALLATION#2"))
                                 .And(Restrict.User("USER#2"))
                                 .And(Allow.DaysOfWeek(DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Thursday, DayOfWeek.Friday, DayOfWeek.Saturday, DayOfWeek.Sunday))
                                 .And(Allow.Installation("SAMPLE_INSTALLATION#1"))
                                 .And(Allow.User("USER#1"))
                                 .And(Restrict.Simple())
                                 .And(Allow.FromTimeOfDay(new TimeSpan(15, 0, 0)))
                                 .And(Allow.UntilTimeOfDay(new TimeSpan(16, 0, 0)))
                                 );
            var featureToggle = new FeatureToggle();

            featureToggle.FeatureName = "MyFeature";
            featureToggle.Condition   = condition;

            // Act
            var serialized = serializer.Serialize(featureToggle);

            // Assert
            // Assert correctly. Don't read the expected from the static variable but from a static file
        }
コード例 #8
0
ファイル: Juicy.cs プロジェクト: Artlock/SpaceInvaders
 private void FlipOnInput(FeatureToggle feature)
 {
     if (Input.GetKeyDown(feature.key))
     {
         feature.enabled = !feature.enabled;
     }
 }
コード例 #9
0
    // This runs once for every property in our shader.
    private void ShaderPropertyImpl(Shader shader, int propertyIndex, FeatureToggle currentToggle)
    {
        string propertyDescription = ShaderUtil.GetPropertyDescription(shader, propertyIndex);

        // If current toggle is null, we only want to show properties that aren't already "owned" by a toggle,
        // so if it is owned by another toggle, then return.
        if (currentToggle == null)
        {
            for (int i = 0; i < Toggles.Count; i++)
            {
                if (Regex.IsMatch(propertyDescription, Toggles[i].InspectorPropertyHideTag, RegexOptions.IgnoreCase))
                {
                    return;
                }
            }
        }
        // Only draw if we the current property is owned by the current toggle.
        else if (!Regex.IsMatch(propertyDescription, currentToggle.InspectorPropertyHideTag, RegexOptions.IgnoreCase))
        {
            return;
        }
        // If we've gotten to this point, draw the shader property regulairly.
        //ShaderProperty(shader,propertyIndex);
        Object[] temptarget = new Object[1];
        temptarget[0] = target;
        MaterialProperty prop = GetMaterialProperty(temptarget, propertyIndex);

        ShaderProperty(prop, propertyDescription);
    }
コード例 #10
0
        public void AddEnvironment_FeatureToggleStatus_IsCreated_ForEveryFeatureToggle()
        {
            //arrange
            var app = new Application {
                Id = 1, AppName = "TestApp"
            };
            var newEnvironment = new AddEnvironmentModel {
                ApplicationId = 1, EnvName = "DEV"
            };
            var featureOne = new FeatureToggle {
                Application = app, Id = 1, ApplicationId = app.Id, ToggleName = "TestToggle"
            };
            var featureTwo = new FeatureToggle {
                Application = app, Id = 2, ApplicationId = app.Id, ToggleName = "OtherTestToggle"
            };

            _context.Applications.Add(app);
            _context.FeatureToggles.AddRange(featureOne, featureTwo);
            _context.SaveChanges();
            var controller = new FeatureTogglesController(_context);

            //act
            var result = controller.AddEnvironment(newEnvironment);

            //assert
            result.Should().BeOfType <OkResult>();
            _context.FeatureToggleStatuses.Count().Should().Be(2);
        }
コード例 #11
0
        public void GetToggles_ReturnsAList_WithAllTheToggles_ForTheGivenApplication()
        {
            //arrange
            var app = new Application {
                AppName = "BCC", Id = 1
            };
            var date = DateTime.Now;
            var firstFeatureToggle = new FeatureToggle {
                Application = app, ApplicationId = app.Id, UserAccepted = true,
                ToggleName  = "TestToggle", CreatedDate = date, Notes = "TestNote", IsPermanent = true
            };

            var secondFeatureToggle = new FeatureToggle {
                Application = app, ApplicationId = app.Id, UserAccepted = false,
                ToggleName  = "TestToggle", CreatedDate = date, Notes = "TestNote"
            };

            _context.FeatureToggles.AddRange(firstFeatureToggle, secondFeatureToggle);
            _context.SaveChanges();

            var controller = new FeatureTogglesController(_context);

            //act
            var result = controller.GetToggles(app.Id) as OkObjectResult;
            var list   = result.Value as IEnumerable <FeatureToggleViewModel>;

            //assert
            list.Count().Should().Be(2);
            list.First().Notes.Should().Be(firstFeatureToggle.Notes);
            list.First().CreatedDate.Should().Be(date);
            list.First().ToggleName.Should().Be(firstFeatureToggle.ToggleName);
            list.First().UserAccepted.Should().Be(firstFeatureToggle.UserAccepted);
            list.First().IsPermanent.Should().Be(firstFeatureToggle.IsPermanent);
        }
コード例 #12
0
        public static Variant SelectVariant(FeatureToggle featureToggle, UnleashContext context, Variant defaultVariant)
        {
            var variantDefinitions = featureToggle.Variants;
            var totalWeight        = variantDefinitions.Sum(v => v.Weight);

            if (totalWeight == 0)
            {
                return(defaultVariant);
            }

            var variantOverride = GetOverride(variantDefinitions, context);

            if (variantOverride != null)
            {
                return(variantOverride.ToVariant());
            }

            var target = StrategyUtils.GetNormalizedNumber(GetIdentifier(context), featureToggle.Name, totalWeight);

            var counter = 0;

            foreach (var variantDefinition in variantDefinitions)
            {
                if (variantDefinition.Weight != 0)
                {
                    counter += variantDefinition.Weight;
                    if (counter >= target)
                    {
                        return(variantDefinition.ToVariant());
                    }
                }
            }

            return(defaultVariant);
        }
コード例 #13
0
        public void Updates_CanBeMade_ToExistingFeatureToggle()
        {
            //arrange
            var app = new Application {
                Id = 1, AppName = "TestApp"
            };
            var existingValue = new FeatureToggle {
                Id = 1, Application = app, ApplicationId = app.Id, ToggleName = "TestToggle", FeatureToggleStatuses = new List <FeatureToggleStatus>(), Notes = "FirstNote", IsPermanent = false
            };
            var updatedValue = new FeatureToggleUpdateModel {
                Id = 1, FeatureToggleName = "UpdatedFeatureToggleName", Notes = "Update", UserAccepted = true, Statuses = new List <FeatureToggleStatusUpdateModel>(), IsPermanent = true
            };

            _context.FeatureToggles.Add(existingValue);
            _context.SaveChanges();
            var controller = new FeatureTogglesController(_context);

            //act
            var result = controller.Update(updatedValue) as OkObjectResult;

            //assert
            _context.FeatureToggles.FirstOrDefault().ToggleName.Should().Be("UpdatedFeatureToggleName");
            _context.FeatureToggles.FirstOrDefault().Notes.Should().Be(updatedValue.Notes);
            _context.FeatureToggles.FirstOrDefault().UserAccepted.Should().BeTrue();
            _context.FeatureToggles.FirstOrDefault().IsPermanent.Should().BeTrue();
        }
コード例 #14
0
        public static string DisplayName(this FeatureToggle featureToggle)
        {
            var field     = featureToggle.GetType().GetField(featureToggle.ToString());
            var attribute = Attribute.GetCustomAttribute(field, typeof(FeatureDisplayNameAttribute)) as FeatureDisplayNameAttribute;

            return(attribute == null?featureToggle.ToString() : attribute.Value);
        }
コード例 #15
0
        public void TestToggleDoesNotExistExceptionIsReturnedWhenParsingAnItemThatDoesNotExist()
        {
            var configParser = new ToggleParser();
            IFeatureToggle <bool> featureToggle = new FeatureToggle <bool>();

            Assert.Throws <ToggleDoesNotExistException>(() => featureToggle.GetToggleState(configParser, "wewewewewewewewe"));
        }
コード例 #16
0
        public void TestUnSuccessfullParseReturnsToggleStatusInactive()
        {
            IToggleParser testParser     = new ToggleParserTestDouble();
            var           toggle         = new FeatureToggle <bool>();
            var           toggleResponse = toggle.GetToggleState(testParser, "anythingElse");

            Assert.AreEqual(ToggleStatus.Inactive, toggleResponse);
        }
コード例 #17
0
        public void TestActionFakeMethodThatReturnsTrueWillReturnFalseIfConfigItemIsToggledToFalse()
        {
            IFeatureToggle <bool> featureToggler = new FeatureToggle <bool>();

            var result = featureToggler.ExecuteMethodIfToggleOn(FakeMethodThatReturnsTrue, "FakeFalse");

            Assert.IsFalse(result);
        }
コード例 #18
0
        public void FeatureIsTurnedOffWhenResourceReturnedIsNull()
        {
            var restClient = new Mock <IRestClient>();

            var featureToggle = new FeatureToggle(restClient.Object);

            Assert.That(featureToggle.IsEnabled(Features.BaseValueSegment), Is.False);
        }
コード例 #19
0
        public void TestSuccessfullParseReturnsToggleStatusActive()
        {
            IToggleParser testParser     = new ToggleParserTestDouble();
            var           toggle         = new FeatureToggle <bool>();
            var           toggleResponse = toggle.GetToggleState(testParser, "positive");

            Assert.AreEqual(ToggleStatus.Active, toggleResponse);
        }
コード例 #20
0
        public void RunActionIfOffShouldNotRunActionWhenOn()
        {
            var featureToggle = new FeatureToggle(true);

            bool actionWasRun = false;

            featureToggle.RunActionIfOff(() => { actionWasRun = true; });
            Assert.IsFalse(actionWasRun);
        }
コード例 #21
0
        public void Map_Inactive()
        {
            var toggler = new FeatureToggle();
            var feature = toggler.For("Feature1");

            int i = feature.Map(active: () => 1, inactive: () => 2);

            Assert.That(i, Is.EqualTo(2));
        }
コード例 #22
0
        public ActionResult RepManual()
        {
            if (FeatureToggle.IsAlbania())
            {
                return(View("RepManual.sq"));
            }

            return(View("Manual"));
        }
コード例 #23
0
        public void TestToggleStatusInactiveIsReturnedWhenParsingAnItemThatIsToggledOff()
        {
            IToggleParser         configParser  = new ToggleParser();
            IFeatureToggle <bool> featureToggle = new FeatureToggle <bool>();

            var toggleStatus = featureToggle.GetToggleState(configParser, "NotFinished");

            Assert.AreEqual(ToggleStatus.Inactive, toggleStatus);
        }
コード例 #24
0
        public void TestToggleStatusActiveIsReturnedWhenParsingAnItemThatIsToggledOn()
        {
            IToggleParser         configParser  = new ToggleParser();
            IFeatureToggle <bool> featureToggle = new FeatureToggle <bool>();

            var toggleStatus = featureToggle.GetToggleState(configParser, "ButtonToggle");

            Assert.AreEqual(ToggleStatus.Active, toggleStatus);
        }
コード例 #25
0
 public string Serialize(FeatureToggle serializedFeatureToggle)
 {
     return(JsonConvert.SerializeObject(serializedFeatureToggle, Formatting.Indented, new JsonSerializerSettings()
     {
         NullValueHandling = NullValueHandling.Ignore,
         DateTimeZoneHandling = DateTimeZoneHandling.Utc,
         TypeNameHandling = TypeNameHandling.All
     }));
 }
コード例 #26
0
        public void TestSuccessfullFuncTestDataTypeCallWhenToggleStatusActive()
        {
            IToggleParser       testParser = new ToggleParserTestDouble();
            var                 toggle     = new FeatureToggle <TestDataType>();
            Func <TestDataType> theAction  = AlwaysReturnNewTestDataType;

            var toggleResponse = toggle.ExecuteMethodIfToggleOn(theAction, testParser, "positive");

            Assert.AreEqual(new TestDataType().HappynessIs, toggleResponse.HappynessIs);
        }
コード例 #27
0
        public void TestUnSuccessfullFuncTestDataTypeCallWhenToggleStatusInactive()
        {
            IToggleParser       testParser = new ToggleParserTestDouble();
            var                 toggle     = new FeatureToggle <TestDataType>();
            Func <TestDataType> theAction  = AlwaysReturnNewTestDataType;

            var toggleResponse = toggle.ExecuteMethodIfToggleOn(theAction, testParser, "anythingElse");

            Assert.IsNull(toggleResponse);
        }
コード例 #28
0
        public void Do_Inactive()
        {
            var toggler = new FeatureToggle();
            var feature = toggler.For("Feature1");
            int i       = 0;

            feature.Do(active: () => i = 1, inactive: () => i = 2);

            Assert.That(i, Is.EqualTo(2));
        }
コード例 #29
0
        protected void Page_Load(object sender, EventArgs e)
        {
            FeatureToggle.Initialize();

            string userName = this.featureCTextBox.Text;

            this.featureCLabel.Text = FeatureToggle.IsEnabled("featureC", userName) ? "On" : "Off";

            this.featureD.Visible = FeatureToggle.IsEnabled("featureD");
        }
コード例 #30
0
ファイル: Application.cs プロジェクト: appconfi/appconfi-web
        public FeatureToggle AddNewFeatureToggle(string key, string description)
        {
            Guard.IsFalse(FeatureToggles.Any(x => x.Key == key), "Duplicated key for this application");

            var featureToggle = FeatureToggle.New(key, description, this);

            FeatureToggles.Add(featureToggle);

            return(featureToggle);
        }
コード例 #31
0
        public void Should_delete_a_feature_and_audit()
        {
            var featureToDelete = new FeatureToggle("MyFeatureToDelete");

            var repository = new SqlServerRepository(_dbConnection);

            repository.Delete(featureToDelete.Id);

            _dbConnection.Received(1).Execute("delete FeatureToggle where Id = @Id", Arg.Any<object>());
            _dbConnection.Received(1).Execute("insert into FeatureToggleAudit (Id, Status, Enable, ModificationDate) values (@Id, @Status, @Enable, @ModificationDate)", Arg.Any<object>());
        }
コード例 #32
0
        public void Should_create_a_feature_and_audit()
        {
            var featureToCreate = new FeatureToggle("MyFeatureToDelete")
            {
                Type = "Test",
                Enable = true
            };

            var repository = new SqlServerRepository(_dbConnection);

            repository.Create(featureToCreate);

            _dbConnection.Received(1).Execute("insert into FeatureToggle (Id, Name, Type, Enable, Description) values (@Id, @Name, @Type, @Enable, @Description)", Arg.Any<object>());
            _dbConnection.Received(1).Execute("insert into FeatureToggleAudit (Id, Status, Enable, ModificationDate) values (@Id, @Status, @Enable, @ModificationDate)", Arg.Any<object>());
        }
コード例 #33
0
 public void is_instance_of_IFeatureToggle()
 {
     var sut = new FeatureToggle();
     Assert.IsInstanceOf<IFeatureToggle>(sut);
 }
コード例 #34
0
 public void id_returns_name_of_class()
 {
     var sut = new FeatureToggle();
     Assert.AreEqual("FeatureToggle", sut.Id);
 }
コード例 #35
0
	// This runs once for every property in our shader.
	private void ShaderPropertyImpl(Shader shader, int propertyIndex, FeatureToggle currentToggle)
	{
		string propertyDescription = ShaderUtil.GetPropertyDescription(shader, propertyIndex);
		
		// If current toggle is null, we only want to show properties that aren't already "owned" by a toggle,
		// so if it is owned by another toggle, then return.
		if (currentToggle == null)
		{
			for (int i = 0; i < Toggles.Count; i++)
			{
				if (Regex.IsMatch(propertyDescription, Toggles[i].InspectorPropertyHideTag , RegexOptions.IgnoreCase))
				{
					return; 
				}           
			}       
		}      
		// Only draw if we the current property is owned by the current toggle. 
		else if (!Regex.IsMatch(propertyDescription, currentToggle.InspectorPropertyHideTag , RegexOptions.IgnoreCase))
		{          
			return; 
		}       
		// If we've gotten to this point, draw the shader property regulairly.
		//ShaderProperty(shader,propertyIndex);
		Object[] temptarget = new Object[1];
		temptarget[0] = target;
		MaterialProperty prop = GetMaterialProperty(temptarget, propertyIndex);
		ShaderProperty(prop,propertyDescription);

	}