Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

test cleanup

  • Loading branch information...
commit 0a856a3dccb698890c72357911b8d0f42da3134b 1 parent f88478b
Lucas Meijer authored
View
12 Tests/DependencyGraphTests.cs
@@ -1,4 +1,5 @@
-using System.IO;
+using System;
+using System.IO;
using NUnit.Framework;
namespace bs.Tests
@@ -15,9 +16,18 @@ public void Setup()
Directory.CreateDirectory(dirName);
Directory.SetCurrentDirectory(dirName);
+
+ _depGraph = new DependencyGraph();
}
protected const string defaultSourceFile = "input.txt";
protected const string defaulttargetFile = "output.txt";
+
+ protected DependencyGraph _depGraph;
+
+ protected void ThrowIfDepgraphGenerates()
+ {
+ _depGraph.GenerateCallback += (target, instructions) => { throw new InvalidOperationException(); };
+ }
}
}
View
43 Tests/SimpleCopyDepGraph.cs
@@ -12,35 +12,46 @@ class SimpleCopyDepGraph : DependencyGraphTests
[Test]
public void ThrowsIfDependencyDoesNotExist()
{
- DependencyGraph depGraph = SetupSimpleCopyDepGraph();
- Assert.Throws<MissingDependencyException>(() => depGraph.RequestTarget(defaulttargetFile));
+ SetupSimpleCopyDepGraph();
+ Assert.Throws<MissingDependencyException>(() => _depGraph.RequestTarget(defaulttargetFile));
}
[Test]
public void RegeneratesWhenSourceChanges()
{
- DependencyGraph depGraph = SetupSimpleCopyDepGraph();
- Assert.Throws<MissingDependencyException>(() => depGraph.RequestTarget(defaulttargetFile));
-
- File.WriteAllText(defaultSourceFile, "One");
- depGraph.RequestTarget(defaulttargetFile);
- FileAssert.Contains(defaulttargetFile, "One");
-
- File.WriteAllText(defaultSourceFile, "Two");
- depGraph.RequestTarget(defaulttargetFile);
- FileAssert.Contains(defaulttargetFile, "Two");
+ SetupSimpleCopyDepGraph();
+ Assert.Throws<MissingDependencyException>(() => _depGraph.RequestTarget(defaulttargetFile));
+
+ WriteToSourceRunDepGraphAndVerifyTarget("One");
+ WriteToSourceRunDepGraphAndVerifyTarget("Two");
}
- private static DependencyGraph SetupSimpleCopyDepGraph()
+ private void WriteToSourceRunDepGraphAndVerifyTarget(string contents)
+ {
+ File.WriteAllText(defaultSourceFile, contents);
+ _depGraph.RequestTarget(defaulttargetFile);
+ FileAssert.Contains(defaulttargetFile, contents);
+ }
+
+ [Test]
+ public void WillNotRegeneratesWhenSourceDidNotChange()
{
- var depGraph = new DependencyGraph();
+ SetupSimpleCopyDepGraph();
+ Assert.Throws<MissingDependencyException>(() => _depGraph.RequestTarget(defaulttargetFile));
- depGraph.RegisterTarget(defaulttargetFile, new TargetBuildInstructions()
+ WriteToSourceRunDepGraphAndVerifyTarget("One");
+
+ ThrowIfDepgraphGenerates();
+ _depGraph.RequestTarget(defaulttargetFile);
+ }
+
+ private void SetupSimpleCopyDepGraph()
+ {
+ _depGraph.RegisterTarget(defaulttargetFile, new TargetBuildInstructions()
{
Action = (target,sources) => File.Copy(sources.Single(), target, true),
SourceFiles = new[] { defaultSourceFile }
});
- return depGraph;
}
}
}
View
2  Tests/TargetWithoutSources.cs
@@ -25,7 +25,7 @@ public void WontGenerateTargetWithoutSourcesTwice()
depGraph.RequestTarget(defaulttargetFile);
FileAssert.Contains(defaulttargetFile, "Hello");
- depGraph.GenerateCallback += (target, instructions) => { throw new InvalidOperationException(); };
+ ThrowIfDepgraphGenerates();
depGraph.RequestTarget(defaulttargetFile);
}
Please sign in to comment.
Something went wrong with that request. Please try again.