Beispiel #1
0
        public void Filter_WithRuleIdPredicate_ReturnsLogWithExpectedResultsAndRunLevelArrayContentsFromSelectedResults()
        {
            FilteringVisitor.IncludeResultPredicate predicate =
                (Result result) => result.RuleId.Equals(TestData.RuleIds.Rule1, StringComparison.InvariantCulture);

            RunTest("FilterByPredicate.sarif", "RuleIdPredicate.sarif", predicate);
        }
Beispiel #2
0
        /// <summary>
        /// Filter the specified SARIF log to create a new log containing only those results for
        /// which the specified predicate returns true, and only those elements of run-level
        /// collections such as Run.Artifacts that are relevant to the filtered results.
        /// </summary>
        /// <param name="log">
        /// The log file to be filtered.
        /// </param>
        /// <param name="predicate">
        /// The predicate that selects the results in the filtered log file.
        /// </param>
        /// <returns>
        /// A new SARIF log containing only the filtered results, and only the relevant elements
        /// of the run-level collections.
        /// </returns>
        public static SarifLog Filter(SarifLog log, FilteringVisitor.IncludeResultPredicate predicate)
        {
            SarifLog newLog = log.DeepClone();

            var visitor = new FilteringVisitor(predicate);

            return(visitor.VisitSarifLog(newLog));
        }
Beispiel #3
0
        public void Filter_WithAlwaysFalsePredicate_ReturnsLogWithNoResultsAndNoRunLevelArrayContents()
        {
            FilteringVisitor.IncludeResultPredicate predicate = (Result result) => false;

            RunTest("FilterByPredicate.sarif", "AlwaysFalsePredicate.sarif", predicate);
        }
Beispiel #4
0
        public void Filter_WithAlwaysTruePredicate_ReturnsLogWithAllResultsAndRunLevelArrayContentsFromAllResults()
        {
            FilteringVisitor.IncludeResultPredicate predicate = result => true;

            RunTest("FilterByPredicate.sarif", "AlwaysTruePredicate.sarif", predicate);
        }