Hi Hugh,
Thanks for posting!
Unfortunately there isn't any feature in NCrunch you can use to force a project to rebuild before an individual test is run. Pre/post build events also unfortunately won't work in this situation, as they still require the repeat execution of a build step.
I would, however, consider taking a good look at what this test is doing and perhaps look at ways it could be redesigned.
When creating tests, it's important that they execute without side-effects such as this, as otherwise the results of the test can become very difficult to consistently interpret and the test can be very difficult to maintain/execute.
Is it possible to modify the test to introduce an additional file copy step before the rest of the test executes? You could copy the file to a temporary location, then allow the test to move it as part of its normal behaviour. The initial copy step would allow the test to become repeatable as it does not modify the original file.
It's probably worth looking at cleaning up the moved file at the end of the test run, to keep things tidy. A great pattern when working with tests of this nature is to operate within a temporary directory, for example:
using System.IO;
using NUnit.Framework;
public class Fixture
{
private string _originalDir;
private string _tempDir;
[SetUp]
public void SetUp()
{
_originalDir = Directory.GetCurrentDirectory();
_tempDir = Path.GetRandomFileName();
Directory.CreateDirectory(_tempDir);
Directory.SetCurrentDirectory(_tempDir);
}
[Test]
public void Test()
{
// Place test code here
}
[TearDown]
public void TearDown()
{
Directory.SetCurrentDirectory(_originalDir);
Directory.Delete(_tempDir, true);
}
}