Ejemplo n.º 1
0
		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();
		}
Ejemplo n.º 2
0
		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();
		}
Ejemplo n.º 3
0
		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();
		}
Ejemplo n.º 4
0
		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();
		}
Ejemplo n.º 6
0
		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();
		}
Ejemplo n.º 7
0
		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();
		}
Ejemplo n.º 8
0
		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();
		}
Ejemplo n.º 9
0
		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();
		}
Ejemplo n.º 10
0
		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();
		}
Ejemplo n.º 11
0
		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();
		}
Ejemplo n.º 12
0
		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();
		}  
Ejemplo n.º 13
0
		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();
		}
Ejemplo n.º 14
0
		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);
		}
Ejemplo n.º 15
0
		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);
		}
Ejemplo n.º 16
0
		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();
		}
Ejemplo n.º 17
0
		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();
		}