Exemplo n.º 1
0
        public void Format_should_separate_groups_properly_when_formatting_with_custom_match(string testInput, string[] inputUsingNamespaces, string[] expectedOutputNamespaces)
        {
            // Arrange
            var inputUsings = inputUsingNamespaces.Select(ns => new UsingStatement()
            {
                Namespace = ns
            });

            var rule = GroupingRule.Parse(testInput).Single();

            var output = new OutputBuffer();

            // Act
            rule.Format(output, inputUsings);

            // Assert
            var expectedUsings = expectedOutputNamespaces.Select(ns => (ns == "") ? "" : $"using {ns};");

            output
            .GetLines()
            .Zip(expectedUsings)
            .Apply(
                ((string Actual, string Expected)pair, int index) =>
            {
                pair.Actual.Should().Be(pair.Expected, because: $"line {index} should match");
            });
Exemplo n.º 2
0
        public void Parse_should_parse_empty_string_as_empty_sequence(string testInput)
        {
            // Act
            var rules = GroupingRule.Parse(testInput);

            rules = rules.ToList();

            // Assert
            rules.Should().BeEmpty();
        }
Exemplo n.º 3
0
        public void Parse_should_parse_direct_namespace_name(string testInput, string expectedParsedNamespace)
        {
            // Act
            var rules = GroupingRule.Parse(testInput);

            rules = rules.ToList();

            // Assert
            rules.Should().HaveCount(1);

            rules.Single().MatchList.Should().HaveCount(1);
            rules.Single().MatchList.Should().HaveElementAt(index: 0, expectedParsedNamespace);

            rules.Single().SubgroupingBehaviour.Should().Be(SubgroupingBehaviour.MatchRootGroup);
        }
        public void Format_should_produce_matching_output(FormatTestCase testCase)
        {
            // Arrange
            var groupingRules = GroupingRule.Parse(testCase.ConfigurationString);

            var outputBuffer = new StringWriter();

            // Act
            UsingStatementFormatter.Format(
                outputBuffer,
                testCase.Input,
                groupingRules);

            // Assert
            outputBuffer.ToString().Should().Be(testCase.ExpectedOutput);
        }
Exemplo n.º 5
0
        public void IsMatch_should_return_false_when_no_match_list()
        {
            // Arrange
            var rule = new GroupingRule();

            var usingStatement = new UsingStatement()
            {
                Namespace = "Foo"
            };

            // Act
            var result = rule.IsMatch(usingStatement);

            // Assert
            result.Should().BeFalse();
        }
Exemplo n.º 6
0
        public void Parse_should_parse_wildcard_with_matchlist(string testInput, SubgroupingBehaviour expectedSubgroupingBehaviour, string[] expectedMatchList)
        {
            // Act
            var rules = GroupingRule.Parse(testInput);

            rules = rules.ToList();

            // Assert
            rules.Should().HaveCount(1);

            var rule = rules.Single();

            rule.MatchList.Should().BeEquivalentTo(expectedMatchList);

            rule.SubgroupingBehaviour.Should().Be(expectedSubgroupingBehaviour);
        }
Exemplo n.º 7
0
        public void Parse_should_parse_wildcard_with_no_matchlist(string testInput, SubgroupingBehaviour expectedSubgroupingBehaviour)
        {
            // Act
            var rules = GroupingRule.Parse(testInput);

            rules = rules.ToList();

            // Assert
            rules.Should().HaveCount(1);

            var rule = rules.Single();

            rule.MatchList.Should().HaveCount(1);
            rule.MatchList.Should().HaveElementAt(index: 0, "*");

            rule.SubgroupingBehaviour.Should().Be(expectedSubgroupingBehaviour);
        }
Exemplo n.º 8
0
        public void IsMatch_should_return_true_when_prefix_match([Values] MatchingEntryIndex matching)
        {
            // Arrange
            var rule = new GroupingRule();

            rule.MatchList.Add("Foo");
            rule.MatchList.Add("Bar");
            rule.MatchList.Add("Qux");

            var usingStatement = new UsingStatement()
            {
                Namespace = rule.MatchList[(int)matching] + ".Common"
            };

            // Act
            var result = rule.IsMatch(usingStatement);

            // Assert
            result.Should().BeTrue();
        }
Exemplo n.º 9
0
        public void IsMatch_should_return_false_when_no_matches()
        {
            // Arrange
            var rule = new GroupingRule();

            rule.MatchList.Add("Foo");
            rule.MatchList.Add("Bar");
            rule.MatchList.Add("Qux");

            var usingStatement = new UsingStatement()
            {
                Namespace = "Eenp"
            };

            // Act
            var result = rule.IsMatch(usingStatement);

            // Assert
            result.Should().BeFalse();
        }
Exemplo n.º 10
0
        public void Parse_should_handle_multiple_rules(string testInput)
        {
            // Act
            var rules = GroupingRule.Parse(testInput)
                        .ToList();

            // Assert
            rules.Should().HaveCount(4);

            rules[0].MatchList.Should().BeEquivalentTo(new[] { "System" });
            rules[0].SubgroupingBehaviour.Should().Be(SubgroupingBehaviour.MatchRootGroup);

            rules[1].MatchList.Should().BeEquivalentTo(new[] { "Test" });
            rules[1].SubgroupingBehaviour.Should().Be(SubgroupingBehaviour.MatchSubgroupsOnlyAsSeparateBlocks);

            rules[2].MatchList.Should().BeEquivalentTo(new[] { "A", "B" });
            rules[2].SubgroupingBehaviour.Should().Be(SubgroupingBehaviour.MatchRootGroupAndSubgroupsAsSingleBlock);

            rules[3].MatchList.Should().BeEquivalentTo(new[] { "*" });
            rules[3].SubgroupingBehaviour.Should().Be(SubgroupingBehaviour.MatchSubgroupsOnlyAsSeparateBlocks);
        }