Skip to content
This repository was archived by the owner on Dec 6, 2024. It is now read-only.
Merged

2.1.3 #324

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion AlphaFS.UnitTest/AlphaFS.UnitTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@
<Compile Include="Directory Class\Directory_SetTimestamps.cs" />
<Compile Include="Directory Class\Directory_GetTimestamps.cs" />
<Compile Include="Directory Class\Directory_SetAccessControl.cs" />
<Compile Include="DirectoryInfo Class\DirectoryInfo_FolderName255Characters.cs" />
<Compile Include="DirectoryInfo Class\DirectoryInfo_MoveTo.cs" />
<Compile Include="DirectoryInfo Class\DirectoryInfo_Refresh.cs" />
<Compile Include="File Class\AlphaFS_File_GetHash.cs" />
<Compile Include="File Class\File_CreateText.cs" />
Expand Down Expand Up @@ -192,8 +194,15 @@
<Compile Include="File Class\File_GetAccessControl.cs" />
<Compile Include="FileInfo Class\FileInfo_InitializeInstance.cs" />
<Compile Include="FileInfo Class\FileInfo_Refresh.cs" />
<Compile Include="Host Class\AlphaFS_Host_EnumerateDomainDfsRoot.cs" />
<Compile Include="Host Class\AlphaFS_Host_EnumerateDfsRoot.cs" />
<Compile Include="Host Class\AlphaFS_Host_EnumerateDfsLinks.cs" />
<Compile Include="Host Class\AlphaFS_Host_ConnectTo.cs" />
<Compile Include="Host Class\AlphaFS_Host_ConnectDrive.cs" />
<Compile Include="Host Class\AlphaFS_Host_EnumerateDrives.cs" />
<Compile Include="Host Class\AlphaFS_Host_GetHostShareFromPath.cs" />
<Compile Include="Host Class\AlphaFS_Host_DriveConnection.cs" />
<Compile Include="Host Class\HostTest.cs" />
<Compile Include="Host Class\AlphaFS_Host_GetUncName.cs" />
<Compile Include="Classes\ClassesTest.cs" />
<Compile Include="Directory Class\Directory_CreateDirectory.cs" />
<Compile Include="Directory Class\DirectoryTest.cs" />
Expand Down
2 changes: 1 addition & 1 deletion AlphaFS.UnitTest/Classes/ClassesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ private void DumpClassDfsInfo()
Console.WriteLine("\n\n\t{0}", UnitTestConstants.Reporter(true));

if (noDomainConnection)
Assert.Inconclusive("Test ignored because the computer is probably not connected to a domain.");
Assert.Inconclusive("Test ignored because the computer is either not connected to a domain or no DFS root exists.");

if (cnt == 0)
Assert.Inconclusive("Nothing was enumerated, but it was expected.");
Expand Down
52 changes: 52 additions & 0 deletions AlphaFS.UnitTest/Directory Class/Directory_Exists.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,57 @@ private void Directory_Exists(bool isNetwork)
{
UnitTestConstants.PrintUnitTestHeader(isNetwork);


// Test Driveletter according to System.IO

// SystemIO: "C:"
// AlphaFS : "\\?\C:"
var shouldBe = true;
var driveSysIO = UnitTestConstants.SysDrive;
var drive = @"\\?\" + UnitTestConstants.SysDrive;
if (isNetwork) { driveSysIO = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(driveSysIO); drive = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(drive); }
Console.Write("\nDrive path (System.IO, should be " + shouldBe + "):\t\t" + driveSysIO + "\t\t\t");
var existSystemIO = System.IO.Directory.Exists(driveSysIO);
Console.WriteLine(existSystemIO);
var existAlphaFS = Alphaleonis.Win32.Filesystem.Directory.Exists(drive);
Console.Write("Drive path (AlphaFS, should be " + shouldBe + "):\t\t" + drive + "\t\t\t");
Console.WriteLine(existAlphaFS);
Assert.AreEqual(shouldBe, existSystemIO, "The result should be: " + shouldBe);
Assert.AreEqual(existSystemIO, existAlphaFS, "The results are not equal, but were expected to be.");
Console.WriteLine();




// Both: "\\?\C:\"
shouldBe = isNetwork; // True when network (UNC path), false when local path.
drive = @"\\?\" + UnitTestConstants.SysDrive + @"\";
if (isNetwork) drive = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(drive);
Console.Write("Drive path (System.IO, should be " + shouldBe + "):\t\t" + drive + "\t\t\t");
existSystemIO = System.IO.Directory.Exists(drive);
existAlphaFS = Alphaleonis.Win32.Filesystem.Directory.Exists(drive);
Console.WriteLine(existSystemIO);
Assert.AreEqual(shouldBe, existSystemIO, "The result should be: " + shouldBe);
Assert.AreEqual(existSystemIO, existAlphaFS, "The results are not equal, but were expected to be.");



// Both: "C:\"
shouldBe = true;
drive = UnitTestConstants.SysDrive + @"\";
if (isNetwork) drive = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(drive);
Console.Write("Drive path (System.IO, should be " + shouldBe + "):\t\t" + drive + "\t\t\t");
existSystemIO = System.IO.Directory.Exists(drive);
existAlphaFS = Alphaleonis.Win32.Filesystem.Directory.Exists(drive);
Console.WriteLine(existSystemIO);
Assert.AreEqual(shouldBe, existSystemIO, "The result should be: " + shouldBe);
Assert.AreEqual(existSystemIO, existAlphaFS, "The results are not equal, but were expected to be.");




// Test Folder.

var tempPath = System.IO.Path.GetTempPath();
if (isNetwork)
tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath);
Expand All @@ -67,6 +118,7 @@ private void Directory_Exists(bool isNetwork)
Assert.IsTrue(Alphaleonis.Win32.Filesystem.Directory.Exists(folder), "The directory does not exists, but is expected to be.");
}


Console.WriteLine();
}

Expand Down
191 changes: 161 additions & 30 deletions AlphaFS.UnitTest/Directory Class/Directory_Move.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ partial class DirectoryTest
{
// Pattern: <class>_<function>_<scenario>_<expected result>

[TestMethod]
public void Directory_Move_Rename_LocalAndNetwork_Success()
{
Directory_Move_Rename(false);
Directory_Move_Rename(true);
}


[TestMethod]
public void Directory_Move_Rename_DifferentCasing_LocalAndNetwork_Success()
{
Directory_Move_Rename_DifferentCasing(false);
Directory_Move_Rename_DifferentCasing(true);
}


[TestMethod]
public void Directory_Move_SameVolume_LocalAndNetwork_Success()
{
Expand Down Expand Up @@ -95,7 +111,15 @@ public void Directory_Move_CatchDirectoryNotFoundException_NonExistingDirectory_
Directory_Move_CatchDirectoryNotFoundException_NonExistingDirectory(false);
Directory_Move_CatchDirectoryNotFoundException_NonExistingDirectory(true);
}



[TestMethod]
public void Directory_Move_CatchIOException_SameSourceAndDestination_LocalAndNetwork_Success()
{
Directory_Move_CatchIOException_SameSourceAndDestination(false);
Directory_Move_CatchIOException_SameSourceAndDestination(true);
}


[TestMethod]
public void Directory_Move_CatchNotSupportedException_PathContainsColon_LocalAndNetwork_Success()
Expand All @@ -112,9 +136,9 @@ public void Directory_Move_CatchUnauthorizedAccessException_UserExplicitDeny_Loc
Directory_Move_CatchUnauthorizedAccessException_UserExplicitDeny(true);
}






private void Directory_Move(bool isNetwork)
{
UnitTestConstants.PrintUnitTestHeader(isNetwork);
Expand Down Expand Up @@ -352,34 +376,7 @@ private void Directory_Move_CatchArgumentException_PathStartsWithColon(bool isNe

Console.WriteLine();
}


private void Directory_Move_CatchNotSupportedException_PathContainsColon(bool isNetwork)
{
UnitTestConstants.PrintUnitTestHeader(isNetwork);

var colonText = @"\My:FilePath";
var folderSrc = (isNetwork ? Alphaleonis.Win32.Filesystem.Path.LocalToUnc(UnitTestConstants.LocalHostShare) : UnitTestConstants.SysDrive + @"\dev\test") + colonText;

Console.WriteLine("\nSrc Directory Path: [{0}]", folderSrc);


var gotException = false;
try
{
Alphaleonis.Win32.Filesystem.Directory.Move(folderSrc, string.Empty);
}
catch (Exception ex)
{
var exName = ex.GetType().Name;
gotException = exName.Equals("NotSupportedException", StringComparison.OrdinalIgnoreCase);
Console.WriteLine("\n\tCaught Exception: [{0}] Message: [{1}]", exName, ex.Message);
}
Assert.IsTrue(gotException, "The exception is not caught, but is expected to.");

Console.WriteLine();
}


private void Directory_Move_CatchDirectoryNotFoundException_NonExistingDriveLetter(bool isNetwork)
{
Expand Down Expand Up @@ -457,6 +454,70 @@ private void Directory_Move_CatchDirectoryNotFoundException_NonExistingDirectory
}


private void Directory_Move_CatchIOException_SameSourceAndDestination(bool isNetwork)
{
UnitTestConstants.PrintUnitTestHeader(isNetwork);

var tempPath = System.IO.Path.GetTempPath();
if (isNetwork)
tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath);


using (var rootDir = new TemporaryDirectory(tempPath, "Directory_Move_CatchIOException_SameSourceAndDestination"))
{
var folderSrc = System.IO.Directory.CreateDirectory(System.IO.Path.Combine(rootDir.Directory.FullName, "Source-") + System.IO.Path.GetRandomFileName());
var folderDst = folderSrc;


Console.WriteLine("\nSrc Directory Path: [{0}]", folderSrc.FullName);
Console.WriteLine("Dst Directory Path: [{0}]", folderDst.FullName);


var gotException = false;
try
{
System.IO.Directory.Move(folderSrc.FullName, folderDst.FullName);
}
catch (Exception ex)
{
var exName = ex.GetType().Name;
gotException = exName.Equals("IOException", StringComparison.OrdinalIgnoreCase);
Console.WriteLine("\n\tCaught Exception: [{0}] Message: [{1}]", exName, ex.Message);
}
Assert.IsTrue(gotException, "The exception is not caught, but is expected to.");
}

Console.WriteLine();
}


private void Directory_Move_CatchNotSupportedException_PathContainsColon(bool isNetwork)
{
UnitTestConstants.PrintUnitTestHeader(isNetwork);

var colonText = @"\My:FilePath";
var folderSrc = (isNetwork ? Alphaleonis.Win32.Filesystem.Path.LocalToUnc(UnitTestConstants.LocalHostShare) : UnitTestConstants.SysDrive + @"\dev\test") + colonText;

Console.WriteLine("\nSrc Directory Path: [{0}]", folderSrc);


var gotException = false;
try
{
Alphaleonis.Win32.Filesystem.Directory.Move(folderSrc, string.Empty);
}
catch (Exception ex)
{
var exName = ex.GetType().Name;
gotException = exName.Equals("NotSupportedException", StringComparison.OrdinalIgnoreCase);
Console.WriteLine("\n\tCaught Exception: [{0}] Message: [{1}]", exName, ex.Message);
}
Assert.IsTrue(gotException, "The exception is not caught, but is expected to.");

Console.WriteLine();
}


private void Directory_Move_CatchUnauthorizedAccessException_UserExplicitDeny(bool isNetwork)
{
UnitTestConstants.PrintUnitTestHeader(isNetwork);
Expand Down Expand Up @@ -516,5 +577,75 @@ private void Directory_Move_CatchUnauthorizedAccessException_UserExplicitDeny(bo

Console.WriteLine();
}


private void Directory_Move_Rename(bool isNetwork)
{
UnitTestConstants.PrintUnitTestHeader(isNetwork);

var tempPath = System.IO.Path.GetTempPath();
if (isNetwork)
tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath);


using (var rootDir = new TemporaryDirectory(tempPath, "Directory.Move (Rename)"))
{
var folderSrc = System.IO.Directory.CreateDirectory(System.IO.Path.Combine(rootDir.Directory.FullName, "Source-") + System.IO.Path.GetRandomFileName());
var folderDst = new System.IO.DirectoryInfo(System.IO.Path.Combine(rootDir.Directory.FullName, "Destination-") + System.IO.Path.GetRandomFileName());

Console.WriteLine("\nInput Directory Path: [{0}]", folderSrc.FullName);
Console.WriteLine("\nRename folder: [{0}] to: [{1}]", folderSrc.Name, folderDst.Name);


Assert.IsTrue(folderSrc.Exists, "The source folder does not exist which was not expected.");
Assert.IsFalse(folderDst.Exists, "The destination folder exists which was not expected.");

Alphaleonis.Win32.Filesystem.Directory.Move(folderSrc.FullName, folderDst.FullName);

folderSrc.Refresh();
folderDst.Refresh();

Assert.IsFalse(folderSrc.Exists, "The source folder exists which was not expected.");
Assert.IsTrue(folderDst.Exists, "The destination folder does not exists which was not expected.");
}

Console.WriteLine();
}


private void Directory_Move_Rename_DifferentCasing(bool isNetwork)
{
UnitTestConstants.PrintUnitTestHeader(isNetwork);

var tempPath = System.IO.Path.GetTempPath();
if (isNetwork)
tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath);


using (var rootDir = new TemporaryDirectory(tempPath, "Directory.Move (Rename_DifferentCasing)"))
{
var folderSrc = System.IO.Directory.CreateDirectory((System.IO.Path.Combine(rootDir.Directory.FullName, "Source-") + System.IO.Path.GetRandomFileName()).ToLowerInvariant());
var folderDst = folderSrc;
var newFolderName = System.IO.Path.GetFileName(folderDst.FullName.ToUpperInvariant());


Console.WriteLine("\nInput Directory Path: [{0}]", folderSrc.FullName);
Console.WriteLine("\nRename folder: [{0}] to: [{1}]", folderSrc.Name, newFolderName);


Assert.IsTrue(folderSrc.Exists, "The source folder does not exist which was not expected.");
Assert.IsTrue(folderDst.Exists, "The destination folder exists which was not expected.");

Alphaleonis.Win32.Filesystem.Directory.Move(folderSrc.FullName, folderDst.FullName.ToUpperInvariant());

folderSrc.Refresh();
folderDst.Refresh();

Assert.IsTrue(folderSrc.Exists, "The source folder exists which was not expected.");
Assert.IsTrue(folderDst.Exists, "The destination folder does not exists which was not expected.");
}

Console.WriteLine();
}
}
}
Loading