示例#1
0
        private void LinkResultsWithIdenticalWhere()
        {
            // Walk Results sorted by where, linking those with identical positions and a matching category.
            int beforeIndex = 0, afterIndex = 0;

            while (beforeIndex < Before.Count && afterIndex < After.Count)
            {
                ExtractedResult left  = Before[beforeIndex];
                ExtractedResult right = After[afterIndex];

                int whereCmp = WhereComparer.CompareWhere(left, right);
                if (whereCmp < 0)
                {
                    // Left is in a 'Where' before Right - look at the next Result in 'Before'.
                    beforeIndex++;
                }
                else if (whereCmp > 0)
                {
                    // Right is in a 'Where' before Left - look at the next Result in 'After'.
                    afterIndex++;
                }
                else
                {
                    // The Results have a matching where. If the category matches, link them.
                    if (left.MatchesCategory(right))
                    {
                        LinkIfSimilar(beforeIndex, afterIndex);
                    }

                    // Look at the next pair of Results.
                    beforeIndex++;
                    afterIndex++;
                }
            }
        }
示例#2
0
        public void WhatComparer_MatchesCategory()
        {
            Run run = new Run()
            {
                Tool = new Tool()
                {
                    Driver = new ToolComponent()
                    {
                        Rules = new List <ReportingDescriptor>()
                        {
                            new ReportingDescriptor()
                            {
                                Id = "Rule001"
                            },
                            new ReportingDescriptor()
                            {
                                Id = "Rule002"
                            },
                            new ReportingDescriptor()
                            {
                                Id            = "Rule001_v2",
                                DeprecatedIds = new List <string>()
                                {
                                    "Rule001"
                                }
                            }
                        }
                    }
                }
            };

            ExtractedResult left;
            ExtractedResult right;

            // Same RuleIndex: Matches
            left = new ExtractedResult(new Result()
            {
                RuleIndex = 0
            }, run);
            right = new ExtractedResult(new Result()
            {
                RuleIndex = 0
            }, run);
            left.MatchesCategory(right).Should().BeTrue();
            right.MatchesCategory(left).Should().BeTrue();

            // RuleId from index matches RuleId: Matches
            left = new ExtractedResult(new Result()
            {
                RuleId = "Rule001"
            }, run);
            left.MatchesCategory(right).Should().BeTrue();
            right.MatchesCategory(left).Should().BeTrue();

            // Different RuleId: Non-Match
            left = new ExtractedResult(new Result()
            {
                RuleIndex = 1
            }, run);
            left.MatchesCategory(right).Should().BeFalse();
            right.MatchesCategory(left).Should().BeFalse();

            // RuleId is a DeprecatedId from other Rule: Matches
            left = new ExtractedResult(new Result()
            {
                RuleIndex = 2
            }, run);
            left.MatchesCategory(right).Should().BeTrue();
            right.MatchesCategory(left).Should().BeTrue();

            // DeprecatedIds, but they don't match
            right = new ExtractedResult(new Result()
            {
                RuleIndex = 1
            }, run);
            left.MatchesCategory(right).Should().BeFalse();
            right.MatchesCategory(left).Should().BeFalse();
        }