Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #1 - Tasks using Pattern matching for finding files now throw a… #2

Merged
merged 1 commit into from
Jun 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Frends.File.Tests/UnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,20 @@ public void FindFiles()
Assert.That(results.All(x => x.Extension.Equals(".xml")));
}

[Test]
public void FindFilesShouldThrowIfFolderNotExist()
{
var ex = Assert.Throws<Exception>(() => File.Find(
new FindInput()
{
Directory = "DoesNotExist",
Pattern = "**.*"
},
new FindOption()));

Assert.That(ex.Message, Does.Contain("Directory does not exist or you do not have read access"));
}

[Test]
public async Task WriteFileAppend()
{
Expand Down
7 changes: 7 additions & 0 deletions Frends.File/File.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ private static TResult ExecuteAction<TResult>(Func<TResult> action, bool useGive

internal static PatternMatchingResult FindMatchingFiles(string directoryPath, string pattern)
{
// Check the user can access the folder
// This will return false if the path does not exist or you do not have read permissions.
if (!Directory.Exists(directoryPath))
{
throw new Exception($"Directory does not exist or you do not have read access. Tried to access directory '{directoryPath}'");
}

var matcher = new Matcher();
matcher.AddInclude(pattern);
var results = matcher.Execute(new DirectoryInfoWrapper(new DirectoryInfo(directoryPath)));
Expand Down