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

Commit

Permalink
Updated unit tests related to FileSystemEntryInfo.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yomodo committed May 31, 2018
1 parent 36148c9 commit d1dcbd2
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,23 @@ public void AlphaFS_Directory_GetFileSystemEntryInfo_LocalAndNetwork_Success()

private void AlphaFS_Directory_GetFileSystemEntryInfo(bool isNetwork)
{
UnitTestConstants.PrintUnitTestHeader(isNetwork);
using (var tempRoot = new TemporaryDirectory(isNetwork))
{
var folder = tempRoot.CreateDirectoryRandomizedAttributes();

var tempPath = Environment.SystemDirectory;
if (isNetwork)
tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath);
Console.WriteLine("Input Directory Path: [{0}]", folder.FullName);

Console.WriteLine("Input Directory Path: [{0}]", tempPath);
var fsei = Alphaleonis.Win32.Filesystem.Directory.GetFileSystemEntryInfo(folder.FullName);

UnitTestConstants.Dump(fsei, -19);

var fsei = Alphaleonis.Win32.Filesystem.Directory.GetFileSystemEntryInfo(tempPath);

UnitTestConstants.Dump(fsei, -19);
Assert.IsTrue(fsei.GetType().IsEquivalentTo(typeof(Alphaleonis.Win32.Filesystem.FileSystemEntryInfo)));

Assert.IsTrue((fsei.Attributes & System.IO.FileAttributes.Directory) != 0, "The Directory attribute is not found, but is expected.");

Assert.IsTrue(fsei.GetType().IsEquivalentTo(typeof(Alphaleonis.Win32.Filesystem.FileSystemEntryInfo)));

Assert.IsTrue((fsei.Attributes & System.IO.FileAttributes.Directory) != 0, "The Directory attribute is not found, but is expected.");

Assert.AreEqual(tempPath, fsei.FullPath, "The paths are not equal, but are expected to be.");

Assert.AreEqual(folder.FullName, fsei.FullPath, "The paths are not equal, but are expected to be.");
}

Console.WriteLine();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,15 @@ public void AlphaFS_Directory_GetFileSystemEntryInfo_ThrowDirectoryNotFoundExcep

private void AlphaFS_Directory_GetFileSystemEntryInfo_ThrowDirectoryNotFoundException_FileExistsWithSameNameAsDirectory(bool isNetwork)
{
var path = System.IO.Path.Combine(Environment.SystemDirectory, "notepad.exe");
using (var tempRoot = new TemporaryDirectory(isNetwork))
{
var folder = tempRoot.CreateFileRandomizedAttributes();

if (!System.IO.File.Exists(path))
UnitTestAssert.InconclusiveBecauseFileNotFound(path);
Console.WriteLine("Input Directory Path: [{0}]", folder.FullName);

ExceptionAssert.DirectoryNotFoundException(() => Alphaleonis.Win32.Filesystem.Directory.GetFileSystemEntryInfo(folder.FullName));
}

UnitTestConstants.PrintUnitTestHeader(isNetwork);

var tempPath = path;
if (isNetwork)
tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath);

Console.WriteLine("Input Directory Path: [{0}]", tempPath);

ExceptionAssert.DirectoryNotFoundException(() => Alphaleonis.Win32.Filesystem.Directory.GetFileSystemEntryInfo(tempPath));

Console.WriteLine();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,23 @@ public void AlphaFS_File_GetFileSystemEntryInfo_LocalAndNetwork_Success()

private void AlphaFS_File_GetFileSystemEntryInfo(bool isNetwork)
{
var path = System.IO.Path.Combine(Environment.SystemDirectory, "notepad.exe");
using (var tempRoot = new TemporaryDirectory(isNetwork))
{
var file = tempRoot.CreateFileRandomizedAttributes();

if (!System.IO.File.Exists(path))
UnitTestAssert.InconclusiveBecauseFileNotFound(path);
Console.WriteLine("Input File Path: [{0}]", file.FullName);

var fsei = Alphaleonis.Win32.Filesystem.File.GetFileSystemEntryInfo(file.FullName);

UnitTestConstants.PrintUnitTestHeader(isNetwork);
UnitTestConstants.Dump(fsei, -19);

var tempPath = path;
if (isNetwork)
tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath);
Assert.IsTrue(fsei.GetType().IsEquivalentTo(typeof(Alphaleonis.Win32.Filesystem.FileSystemEntryInfo)));

Console.WriteLine("Input File Path: [{0}]", tempPath);
Assert.IsTrue(fsei.Attributes != System.IO.FileAttributes.Directory, "The directory attribute is found, but is not expected.");

Assert.AreEqual(file.FullName, fsei.FullPath, "The paths are not equal, but are expected to be.");
}

var fsei = Alphaleonis.Win32.Filesystem.File.GetFileSystemEntryInfo(tempPath);
UnitTestConstants.Dump(fsei, -19);

Assert.IsTrue(fsei.GetType().IsEquivalentTo(typeof(Alphaleonis.Win32.Filesystem.FileSystemEntryInfo)));
Assert.IsTrue(fsei.Attributes != System.IO.FileAttributes.Directory, "The directory attribute is found, but is not expected.");
Assert.AreEqual(tempPath, fsei.FullPath, "The paths are not equal, but are expected to be.");

Console.WriteLine();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private void AlphaFS_File_GetFileSystemEntryInfo_ThrowFileNotFoundException_Dire
{
using (var tempRoot = new TemporaryDirectory(isNetwork))
{
var folder = tempRoot.CreateDirectory();
var folder = tempRoot.CreateDirectoryRandomizedAttributes();

Console.WriteLine("Input Directory Path: [{0}]", folder.FullName);

Expand Down
11 changes: 3 additions & 8 deletions AlphaFS/Filesystem/FindFileSystemEntryInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,6 @@ private FileSystemEntryInfo NewFilesystemEntry(string pathLp, string fileName, N
var fullPath = (IsRelativePath ? pathLp.Replace(RelativeAbsolutePrefix, string.Empty) : pathLp) + fileName;

return new FileSystemEntryInfo(win32FindData) {FullPath = fullPath};

//return new FileSystemEntryInfo(win32FindData) {FullPath = (IsRelativePath ? OriginalInputPath + Path.DirectorySeparator : pathLp) + fileName};
}


Expand Down Expand Up @@ -547,17 +545,14 @@ public T Get<T>()
{
using (var handle = FindFirstFile(InputPath, out win32FindData))
{
// When the handle is null and we are still here, it means the ErrorHandler is active, preventing the Exception from being thrown.

if (null != handle)
VerifyInstanceType(win32FindData);

else
return (T) (object) null;

return null == handle

? (T) (object) null

: NewFileSystemEntryType<T>((win32FindData.dwFileAttributes & FileAttributes.Directory) != 0, null, null, InputPath, win32FindData);
return NewFileSystemEntryType<T>((win32FindData.dwFileAttributes & FileAttributes.Directory) != 0, null, null, InputPath, win32FindData);
}

}
Expand Down

0 comments on commit d1dcbd2

Please sign in to comment.