public void GetRepositoryRoot_WhenCachingIsDisabled_DoesNotPopulateTheDirectoryToRepoRootCache() { var mockFileSystem = new Mock <IFileSystem>(); mockFileSystem.Setup(x => x.DirectoryExists(It.IsAny <string>())).Returns(false); mockFileSystem.Setup(x => x.DirectoryExists(@"C:\dev\sarif-sdk")).Returns(true); mockFileSystem.Setup(x => x.DirectoryExists(@"C:\dev\sarif-sdk\.git")).Returns(true); mockFileSystem.Setup(x => x.DirectoryExists(@"C:\dev\sarif-sdk\src")).Returns(true); mockFileSystem.Setup(x => x.DirectoryExists(@"C:\dev\sarif-sdk\src\Sarif")).Returns(true); mockFileSystem.Setup(x => x.DirectoryExists(@"C:\")).Returns(true); mockFileSystem.Setup(x => x.DirectoryExists(@"C:\docs")).Returns(true); mockFileSystem.Setup(x => x.DirectoryExists(@"C:\docs\public")).Returns(true); var gitHelper = new GitHelper(mockFileSystem.Object); // Verify that the API returns the correct results whether or not the cache is in use. string topLevelDirectoryRoot = gitHelper.GetRepositoryRoot(@"C:\dev\sarif-sdk", useCache: false); string topLevelDirectoryRootAgain = gitHelper.GetRepositoryRoot(@"C:\dev\sarif-sdk", useCache: false); string subdirectoryRoot = gitHelper.GetRepositoryRoot(@"C:\dev\sarif-sdk\src\Sarif", useCache: false); string nonSourceControlledRoot = gitHelper.GetRepositoryRoot(@"C:\docs\public", useCache: false); gitHelper.directoryToRepoRootPathDictionary.Count.Should().Be(0); }
public void GetRepositoryRoot_WhenDotGitIsPresent_ReturnsTheDirectortyContainingDotGit() { string productDirectory = Path.GetDirectoryName(FileDiffingUnitTests.GetProductDirectory()); string repoDirectory = Directory.GetParent(productDirectory).FullName; var gitHelper = new GitHelper(); gitHelper.GetRepositoryRoot(productDirectory).Should().BeEquivalentTo(repoDirectory); }
public void GitExePath_WhenPathDoesNotExist_SettingManuallyShouldWork() { var mockFileSystem = new Mock <IFileSystem>(); mockFileSystem.Setup(x => x.FileExists(It.IsAny <string>())).Returns(false); var gitHelper = new GitHelper(mockFileSystem.Object); gitHelper.GitExePath = @"C:\dev"; gitHelper.GitExePath.Should().Be(@"C:\dev"); }
public void GetGitExePath_WhenPathDoesNotExistInProgramFiles() { var mockFileSystem = new Mock <IFileSystem>(); mockFileSystem.Setup(x => x.FileExists(It.IsAny <string>())).Returns(false); var gitHelper = new GitHelper(mockFileSystem.Object); gitHelper.GitExePath.Should().BeNull(); GitHelper.GetGitExePath(mockFileSystem.Object).Should().BeNull(); }
public void GetTopLevel_WhenGitDoesnotExist() { var mockFileSystem = new Mock <IFileSystem>(); mockFileSystem.Setup(x => x.DirectoryExists(It.IsAny <string>())).Returns(false); mockFileSystem.Setup(x => x.DirectoryExists(@"C:\dev\sarif-sdk\src\Sarif")).Returns(true); var gitHelper = new GitHelper(mockFileSystem.Object); gitHelper.GetTopLevel(@"C:\dev\sarif-sdk\src\Sarif").Should().BeNull(); }
public void GetRepositoryRoot_WhenDotGitIsPresent_ReturnsTheDirectortyContainingDotGit() { var mockFileSystem = new Mock <IFileSystem>(); mockFileSystem.Setup(x => x.DirectoryExists(It.IsAny <string>())).Returns(false); mockFileSystem.Setup(x => x.DirectoryExists(@"C:\dev\sarif-sdk")).Returns(true); mockFileSystem.Setup(x => x.DirectoryExists(@"C:\dev\sarif-sdk\.git")).Returns(true); mockFileSystem.Setup(x => x.DirectoryExists(@"C:\dev\sarif-sdk\src")).Returns(true); mockFileSystem.Setup(x => x.DirectoryExists(@"C:\dev\sarif-sdk\src\Sarif")).Returns(true); var gitHelper = new GitHelper(mockFileSystem.Object); gitHelper.GetRepositoryRoot(@"C:\dev\sarif-sdk\src\Sarif").Should().Be(@"C:\dev\sarif-sdk\"); }
public void GetRepositoryRoot_ByDefault_PopulatesTheDirectoryToRepoRootCache() { // Returns '\src\' location within repo, e.g., 'c:\src\sarif-sdk\src' string productDirectory = Path.GetDirectoryName(FileDiffingUnitTests.GetProductDirectory()); string repoDirectory = Directory.GetParent(productDirectory).FullName; var gitHelper = new GitHelper(); gitHelper.GetRepositoryRoot(repoDirectory).Should().BeEquivalentTo(repoDirectory); gitHelper.GetRepositoryRoot(productDirectory).Should().BeEquivalentTo(repoDirectory); // Verify that the API returns the correct results whether or not the cache is in use. gitHelper.GetRepositoryRoot(repoDirectory).Should().BeEquivalentTo(repoDirectory); gitHelper.GetRepositoryRoot(productDirectory).Should().BeEquivalentTo(repoDirectory); gitHelper.directoryToRepoRootPathDictionary.Count.Should().Be(2); gitHelper.directoryToRepoRootPathDictionary[repoDirectory].Should().BeEquivalentTo(repoDirectory); gitHelper.directoryToRepoRootPathDictionary[productDirectory].Should().BeEquivalentTo(repoDirectory); }