Exemplo n.º 1
0
        public void PerRunPerRuleSplittingVisitor_EmptyLog()
        {
            var visitor = new PerRunPerRuleSplittingVisitor();

            visitor.VisitRun(new Run());
            visitor.SplitSarifLogs.Count.Should().Be(0);
        }
Exemplo n.º 2
0
        public void PerRunPerRuleSplittingVisitor_RetainsNewResultsOnly()
        {
            var sarifLog = new SarifLog
            {
                Runs = new[]
                {
                    new Run
                    {
                        Results = new[]
                        {
                            new Result
                            {
                                RuleId        = TestConstants.RuleIds.Rule1,
                                BaselineState = BaselineState.New
                            },

                            new Result
                            {
                                RuleId        = TestConstants.RuleIds.Rule2,
                                BaselineState = BaselineState.Updated
                            },

                            new Result
                            {
                                RuleId        = TestConstants.RuleIds.Rule2,
                                BaselineState = BaselineState.New
                            }
                        }
                    }
                }
            };

            var visitor = new PerRunPerRuleSplittingVisitor();

            visitor.VisitSarifLog(sarifLog);

            visitor.SplitSarifLogs.Count.Should().Be(2);

            visitor.SplitSarifLogs[0].Runs[0].Results.Count.Should().Be(1);
            visitor.SplitSarifLogs[0].Runs[0].Results[0].RuleId.Should().Be(TestConstants.RuleIds.Rule1);

            visitor.SplitSarifLogs[1].Runs[0].Results.Count.Should().Be(1);
            visitor.SplitSarifLogs[1].Runs[0].Results[0].RuleId.Should().Be(TestConstants.RuleIds.Rule2);
        }
Exemplo n.º 3
0
        public void PerRunPerRuleSplittingVisitor_RetainsRulesForUnbaselinedAndNewResultsOnly()
        {
            SarifLog sarifLog = GetTestSarifLog();

            HashSet <string> ruleIds = new HashSet <string>();

            for (int i = 0; i < sarifLog.Runs[0].Results.Count; i++)
            {
                Result result = sarifLog.Runs[0].Results[i];
                if (result.BaselineState == BaselineState.New ||
                    result.BaselineState == BaselineState.None)
                {
                    ruleIds.Add(result.RuleId);
                }
            }

            int ruleCount = ruleIds.Count;

            var visitor = new PerRunPerRuleSplittingVisitor();

            visitor.VisitSarifLog(sarifLog);

            visitor.SplitSarifLogs.Count.Should().Be(ruleCount);
        }