public void ShouldThrowIfAddingMultipleSpecificationDifferOnlyInCasing()
		{
			var mappings = new DefaultSpecificationMappings();
			mappings.AddMapping("DOUBle", new TrueSpecification());
			Assert.Throws<ArgumentException>(() =>
				mappings.AddMapping("double", new TrueSpecification()));
		}
		public void ShouldThrowIfAddingSpecificationsWithSameName()
		{
			var mappings = new DefaultSpecificationMappings();
			mappings.AddMapping("double", new TrueSpecification());
			Assert.Throws<ArgumentException>(() => 
				mappings.AddMapping("double", new TrueSpecification()));
		}
		public void ShouldNotBeAbleToChangeNameSpecificationMappings()
		{
			var mappings = new DefaultSpecificationMappings();
			var specificationMappings = mappings.NameSpecificationMappings();
			specificationMappings.Add("added", new TrueSpecification());

			mappings.NameSpecificationMappings().Count
				.Should().Not.Be.EqualTo(specificationMappings.Count);
		}
		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 ShouldThrowIfParameterIsUsedAndMoreThanTwoDotsExist()
		{
			var content = new[]
			{
				"myfeature=ParameterSpecification",
				"myfeature.ParameterSpecification.three.four=true"
			};
			var mappings = new DefaultSpecificationMappings();
			mappings.AddMapping("parameterSpecification", new SpecificationWithParameter());
			var fileProvider = new FileParser(new FileReaderStub(content), mappings);

			Assert.Throws<IncorrectTextFileException>(() =>
				new ToggleConfiguration(fileProvider).Create()
				).ToString()
				.Should().Contain(string.Format(FileParser.MustHaveTwoDotsIfParameterUse, 2));
		}
		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();
		}  
Exemple #7
0
		public void ShouldThrowIfRegExIsMissing()
		{
			const string wordToMatch = "the toggle";

			var content = new[]
			{
				"sometoggle=myRegex"
			};
			var mappings = new DefaultSpecificationMappings();
			mappings.AddMapping("myRegex", new RegExSpecification(new Regex("^" + wordToMatch + "$")));

			Assert.Throws<IncorrectTextFileException>(() => 
				new ToggleConfiguration(new FileParser(new FileReaderStub(content), mappings))
				.Create()).ToString()
			.Should().Contain(string.Format(RegExSpecification.MustDeclareRegexPattern, "sometoggle"));
		}
		public void ShouldThrowIfParameterIsDeclaredMoreThanOnce()
		{
			var content = new[]
			{
				"someflag=ParameterSpecification",
				"someflag.ParameterSpecification." + SpecificationWithParameter.ParameterName + "=true",
				"someflag.ParameterSpecification." + SpecificationWithParameter.ParameterName + "=true"
			};
			var mappings = new DefaultSpecificationMappings();
			mappings.AddMapping("parameterSpecification", new SpecificationWithParameter());
			var fileProvider = new FileParser(new FileReaderStub(content), mappings);

			Assert.Throws<IncorrectTextFileException>(() =>
				new ToggleConfiguration(fileProvider).Create()
				).ToString()
				.Should().Contain(string.Format(FileParser.MustOnlyContainSameParameterOnce, SpecificationWithParameter.ParameterName, 3));
		}
Exemple #9
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();
		}