Skip to content

Commit

Permalink
Fixing source watcher disposal checking spec, was not a real test before
Browse files Browse the repository at this point in the history
  • Loading branch information
codereflection committed Nov 6, 2011
1 parent 0f2d771 commit ba7a285
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 18 deletions.
16 changes: 3 additions & 13 deletions src/Giles.Core/Watchers/SourceWatcher.cs
Expand Up @@ -20,6 +20,7 @@ public class SourceWatcher : IDisposable
readonly GilesConfig config;
readonly ITestRunner testRunner;

public List<FileSystemWatcher> FileWatchers { get; set; }

public SourceWatcher(IBuildRunner buildRunner, ITestRunner testRunner, IFileSystem fileSystem,
IFileWatcherFactory fileWatcherFactory, GilesConfig config)
Expand All @@ -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<FileSystemWatcher> 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);
Expand Down
20 changes: 20 additions & 0 deletions 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; }
}
}
8 changes: 4 additions & 4 deletions 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;

Expand All @@ -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;
Expand All @@ -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";
Expand Down Expand Up @@ -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();
}
}
3 changes: 3 additions & 0 deletions src/Giles.Specs/Giles.Specs.csproj
Expand Up @@ -57,6 +57,9 @@
</Compile>
<Compile Include="Core\Configuration\TestAssemblyFinderSpecs.cs" />
<Compile Include="Core\Runners\GilesTestListenerSpecs.cs" />
<Compile Include="Core\Utility\FakeFileSystemWatcher.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="TestResources.cs" />
<Compile Include="Core\Configuration\GilesConfigFactorySpecs.cs" />
<Compile Include="Core\Configuration\MsBuildProjectSpecs.cs" />
Expand Down
2 changes: 1 addition & 1 deletion src/Specs/Support/ClassLibraryWithTests/SpiderManTests.cs
Expand Up @@ -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();

Expand Down

0 comments on commit ba7a285

Please sign in to comment.