public void CodeAnalysisResultManager_GetRebaselinedFileName_AcceptsMatchingFileNameFromUser()
        {
            // Arrange.
            const string PathInLogFile        = @"C:\Code\sarif-sdk\src\Sarif\Notes.cs";
            const string ExpectedResolvedPath = @"D:\Users\John\source\sarif-sdk\src\Sarif\Notes.cs";

            const int RunId = 1;

            this.pathFromPrompt = ExpectedResolvedPath;

            var target = new CodeAnalysisResultManager(
                null,                               // This test never touches the file system.
                this.FakePromptForResolvedPath);
            var dataCache = new RunDataCache();

            target.RunIndexToRunDataCache.Add(RunId, dataCache);

            // Act.
            string actualResolvedPath = target.GetRebaselinedFileName(uriBaseId: null, pathFromLogFile: PathInLogFile, dataCache: dataCache);

            actualResolvedPath = this.FakePromptForResolvedPath(null, actualResolvedPath);
            target.SaveResolvedPathToUriBaseMapping(null, PathInLogFile, PathInLogFile, actualResolvedPath, dataCache);
            // Assert.
            actualResolvedPath.Should().Be(ExpectedResolvedPath);

            Tuple <string, string>[] remappedPathPrefixes = target.GetRemappedPathPrefixes();
            remappedPathPrefixes.Length.Should().Be(1);
            remappedPathPrefixes[0].Item1.Should().Be(@"C:\Code");
            remappedPathPrefixes[0].Item2.Should().Be(@"D:\Users\John\source");
        }
        public void CodeAnalysisResultManager_GetRebaselinedFileName_ConstructPathFromSolutionPathRemapping()
        {
            const int    RunId = 1;
            const string ResultArtifactPath1   = @"Sarif/Notes.cs";
            const string ResultArtifactPath2   = @"Sarif/OffsetInfo.cs";
            const string SolutionPath          = @"D:\Users\John\source\sarif-sdk\src";
            string       ExpectedResolvedPath1 = Path.Combine(SolutionPath, "Sarif", "Notes.cs");
            string       ExpectedResolvedPath2 = Path.Combine(SolutionPath, "Sarif", "OffsetInfo.cs");

            this.existingFiles.Add(ExpectedResolvedPath1);
            this.existingFiles.Add(ExpectedResolvedPath2);

            var target = new CodeAnalysisResultManager(
                fileSystem: this.mockFileSystem.Object,
                this.FakePromptForResolvedPath);
            var dataCache = new RunDataCache();

            target.RunIndexToRunDataCache.Add(RunId, dataCache);

            // Mimic first time user navigate to a result, resolve file path using solution path.
            // The resolved path should be cached for next resolving
            target.SaveResolvedPathToUriBaseMapping(null, ResultArtifactPath1, ResultArtifactPath1, ExpectedResolvedPath1, dataCache);
            Tuple <string, string>[] remappedPathPrefixes = target.GetRemappedPathPrefixes();
            remappedPathPrefixes.Length.Should().Be(1);
            remappedPathPrefixes[0].Item1.Should().Be("");
            remappedPathPrefixes[0].Item2.Should().Be(SolutionPath);

            string actualResolvedPath = target.GetRebaselinedFileName(
                uriBaseId: null,
                pathFromLogFile: ResultArtifactPath2,
                dataCache: dataCache);

            actualResolvedPath.Should().Be(ExpectedResolvedPath2);
        }
        public void CodeAnalysisResultManager_GetRebaselinedFileName_UsesExistingMapping()
        {
            // Arrange.
            const string FirstFileNameInLogFile   = @"C:\Code\sarif-sdk\src\Sarif\Notes.cs";
            const string FirstRebaselinedFileName = @"D:\Users\John\source\sarif-sdk\src\Sarif\Notes.cs";

            const string SecondFileNameInLogFile   = @"C:\Code\sarif-sdk\src\Sarif.UnitTests\JsonTests.cs";
            const string SecondRebaselinedFileName = @"D:\Users\John\source\sarif-sdk\src\Sarif.UnitTests\JsonTests.cs";

            const int RunId = 1;

            this.existingFiles.Add(SecondRebaselinedFileName);

            this.pathFromPrompt = FirstRebaselinedFileName;

            var target = new CodeAnalysisResultManager(
                this.fileSystem,
                this.FakePromptForResolvedPath);
            var dataCache = new RunDataCache();

            target.RunIndexToRunDataCache.Add(RunId, dataCache);

            // First, rebase a file to prime the list of mappings.
            target.GetRebaselinedFileName(uriBaseId: null, pathFromLogFile: FirstFileNameInLogFile, dataCache: dataCache);
            string actualResolvedPath = this.FakePromptForResolvedPath(null, FirstFileNameInLogFile);

            target.SaveResolvedPathToUriBaseMapping(null, FirstFileNameInLogFile, FirstFileNameInLogFile, actualResolvedPath, dataCache);
            // The first time, we prompt the user for the name of the file to rebaseline to.
            this.numPrompts.Should().Be(1);

            // Act: Rebaseline a second file with the same prefix.
            actualResolvedPath = target.GetRebaselinedFileName(uriBaseId: null, pathFromLogFile: SecondFileNameInLogFile, dataCache: dataCache);

            // Assert.
            actualResolvedPath.Should().Be(SecondRebaselinedFileName);

            Tuple <string, string>[] remappedPathPrefixes = target.GetRemappedPathPrefixes();
            remappedPathPrefixes.Length.Should().Be(1);
            remappedPathPrefixes[0].Item1.Should().Be(@"C:\Code");
            remappedPathPrefixes[0].Item2.Should().Be(@"D:\Users\John\source");

            // The second time, since the existing mapping suffices for the second file,
            // it's not necessary to prompt again.
            this.numPrompts.Should().Be(1);
        }