Esempio n. 1
0
        private void RunTestCase(BranchPickerTestCase testCase)
        {
            // Arrange.
            var pickingOptionsMock = new Mock <IBranchPickingOptions>();

            pickingOptionsMock.SetupGet(z => z.IncludeBranchesRegices).Returns(testCase.IncludeRegices);
            pickingOptionsMock.SetupGet(z => z.ExcludeBranchesRegices).Returns(testCase.ExcludeRegices);

            var expectedPickedSet = new HashSet <string>(testCase.ExpectedPicked, StringComparer.OrdinalIgnoreCase);

            BranchPicker picker = new BranchPicker(pickingOptionsMock.Object, Mock.Of <ILogger <BranchPicker> >());

            // Act.
            var pickedLabels = new List <string>();

            foreach (string input in testCase.Input)
            {
                if (picker.ShouldBePicked(input))
                {
                    pickedLabels.Add(input);
                }
            }

            // Verify.
            Assert.Equal(expectedPickedSet.Count, pickedLabels.Count);
            foreach (string pickedItem in pickedLabels)
            {
                Assert.Contains(pickedItem, expectedPickedSet);
            }
        }
Esempio n. 2
0
        public void GivenNoRules_ThenReturnsAllBranches()
        {
            BranchPickerTestCase testCase = new BranchPickerTestCase();

            testCase.Input          = new[] { "a", "b", "c" };
            testCase.ExpectedPicked = testCase.Input;

            RunTestCase(testCase);
        }
Esempio n. 3
0
        public void GivenSimpleIncludeRule_ThenTreatsItAsRegexForPicking()
        {
            BranchPickerTestCase testCase = new BranchPickerTestCase();

            testCase.Input          = new[] { "a", "b", "c" };
            testCase.ExpectedPicked = new[] { "b", "c" };
            testCase.IncludeRegices = new[] { "[bc]" };

            RunTestCase(testCase);
        }
Esempio n. 4
0
        public void GivenEmptyIncludeRule_ThenReturnsAll()
        {
            BranchPickerTestCase testCase = new BranchPickerTestCase();

            testCase.Input          = new[] { "a", "b", "c" };
            testCase.ExpectedPicked = testCase.Input;
            testCase.IncludeRegices = new string[0];

            RunTestCase(testCase);
        }
Esempio n. 5
0
        public void GivenTwoExcludeRules_ThenTreatsThemCorrectly()
        {
            BranchPickerTestCase testCase = new BranchPickerTestCase();

            testCase.Input          = new[] { "a", "b", "c" };
            testCase.ExpectedPicked = new[] { "c" };
            testCase.ExcludeRegices = new[] { "a", "[bd]" };

            RunTestCase(testCase);
        }
Esempio n. 6
0
        public void GivenIncludeAndExcludeRules_ThenTreatsIncludeWithHigherPriority()
        {
            BranchPickerTestCase testCase = new BranchPickerTestCase();

            testCase.Input          = new[] { "a", "b", "c" };
            testCase.ExpectedPicked = new[] { "b" };
            testCase.IncludeRegices = new[] { "b" };
            testCase.ExcludeRegices = new[] { "b", "c" };

            RunTestCase(testCase);
        }