peteraritchie / LongPath

drop-in library to support long paths in .NET
GNU Lesser General Public License v3.0
112 stars 43 forks source link

Some NUnit Tests failed due to current drive of installation - proposed solution enclosed #64

Open efef77 opened 7 years ago

efef77 commented 7 years ago

Regarding Pri.LongPath AssemblyVersion 2.0.1.0

Failed unit tests running the tests on D: drive instead of C: drive

I did some work on it: So I recommend fixed test cases as follows. They will run on any drive

-------------------------------
public class UncDirectoryTests
-------------------------------
[Test]
public void TestGetDirectoryRoot()
{   
    string plain = Directory.GetDirectoryRoot(directory);
    string unc = Directory.GetDirectoryRoot(uncDirectory);
    string must = @"\\localhost\X$\".Replace('X', plain[0]); // use current drive letter
    Assert.IsTrue(must.Equals(unc, StringComparison.InvariantCultureIgnoreCase));
}

[Test]
public void TestGetPathRoot()
{
    var root = Path.GetPathRoot(uncDirectory);
    Assert.IsNotNull(root);
    Assert.AreEqual(15, root.Length);
    var plain = Path.GetPathRoot(directory);
    string must = @"\\localhost\X$\".Replace('X', plain[0]); // use current drive letter
    Assert.IsTrue(must.Equals(root, StringComparison.InvariantCultureIgnoreCase));
}    

-------------------------------
public class DirectoryInfoTests
-------------------------------
[Test]
public void TestMoveToDifferentRoot()
{
    var randomFileName = Path.GetRandomFileName();
    var tempLongPathDirectory = Path.Combine(longPathDirectory, randomFileName);
    var di = new DirectoryInfo(tempLongPathDirectory);

    // get other drive letter
    char letter = longPathDirectory[0];
    if (letter < 'A' || letter >= 'Z') throw new Exception("invalid letter " + letter);
    letter = (char)(letter + 1); // next other drive
    string target = @"" + letter + @":\";
    Assert.Throws<IOException>(() => di.MoveTo(target)); // move to other drive
}

may some one update the test cases? thx for great work on library

regards efef77