System.UnauthorizedAccessException : Access to the path 'C:\...\Local\Temp\bqrcregv.eww' is denied
<p>I've got a C# access exception problem. Here is my integration test:</p>

<pre><code>[TestFixture]
public class DirectoryTraverserTest
{
    private string testDirectory;

    [SetUp]
    public void Setup()
    {
        testDirectory = CreateTempDirectory();

        var files = new[] { "file1","file2","file3","file4"};
        CreateFiles(testDirectory, files);


        System.Console.WriteLine(testDirectory);
    }

    [TearDown]
    public void TearDown()
    {
        Directory.Delete(testDirectory, true);
    }

    [Test]
    public void testThatFilesComeBackInOrderFileOrder()
    {
        CreateFile(testDirectory, "order.mnl", "file4\nfile3\nfile2\nfile1\n");

        var result = new List&lt;FileInfo&gt;(new DirectoryTraverser(testDirectory));
        Assert.That(result[0].FullName, Is.EqualTo(Path.Combine(testDirectory, "file4")));
        Assert.That(result[1].FullName, Is.EqualTo(Path.Combine(testDirectory, "file3")));
        Assert.That(result[2].FullName, Is.EqualTo(Path.Combine(testDirectory, "file2")));
        Assert.That(result[3].FullName, Is.EqualTo(Path.Combine(testDirectory, "file1")));
    }

    [Test]
    public void testThatFilesComeBackInFileSystemOrder()
    {
        var result = new List&lt;FileInfo&gt;(new DirectoryTraverser(testDirectory));
        Assert.That(result[0].FullName, Is.EqualTo(Path.Combine(testDirectory, "file1")));
        Assert.That(result[1].FullName, Is.EqualTo(Path.Combine(testDirectory, "file2")));
        Assert.That(result[2].FullName, Is.EqualTo(Path.Combine(testDirectory, "file3")));
        Assert.That(result[3].FullName, Is.EqualTo(Path.Combine(testDirectory, "file4")));
    }

    public static string CreateTempDirectory()
    {
        var path = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
        Directory.CreateDirectory(path);
        return path;
    }

    public static void CreateFiles(string path, string[] files)
    {
        foreach (var file in files)
            CreateFile(path, file, file);
    }

    public static void CreateFile(string path, string name, string content)
    {
        using(var f = new StreamWriter(Path.Combine(path, name)))
        {
            f.Write(content);
        }
    }
}
</code></pre>

<p>And here is the class under test (prior to the refactor step as the
test does not pass):</p>

<pre><code>public class DirectoryTraverser : IEnumerable&lt;FileInfo&gt;
{
    private const string ORDER_FILENAME = "order.mnl";
    private readonly IList&lt;FileInfo&gt; order;

    public DirectoryTraverser(string dirPath)
    {
        var orderfilePath = Path.Combine(dirPath, ORDER_FILENAME);
        if (new FileInfo(orderfilePath).Exists)
        {
            order = new List&lt;FileInfo&gt;();
            using (var sr = File.OpenText(dirPath))
            {
                string file;
                while ((file = sr.ReadLine()) != null)
                    order.Add(new FileInfo(Path.Combine(dirPath, file)));
            }
        }
        else
        {
            order = new List&lt;FileInfo&gt;(new DirectoryInfo(dirPath).GetFiles());
        }
    }

    public IEnumerator&lt;FileInfo&gt; GetEnumerator()
    {
        return order.GetEnumerator();
    }

    IEnumerator IEnumerable.GetEnumerator()
    {
        return GetEnumerator();
    }
}
</code></pre>

<p>The output from NUnit:</p>

<pre><code>Test net.purpletube.minla.test.FileSystem.DirectoryTraverserTest.testThatFilesComeBackInOrderFileOrder'
failed: System.UnauthorizedAccessException : Access to the path 'C:...\Temp\tto2nvka.1es' is denied.
       at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
       at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
       at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options) 
       at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize)
       at System.IO.StreamReader..ctor(String path)
       at System.IO.File.OpenText(String path)
       FileSystem\DirectoryTraverser.cs(21,0): at net.purpletube.minla.FileSystem.DirectoryTraverser..ctor(String
dirPath)
       FileSystem\DirectoryTraverserTest.cs(36,0): at net.purpletube.minla.test.FileSystem.DirectoryTraverserTest.testThatFilesComeBackInOrderFileOrder()

1 passed, 1 failed, 0 skipped, took 0.33 seconds (NUnit 2.5.5).
</code></pre>

<p>It appears that reading the four temporary files (file1 to file4) is
fine. It's the order file that causes the problem.</p>

<p>I'm completely lost. Does anyone have a clue what might be happening?</p>
