public void ShouldFindUntrimmedSpecification() { var content = new[] { "someflag= true " }; var toggleChecker = new ToggleConfiguration(new FileParser(new FileReaderStub(content), new DefaultSpecificationMappings())).Create(); toggleChecker.IsEnabled("someflag") .Should().Be.True(); }
public void ShouldBeAbleToChangeDefaultSpecification() { var toggleChecker = new ToggleConfiguration(new FileParser(new FileReaderStub(new string[0]), new DefaultSpecificationMappings())) .SetDefaultSpecification(new TrueSpecification()) .Create(); toggleChecker.IsEnabled("sometoggle") .Should().Be.True(); }
public void ShouldBeEnabled() { var content = new[] {"someflag=true"}; tempPath = Path.GetTempFileName(); File.WriteAllLines(tempPath, content); var toggleChecker = new ToggleConfiguration(new FileParser(new FileReader(tempPath), new DefaultSpecificationMappings())).Create(); toggleChecker.IsEnabled("someflag") .Should().Be.True(); }
public void ShouldAllowCommentingInsideARow() { var content = new[] { "someflag=true #this should be possible" }; var toggleChecker = new ToggleConfiguration(new FileParser(new FileReaderStub(content), new DefaultSpecificationMappings())).Create(); toggleChecker.IsEnabled("someflag") .Should().Be.True(); }
public void AllMustBeEnabledByDefault() { var content = new[] { "someflag=false", "someflag=true" }; var toggleChecker = new ToggleConfiguration(new FileParser(new FileReaderStub(content), new DefaultSpecificationMappings())).Create(); toggleChecker.IsEnabled("someflag") .Should().Be.False(); }
public void ShouldBeAbleToWriteRemarks() { var content = new[] { "#this should not throw", "someflag=true", " # and neither should this" }; var toggleChecker = new ToggleConfiguration(new FileParser(new FileReaderStub(content), new DefaultSpecificationMappings())).Create(); toggleChecker.IsEnabled("someflag") .Should().Be.True(); }
public void ShouldAllowBlankLines() { var content = new[] { " ", "someflag=true", "", string.Empty }; var toggleChecker = new ToggleConfiguration(new FileParser(new FileReaderStub(content), new DefaultSpecificationMappings())).Create(); toggleChecker.IsEnabled("someflag") .Should().Be.True(); }
public void ShouldBeEnabledIfExistsInParameterListWithSpaces() { var content = new[] { "someflag=user", "someflag.user." + UserSpecification.Ids + " = 1, 2 , 3 ,4 " }; var toggleChecker = new ToggleConfiguration(new FileParser(new FileReaderStub(content), new DefaultSpecificationMappings())) .SetUserProvider(new UserProviderStub("2")) .Create(); toggleChecker.IsEnabled("someflag") .Should().Be.True(); }
public void ShouldBeDisabled() { var content = new[] { "someflag=user", "someflag.user." + UserSpecification.Ids + "=nope" }; var toggleChecker = new ToggleConfiguration(new FileParser(new FileReaderStub(content), new DefaultSpecificationMappings())) .SetUserProvider(new UserProviderStub("10")) .Create(); toggleChecker.IsEnabled("someflag") .Should().Be.False(); }
public void ShouldBeAbleToRunSingleParameterSpecificationUsingOneLine() { var content = new[] { "someflag.ParameterSpecification." + SpecificationWithParameter.ParameterName + "=true" }; var mappings = new DefaultSpecificationMappings(); mappings.AddMapping("parameterspecification", new SpecificationWithParameter()); var fileProvider = new FileParser(new FileReaderStub(content), mappings); var toggleChecker = new ToggleConfiguration(fileProvider).Create(); toggleChecker.IsEnabled("someflag") .Should().Be.True(); }
public void ShouldAlwaysBeDisabledIf0Percent() { var content = new[] { "someflag=random", "someflag.random." + RandomSpecification.Percent + "=0" }; var toggleChecker = new ToggleConfiguration(new FileParser(new FileReaderStub(content), new DefaultSpecificationMappings())) .SetUserProvider(new UserProviderStub("something")) .Create(); toggleChecker.IsEnabled("someflag") .Should().Be.False(); }
public void ShouldBeDisabled() { var content = new[] { "someflag=ParametersSpecification", "someflag.ParametersSpecification." + SpecificationWithMultipleParameters.ParameterName1 + "=true", "someflag.ParametersSpecification." + SpecificationWithMultipleParameters.ParameterName2 + "=false", "someflag.ParametersSpecification." + SpecificationWithMultipleParameters.ParameterName3 + "=true" }; var mappings = new DefaultSpecificationMappings(); mappings.AddMapping("parametersSpecification", new SpecificationWithMultipleParameters()); var fileProvider = new FileParser(new FileReaderStub(content), mappings); var toggleChecker = new ToggleConfiguration(fileProvider).Create(); toggleChecker.IsEnabled("someflag") .Should().Be.False(); }
public void ShouldHandleMiss() { const string wordToMatch = "the toggle"; var content = new[] { "sometoggle=myRegex", "sometoggle.myRegex." + RegExSpecification.RegExParameter + "=" + wordToMatch }; var mappings = new DefaultSpecificationMappings(); mappings.AddMapping("myRegex", new RegExSpecification(new Regex("^somethingelse$"))); var toggleChecker = new ToggleConfiguration(new FileParser(new FileReaderStub(content), mappings)) .Create(); toggleChecker.IsEnabled("sometoggle") .Should().Be.False(); }
public void ShouldReturnSameValueForOneSpecificUser() { var content = new[] { "someflag=random", "someflag.random." + RandomSpecification.Percent + "=50" }; var toggleChecker = new ToggleConfiguration(new FileParser(new FileReaderStub(content), new DefaultSpecificationMappings())) .SetUserProvider(new UserProviderStub("something")) .Create(); var firstResult = toggleChecker.IsEnabled("someflag"); toggleChecker.IsEnabled("someflag").Should().Be.EqualTo(firstResult); toggleChecker.IsEnabled("someflag").Should().Be.EqualTo(firstResult); toggleChecker.IsEnabled("someflag").Should().Be.EqualTo(firstResult); toggleChecker.IsEnabled("someflag").Should().Be.EqualTo(firstResult); }
public void ShouldRandomize() { var content = new[] { "someflag=random", "someflag.random." + RandomSpecification.Percent + "=50" }; var toggleChecker = new ToggleConfiguration(new FileParser(new FileReaderStub(content), new DefaultSpecificationMappings())) .SetUserProvider(new UserProviderRandom()) .Create(); const int numberOfQueries = 10000; var numberOfEnabled = 0; for (var x = 0; x < numberOfQueries; x++) { if (toggleChecker.IsEnabled("someflag")) numberOfEnabled++; } numberOfEnabled.Should().Be.IncludedIn(3000, 7000); }
public void ShouldTreatIdsAsOneIfCurrentUserContainsComma_Enabled() { var content = new[] { "someflag=user", "someflag.user." + UserSpecification.Ids + "= 1,2,3,4 " }; var toggleChecker = new ToggleConfiguration(new FileParser(new FileReaderStub(content), new DefaultSpecificationMappings())) .SetUserProvider(new UserProviderStub("1,2,3,4")) .Create(); toggleChecker.IsEnabled("someflag") .Should().Be.True(); }
public void ShouldNotBeCaseSensitiveWhenCurrentUserContainsComma() { var content = new[] { "someflag=user", "someflag.user." + UserSpecification.Ids + "=roger," }; var toggleChecker = new ToggleConfiguration(new FileParser(new FileReaderStub(content), new DefaultSpecificationMappings())) .SetUserProvider(new UserProviderStub("ROGER,")) .Create(); toggleChecker.IsEnabled("someflag") .Should().Be.True(); }