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

Support solution path which is simply a filename. #7

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/Giles.Core/Watchers/SourceWatcher.cs
Expand Up @@ -62,16 +62,25 @@ void buildTimer_Elapsed(object sender, ElapsedEventArgs e)


public void Watch(string solutionPath, string filter) public void Watch(string solutionPath, string filter)
{ {
var solutionFolder = fileSystem.GetDirectoryName(solutionPath); string solutionFolder = GetSolutionFolder(solutionPath);
var fileSystemWatcher = fileWatcherFactory.Build(solutionFolder, filter, ChangeAction, null, var fileSystemWatcher = fileWatcherFactory.Build(solutionFolder,
ErrorAction); filter, ChangeAction, null, ErrorAction);
fileSystemWatcher.EnableRaisingEvents = true; fileSystemWatcher.EnableRaisingEvents = true;
fileSystemWatcher.NotifyFilter = NotifyFilters.LastWrite; fileSystemWatcher.NotifyFilter = NotifyFilters.LastWrite;
fileSystemWatcher.IncludeSubdirectories = true; fileSystemWatcher.IncludeSubdirectories = true;


FileWatchers.Add(fileSystemWatcher); FileWatchers.Add(fileSystemWatcher);
} }


private string GetSolutionFolder(string solutionPath)
{
var solutionFolder = fileSystem.GetDirectoryName(solutionPath);
// handle relative solution path that was only a filename
if (solutionFolder == string.Empty)
solutionFolder = "." + Path.DirectorySeparatorChar;
return solutionFolder;
}

public void ErrorAction(object sender, ErrorEventArgs e) public void ErrorAction(object sender, ErrorEventArgs e)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
Expand Down
16 changes: 15 additions & 1 deletion src/Giles.Specs/Core/Watchers/SourceWatcherSpecs.cs
Expand Up @@ -67,6 +67,20 @@ public class when_starting_to_watch_files : with_a_source_watcher
fileSystem.Received().GetDirectoryName(path); fileSystem.Received().GetDirectoryName(path);
} }


public class when_the_solution_path_is_a_relative_filename : with_a_source_watcher
{
Establish context = () => {
path = "mySolution.sln";
fileSystem.GetDirectoryName(path).ReturnsForAnyArgs(info => Path.GetDirectoryName(info.Arg<string>()));
};

Because of = () =>
watcher.Watch(path, filter);

It watch_files_in_the_current_directory = () =>
fileWatcherFactory.Received().Build(@".\", filter, Arg.Any<FileSystemEventHandler>(), Arg.Any<FileSystemEventHandler>(), Arg.Any<ErrorEventHandler>());
}



public class when_a_file_has_changed : with_a_source_watcher public class when_a_file_has_changed : with_a_source_watcher
{ {
Expand Down Expand Up @@ -98,4 +112,4 @@ public class when_disposing : with_a_source_watcher
It should_call_dispose_on_each_file_watcher = () => It should_call_dispose_on_each_file_watcher = () =>
watcher.FileWatchers.All(x => x == null); watcher.FileWatchers.All(x => x == null);
} }
} }