public void GetAllPathsMoreThanXAndLessThanYCharacters() { // Get a length that doesn't include all paths, and then get the list of paths that should match the length condition. int minPathLength = _filesFixture.AllPaths.Min(p => p.Length) + 1; int maxPathLength = _filesFixture.AllPaths.Max(p => p.Length) - 1; var expectedPaths = _filesFixture.AllPaths.Where(p => p.Length >= minPathLength && p.Length <= maxPathLength); // Setup the Search Options var searchOptions = new PathLengthSearchOptions() { RootDirectory = _filesFixture.RootPath, SearchOption = SearchOption.AllDirectories, TypesToGet = FileSystemTypes.All, SearchPattern = string.Empty, RootDirectoryReplacement = null, MinimumPathLength = minPathLength, MaximumPathLength = maxPathLength }; // Because we try and get a list of paths. var paths = PathLengthChecker.GetPathsWithLengths(searchOptions, CancellationToken.None); // We should have all of the paths. paths.Should().Contain(expectedPaths); // And we should not have any extra paths. paths.Should().OnlyContain(p => expectedPaths.Contains(p)); }
public void MinimumPathLengthGreaterThanMaximumPathLengthSoShouldThrowException() { // Setup the Search Options var searchOptions = new PathLengthSearchOptions() { RootDirectory = _filesFixture.RootPath, SearchOption = SearchOption.AllDirectories, TypesToGet = FileSystemTypes.All, SearchPattern = string.Empty, RootDirectoryReplacement = null, MinimumPathLength = 2, MaximumPathLength = 1 }; // Because we try and get a list of paths from a directory that does not exist. Action act = () => PathLengthChecker.GetPathsWithLengths(searchOptions, CancellationToken.None).Count(); // A DirectoryNotFound exception should be thrown. act.Should().Throw <MinPathLengthGreaterThanMaxPathLengthException>(); }
public void GetAllFilesFromEmptyDirectory() { // Setup the Search Options var searchOptions = new PathLengthSearchOptions() { RootDirectory = _filesFixture.EmptyDirectoryPath, SearchOption = SearchOption.AllDirectories, TypesToGet = FileSystemTypes.All, SearchPattern = string.Empty, RootDirectoryReplacement = null, MinimumPathLength = -1, MaximumPathLength = -1 }; // Because we try and get a list of paths from an empty directory. var paths = PathLengthChecker.GetPathsWithLengths(searchOptions, CancellationToken.None); // There shouldn't be any paths found. paths.Should().HaveCount(0); }
public void InvalidDirectorySoShouldThrowException() { // Setup the Search Options var searchOptions = new PathLengthSearchOptions() { RootDirectory = Path.Combine(RootPath, "ADirectoryThatDoesNotExist"), SearchOption = SearchOption.AllDirectories, TypesToGet = FileSystemTypes.All, SearchPattern = string.Empty, RootDirectoryReplacement = null, MinimumPathLength = -1, MaximumPathLength = -1 }; // Because we try and get a list of paths from a directory that does not exist. Action act = () => PathLengthChecker.GetPathsWithLengths(searchOptions).Count(); // A DirectoryNotFound exception should be thrown. act.ShouldThrow <DirectoryNotFoundException>(); }
public void ReplacingTheStartingDirectoryAndUsingUrlEncodingShouldAlterThePathsProperly() { // Setup the Search Options var newRootDirectoryName = "NewRootDirectory"; var searchOptions = new PathLengthSearchOptions() { RootDirectory = _filesFixture.RootPath, SearchOption = SearchOption.AllDirectories, TypesToGet = FileSystemTypes.All, SearchPattern = string.Empty, RootDirectoryReplacement = newRootDirectoryName, MinimumPathLength = -1, MaximumPathLength = -1, UrlEncodePaths = true }; var expectedPaths = _filesFixture.AllPaths.Select(p => { return(new PathInfo() { Path = p.Path.Replace(_filesFixture.RootPath, newRootDirectoryName) .Replace(" ", "%20") .Replace(@"\", "%5C") .Replace(":", "%3A") }); }); // Act. var paths = PathLengthChecker.GetPathsWithLengths(searchOptions, CancellationToken.None); // We should not have any of the original paths. paths.Should().NotContain(_filesFixture.AllPaths); // We should have the expected transformed paths. paths.Should().Contain(expectedPaths); // And we should not have any extra paths. paths.Should().OnlyContain(p => expectedPaths.Contains(p)); }
public void GetAllFilesInTopLevelDirectory() { // Setup the Search Options var searchOptions = new PathLengthSearchOptions() { RootDirectory = _filesFixture.RootPath, SearchOption = SearchOption.TopDirectoryOnly, TypesToGet = FileSystemTypes.Files, SearchPattern = string.Empty, RootDirectoryReplacement = null, MinimumPathLength = -1, MaximumPathLength = -1 }; // Because we try and get a list of paths. var paths = PathLengthChecker.GetPathsWithLengths(searchOptions, CancellationToken.None); // We should have all of the file paths directly off of the Root Path. paths.Should().Contain(p => string.Equals(Path.GetDirectoryName(p.Path), _filesFixture.RootPath)); // And we should not have any extra paths. paths.Should().OnlyContain(p => string.Equals(Path.GetDirectoryName(p.Path), _filesFixture.RootPath)); }
public void GetAllDirectories() { // Setup the Search Options var searchOptions = new PathLengthSearchOptions() { RootDirectory = _filesFixture.RootPath, SearchOption = SearchOption.AllDirectories, TypesToGet = FileSystemTypes.Directories, SearchPattern = string.Empty, RootDirectoryReplacement = null, MinimumPathLength = -1, MaximumPathLength = -1 }; // Because we try and get a list of directory paths. var paths = PathLengthChecker.GetPathsWithLengths(searchOptions, CancellationToken.None); // We should have all of the directory paths. paths.Should().Contain(_filesFixture.Directories); // And we should not have any extra paths. paths.Should().OnlyContain(p => _filesFixture.Directories.Contains(p)); }