public void IdenticalResultMatcher_DoesNotMatchDifferentResults_Multiple()
        {
            ExtractedResult resultAA = new ExtractedResult()
            {
                Result = ResultMatchingTestHelpers.CreateMatchingResult("file://test", "file://test2", "test context1")
            };

            ExtractedResult resultBA = new ExtractedResult()
            {
                Result = ResultMatchingTestHelpers.CreateMatchingResult("file://test", "file://test2", "test context2")
            };

            ExtractedResult resultAB = new ExtractedResult()
            {
                Result = ResultMatchingTestHelpers.CreateMatchingResult("file://test", "file://test2", "test context3")
            };

            ExtractedResult resultBB = new ExtractedResult()
            {
                Result = ResultMatchingTestHelpers.CreateMatchingResult("file://test", "file://test2", "test context4")
            };


            IEnumerable <MatchedResults> matchedResults = matcher.Match(new ExtractedResult[] { resultAA, resultAB }, new ExtractedResult[] { resultBA, resultBB });

            matchedResults.Should().BeEmpty();
        }
        public void PartialFingerprintResultMatcher_SamePartialFingerprints_Matches()
        {
            ExtractedResult resultA = new ExtractedResult(ResultMatchingTestHelpers.CreateMatchingResult("file://test1", "file://test2", null), null);

            resultA.Result.PartialFingerprints = new Dictionary <string, string>()
            {
                { "Fingerprint1", "Value1" }
            };

            ExtractedResult resultB = new ExtractedResult(ResultMatchingTestHelpers.CreateMatchingResult("file://test3", "file://test4", null), null);

            resultA.Result.PartialFingerprints = new Dictionary <string, string>()
            {
                { "Fingerprint1", "Value1" }
            };

            IEnumerable <MatchedResults> matchedResults = matcher.Match(new List <ExtractedResult>()
            {
                resultA
            }, new List <ExtractedResult>()
            {
                resultB
            });

            matchedResults.Should().BeEmpty();
        }
        public void IdenticalResultMatcher_MatchesResults_DifferingOnIdOrStatus_Multiple()
        {
            ExtractedResult resultAA = new ExtractedResult(ResultMatchingTestHelpers.CreateMatchingResult("file://test", "file://test2", "test context"), null);

            Result changedResultA = resultAA.Result.DeepClone();

            changedResultA.CorrelationGuid = Guid.NewGuid().ToString();
            changedResultA.BaselineState   = BaselineState.Unchanged;

            ExtractedResult resultBA = new ExtractedResult(changedResultA, null);
            ExtractedResult resultAB = new ExtractedResult(ResultMatchingTestHelpers.CreateMatchingResult("file://test", "file://test2", "test context2"), null);

            Result changedResultB = resultAB.Result.DeepClone();

            changedResultA.CorrelationGuid = Guid.NewGuid().ToString();
            changedResultA.BaselineState   = BaselineState.New;

            ExtractedResult resultBB = new ExtractedResult(changedResultB, null);

            IEnumerable <MatchedResults> matchedResults = matcher.Match(new ExtractedResult[] { resultAA, resultAB }, new ExtractedResult[] { resultBA, resultBB });

            matchedResults.Should().HaveCount(2);
            matchedResults.Where(f => f.PreviousResult == resultAA && f.CurrentResult == resultBA).Should().HaveCount(1);
            matchedResults.Where(f => f.PreviousResult == resultAB && f.CurrentResult == resultBB).Should().HaveCount(1);
        }
        public void IdenticalResultMatcher_MatchesIdenticalResults_Multiple()
        {
            ExtractedResult resultAA = new ExtractedResult()
            {
                Result = ResultMatchingTestHelpers.CreateMatchingResult("file://test", "file://test2", "test context")
            };

            ExtractedResult resultBA = new ExtractedResult()
            {
                Result = resultAA.Result.DeepClone()
            };

            ExtractedResult resultAB = new ExtractedResult()
            {
                Result = ResultMatchingTestHelpers.CreateMatchingResult("file://test", "file://test2", "test context2")
            };

            ExtractedResult resultBB = new ExtractedResult()
            {
                Result = resultAB.Result.DeepClone()
            };


            IEnumerable <MatchedResults> matchedResults = matcher.Match(new ExtractedResult[] { resultAA, resultAB }, new ExtractedResult[] { resultBA, resultBB });

            matchedResults.Should().HaveCount(2);
            matchedResults.Where(f => f.PreviousResult == resultAA && f.CurrentResult == resultBA).Should().HaveCount(1);
            matchedResults.Where(f => f.PreviousResult == resultAB && f.CurrentResult == resultBB).Should().HaveCount(1);
        }
        public void FullFingerprintMatcher_DoesNotMatchOnChangedFingerprints()
        {
            Result resultA = ResultMatchingTestHelpers.CreateMatchingResult(@"http://testtesttest", @"file://testa", "contextual contexty contexts");
            Result resultB = ResultMatchingTestHelpers.CreateMatchingResult(@"http://testtesttest", @"file://testa", "contextual contexty contexts");

            resultA.Fingerprints = new Dictionary <string, string>()
            {
                { "FingerprintAlgorithm1", "FingerprintValue1" }, { "FingerprintAlgorithm2", "FingerprintValue2" }
            };
            resultB.Fingerprints = new Dictionary <string, string>()
            {
                { "FingerprintAlgorithm1", "FingerprintValue3" }, { "FingerprintAlgorithm2", "FingerprintValue4" }
            };

            ExtractedResult matchingResultA = new ExtractedResult()
            {
                Result = resultA
            };
            ExtractedResult matchingResultB = new ExtractedResult()
            {
                Result = resultB
            };

            IEnumerable <MatchedResults> matchedResults = matcher.Match(new ExtractedResult[] { matchingResultA }, new ExtractedResult[] { matchingResultB });

            matchedResults.Should().HaveCount(0);
        }
        public void FullFingerprintMatcher_MatchesIdenticalFingerprints()
        {
            Result resultA = ResultMatchingTestHelpers.CreateMatchingResult(@"http://testtesttest", @"file://testa", "contextual contexty contexts");
            Result resultB = ResultMatchingTestHelpers.CreateMatchingResult(@"http://notasmuchatest", @"file://differentpath", "different contexty contexts");

            resultA.Fingerprints = new Dictionary <string, string>()
            {
                { "FingerprintAlgorithm1", "FingerprintValue1" }, { "FingerprintAlgorithm2", "FingerprintValue2" }
            };
            resultB.Fingerprints = new Dictionary <string, string>()
            {
                { "FingerprintAlgorithm1", "FingerprintValue1" }
            };

            ExtractedResult matchingResultA = new ExtractedResult()
            {
                Result = resultA
            };
            ExtractedResult matchingResultB = new ExtractedResult()
            {
                Result = resultB
            };


            IEnumerable <MatchedResults> matchedResults = matcher.Match(new ExtractedResult[] { matchingResultA }, new ExtractedResult[] { matchingResultB });

            matchedResults.Should().HaveCount(1);
            matchedResults.First().PreviousResult.Should().BeEquivalentTo(matchingResultA);
            matchedResults.First().CurrentResult.Should().BeEquivalentTo(matchingResultB);
        }
        public void IdenticalResultMatcher_DoesNotMatchDifferentResults_Single()
        {
            ExtractedResult resultA = new ExtractedResult(ResultMatchingTestHelpers.CreateMatchingResult("file://test", "file://test2", "test context"), null);
            ExtractedResult resultB = new ExtractedResult(ResultMatchingTestHelpers.CreateMatchingResult("file://test", "file://test2", "test context2"), null);

            IEnumerable <MatchedResults> matchedResults = matcher.Match(new ExtractedResult[] { resultA }, new ExtractedResult[] { resultB });

            matchedResults.Should().BeEmpty();
        }
        public void IdenticalResultMatcher_MatchesIdenticalResults_Single()
        {
            ExtractedResult resultA = new ExtractedResult(ResultMatchingTestHelpers.CreateMatchingResult("file://test", "file://test2", "test context"), null);
            ExtractedResult resultB = new ExtractedResult(resultA.Result.DeepClone(), null);

            IEnumerable <MatchedResults> matchedResults = matcher.Match(new ExtractedResult[] { resultA }, new ExtractedResult[] { resultB });

            matchedResults.Should().HaveCount(1);
            matchedResults.First().PreviousResult.Should().BeEquivalentTo(resultA);
            matchedResults.First().CurrentResult.Should().BeEquivalentTo(resultB);
        }
        public void ContextRegionHeuristicMatcher_SameRegion_MatchesResults()
        {
            ExtractedResult resultA = new ExtractedResult(ResultMatchingTestHelpers.CreateMatchingResult("file://test1", "file://test2", null, "region contents"), null);
            ExtractedResult resultB = new ExtractedResult(ResultMatchingTestHelpers.CreateMatchingResult("file://test3", "file://test4", null, "region contents"), null);

            IEnumerable <MatchedResults> matchedResults = matcher.Match(new List <ExtractedResult>()
            {
                resultA
            }, new List <ExtractedResult>()
            {
                resultB
            });

            matchedResults.Should().HaveCount(1);
        }
        public void ContextRegionHeuristicMatcher_DifferentRegion_DoesNotMatchResults()
        {
            ExtractedResult resultA = new ExtractedResult(ResultMatchingTestHelpers.CreateMatchingResult("file://test1", "file://test2", null, "test one"), null);
            ExtractedResult resultB = new ExtractedResult(ResultMatchingTestHelpers.CreateMatchingResult("file://test3", "file://test4", null, "test two"), null);

            IEnumerable <MatchedResults> matchedResults = matcher.Match(new List <ExtractedResult>()
            {
                resultA
            }, new List <ExtractedResult>()
            {
                resultB
            });

            matchedResults.Should().BeEmpty();
        }
        public void PartialFingerprintResultMatcher_WithoutPartialFingerprints_DoesNotMatch()
        {
            ExtractedResult resultA = new ExtractedResult(ResultMatchingTestHelpers.CreateMatchingResult("file://test1", "file://test2", null), null);
            ExtractedResult resultB = new ExtractedResult(ResultMatchingTestHelpers.CreateMatchingResult("file://test3", "file://test4", null), null);

            IEnumerable <MatchedResults> matchedResults = matcher.Match(new List <ExtractedResult>()
            {
                resultA
            }, new List <ExtractedResult>()
            {
                resultB
            });

            matchedResults.Should().BeEmpty();
        }
        public void IdenticalResultMatcher_MatchesResults_DifferingOnIdOrStatus_Single()
        {
            ExtractedResult resultA = new ExtractedResult(ResultMatchingTestHelpers.CreateMatchingResult("file://test", "file://test2", "test context"), null);

            Result changedResultA = resultA.Result.DeepClone();

            changedResultA.CorrelationGuid = Guid.NewGuid().ToString();
            changedResultA.BaselineState   = BaselineState.Unchanged;

            ExtractedResult resultB = new ExtractedResult(changedResultA, null);

            IEnumerable <MatchedResults> matchedResults = matcher.Match(new ExtractedResult[] { resultA }, new ExtractedResult[] { resultB });

            matchedResults.Should().HaveCount(1);
            matchedResults.First().PreviousResult.Should().BeEquivalentTo(resultA);
            matchedResults.First().CurrentResult.Should().BeEquivalentTo(resultB);
        }
        public void IdenticalResultMatcher_MatchesResults_DifferingOnResultMatchingProperties_Multiple()
        {
            ExtractedResult resultAA = new ExtractedResult()
            {
                Result = ResultMatchingTestHelpers.CreateMatchingResult("file://test", "file://test2", "test context")
            };

            Result changedResultA = resultAA.Result.DeepClone();

            changedResultA.CorrelationGuid = Guid.NewGuid().ToString();
            changedResultA.BaselineState   = BaselineState.Unchanged;
            changedResultA.SetProperty(SarifLogResultMatcher.ResultMatchingResultPropertyName, new Dictionary <string, string> {
                { "property", "value" }
            });

            ExtractedResult resultBA = new ExtractedResult()
            {
                Result = changedResultA
            };

            ExtractedResult resultAB = new ExtractedResult()
            {
                Result = ResultMatchingTestHelpers.CreateMatchingResult("file://test", "file://test2", "test context2")
            };

            Result changedResultB = resultAB.Result.DeepClone();

            changedResultA.CorrelationGuid = Guid.NewGuid().ToString();
            changedResultA.BaselineState   = BaselineState.New;

            changedResultB.SetProperty(SarifLogResultMatcher.ResultMatchingResultPropertyName, new Dictionary <string, string> {
                { "property1", "value1" }
            });
            ExtractedResult resultBB = new ExtractedResult()
            {
                Result = changedResultB
            };


            IEnumerable <MatchedResults> matchedResults = matcher.Match(new ExtractedResult[] { resultAA, resultAB }, new ExtractedResult[] { resultBA, resultBB });

            matchedResults.Should().HaveCount(2);
            matchedResults.Where(f => f.PreviousResult == resultAA && f.CurrentResult == resultBA).Should().HaveCount(1);
            matchedResults.Where(f => f.PreviousResult == resultAB && f.CurrentResult == resultBB).Should().HaveCount(1);
        }