diff --git a/src/Giles.Core/Watchers/SourceWatcher.cs b/src/Giles.Core/Watchers/SourceWatcher.cs index 6fa1f7b..ef3aefc 100644 --- a/src/Giles.Core/Watchers/SourceWatcher.cs +++ b/src/Giles.Core/Watchers/SourceWatcher.cs @@ -62,9 +62,9 @@ void buildTimer_Elapsed(object sender, ElapsedEventArgs e) public void Watch(string solutionPath, string filter) { - var solutionFolder = fileSystem.GetDirectoryName(solutionPath); - var fileSystemWatcher = fileWatcherFactory.Build(solutionFolder, filter, ChangeAction, null, - ErrorAction); + string solutionFolder = GetSolutionFolder(solutionPath); + var fileSystemWatcher = fileWatcherFactory.Build(solutionFolder, + filter, ChangeAction, null, ErrorAction); fileSystemWatcher.EnableRaisingEvents = true; fileSystemWatcher.NotifyFilter = NotifyFilters.LastWrite; fileSystemWatcher.IncludeSubdirectories = true; @@ -72,6 +72,15 @@ public void Watch(string solutionPath, string filter) 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) { throw new NotImplementedException(); diff --git a/src/Giles.Specs/Core/Watchers/SourceWatcherSpecs.cs b/src/Giles.Specs/Core/Watchers/SourceWatcherSpecs.cs index 03b6bc1..df5486e 100644 --- a/src/Giles.Specs/Core/Watchers/SourceWatcherSpecs.cs +++ b/src/Giles.Specs/Core/Watchers/SourceWatcherSpecs.cs @@ -67,6 +67,20 @@ public class when_starting_to_watch_files : with_a_source_watcher 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())); + }; + + Because of = () => + watcher.Watch(path, filter); + + It watch_files_in_the_current_directory = () => + fileWatcherFactory.Received().Build(@".\", filter, Arg.Any(), Arg.Any(), Arg.Any()); + } + public class when_a_file_has_changed : with_a_source_watcher { @@ -98,4 +112,4 @@ public class when_disposing : with_a_source_watcher It should_call_dispose_on_each_file_watcher = () => watcher.FileWatchers.All(x => x == null); } -} \ No newline at end of file +}