From ba7a28561baeff4b4ad9db55fe6ce37ca5fdb9ee Mon Sep 17 00:00:00 2001 From: codereflection Date: Sat, 5 Nov 2011 22:48:41 -0700 Subject: [PATCH] Fixing source watcher disposal checking spec, was not a real test before --- src/Giles.Core/Watchers/SourceWatcher.cs | 16 +++------------ .../Core/Utility/FakeFileSystemWatcher.cs | 20 +++++++++++++++++++ .../Core/Watchers/SourceWatcherSpecs.cs | 8 ++++---- src/Giles.Specs/Giles.Specs.csproj | 3 +++ .../ClassLibraryWithTests/SpiderManTests.cs | 2 +- 5 files changed, 31 insertions(+), 18 deletions(-) create mode 100644 src/Giles.Specs/Core/Utility/FakeFileSystemWatcher.cs diff --git a/src/Giles.Core/Watchers/SourceWatcher.cs b/src/Giles.Core/Watchers/SourceWatcher.cs index 6fa1f7b..52278ea 100644 --- a/src/Giles.Core/Watchers/SourceWatcher.cs +++ b/src/Giles.Core/Watchers/SourceWatcher.cs @@ -20,6 +20,7 @@ public class SourceWatcher : IDisposable readonly GilesConfig config; readonly ITestRunner testRunner; + public List FileWatchers { get; set; } public SourceWatcher(IBuildRunner buildRunner, ITestRunner testRunner, IFileSystem fileSystem, IFileWatcherFactory fileWatcherFactory, GilesConfig config) @@ -32,34 +33,23 @@ public class SourceWatcher : IDisposable this.testRunner = testRunner; buildTimer = new Timer { AutoReset = false, Enabled = false, Interval = config.BuildDelay }; config.PropertyChanged += config_PropertyChanged; - buildTimer.Elapsed += buildTimer_Elapsed; + buildTimer.Elapsed += (sender, e) => RunNow(); } void config_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName != "BuildDelay") return; - var buildDelay = (sender as GilesConfig).BuildDelay; + var buildDelay = ((GilesConfig) sender).BuildDelay; buildTimer.Interval = buildDelay; } - public List FileWatchers { get; set; } - - #region IDisposable Members - public void Dispose() { FileWatchers.ToList().ForEach(x => x.Dispose()); } - #endregion - - void buildTimer_Elapsed(object sender, ElapsedEventArgs e) - { - RunNow(); - } - public void Watch(string solutionPath, string filter) { var solutionFolder = fileSystem.GetDirectoryName(solutionPath); diff --git a/src/Giles.Specs/Core/Utility/FakeFileSystemWatcher.cs b/src/Giles.Specs/Core/Utility/FakeFileSystemWatcher.cs new file mode 100644 index 0000000..cd9b192 --- /dev/null +++ b/src/Giles.Specs/Core/Utility/FakeFileSystemWatcher.cs @@ -0,0 +1,20 @@ +using System.IO; + +namespace Giles.Specs.Core.Utility +{ + public class FakeFileSystemWatcher : FileSystemWatcher + { + public FakeFileSystemWatcher(string s) + : base(s) + { } + + protected override void Dispose(bool disposing) + { + WasDisposed = true; + + base.Dispose(disposing); + } + + public bool WasDisposed { get; set; } + } +} \ No newline at end of file diff --git a/src/Giles.Specs/Core/Watchers/SourceWatcherSpecs.cs b/src/Giles.Specs/Core/Watchers/SourceWatcherSpecs.cs index 03b6bc1..75997ee 100644 --- a/src/Giles.Specs/Core/Watchers/SourceWatcherSpecs.cs +++ b/src/Giles.Specs/Core/Watchers/SourceWatcherSpecs.cs @@ -1,10 +1,10 @@ using System.IO; -using System.Linq; using System.Threading; using Giles.Core.Configuration; using Giles.Core.IO; using Giles.Core.Runners; using Giles.Core.Watchers; +using Giles.Specs.Core.Utility; using Machine.Specifications; using NSubstitute; @@ -17,7 +17,7 @@ public class with_a_source_watcher protected static string path; protected static string filter; protected static IBuildRunner buildRunner; - protected static FileSystemWatcher fileSystemWatcher; + protected static FakeFileSystemWatcher fileSystemWatcher; protected static IFileWatcherFactory fileWatcherFactory; protected static string solutionfolder; protected static ITestRunner testRunner; @@ -40,7 +40,7 @@ public class with_a_source_watcher filter = "*.cs"; fileSystem.FileExists(path).Returns(false); - fileSystemWatcher = new FileSystemWatcher("."); + fileSystemWatcher = new FakeFileSystemWatcher("."); fileWatcherFactory.Build(path, filter, null, null, null).ReturnsForAnyArgs(fileSystemWatcher); solutionfolder = @"c:\solutionFolder"; @@ -96,6 +96,6 @@ public class when_disposing : with_a_source_watcher watcher.Dispose(); It should_call_dispose_on_each_file_watcher = () => - watcher.FileWatchers.All(x => x == null); + fileSystemWatcher.WasDisposed.ShouldBeTrue(); } } \ No newline at end of file diff --git a/src/Giles.Specs/Giles.Specs.csproj b/src/Giles.Specs/Giles.Specs.csproj index 7a091ce..bd0f227 100644 --- a/src/Giles.Specs/Giles.Specs.csproj +++ b/src/Giles.Specs/Giles.Specs.csproj @@ -57,6 +57,9 @@ + + Component + diff --git a/src/Specs/Support/ClassLibraryWithTests/SpiderManTests.cs b/src/Specs/Support/ClassLibraryWithTests/SpiderManTests.cs index 5f29966..5bb172f 100644 --- a/src/Specs/Support/ClassLibraryWithTests/SpiderManTests.cs +++ b/src/Specs/Support/ClassLibraryWithTests/SpiderManTests.cs @@ -5,7 +5,7 @@ namespace ClassLibraryWithTests public class SpiderManTests { [Test] - public void SpiderMan_should_know_his_own_catch_phrase() + public void SpiderMan_should_know_his_own_catch_phrase_from_the_app_config() { var spidey = new SpiderMan();