diff --git a/AlphaFS.UnitTest/AlphaFS FileSystemEntryInfo Class/AlphaFS_Directory.EnumerateFileSystemEntryInfos_TypeFileSystemEntryInfo.cs b/AlphaFS.UnitTest/AlphaFS FileSystemEntryInfo Class/AlphaFS_Directory.EnumerateFileSystemEntryInfos_TypeFileSystemEntryInfo.cs index b2934ee38..a858021c3 100644 --- a/AlphaFS.UnitTest/AlphaFS FileSystemEntryInfo Class/AlphaFS_Directory.EnumerateFileSystemEntryInfos_TypeFileSystemEntryInfo.cs +++ b/AlphaFS.UnitTest/AlphaFS FileSystemEntryInfo Class/AlphaFS_Directory.EnumerateFileSystemEntryInfos_TypeFileSystemEntryInfo.cs @@ -38,8 +38,7 @@ public void AlphaFS_Directory_EnumerateFileSystemEntryInfos_TypeFileSystemEntryI - - + private void Directory_EnumerateFileSystemEntryInfos_TypeFileSystemEntryInfo(bool isNetwork) { UnitTestConstants.PrintUnitTestHeader(isNetwork); diff --git a/AlphaFS.UnitTest/AlphaFS FileSystemEntryInfo Class/AlphaFS_Directory.GetFileSystemEntryInfo.cs b/AlphaFS.UnitTest/AlphaFS FileSystemEntryInfo Class/AlphaFS_Directory.GetFileSystemEntryInfo.cs index 60ab3c77d..69ddfafb3 100644 --- a/AlphaFS.UnitTest/AlphaFS FileSystemEntryInfo Class/AlphaFS_Directory.GetFileSystemEntryInfo.cs +++ b/AlphaFS.UnitTest/AlphaFS FileSystemEntryInfo Class/AlphaFS_Directory.GetFileSystemEntryInfo.cs @@ -21,7 +21,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using System; -using System.Linq; namespace AlphaFS.UnitTest { @@ -38,21 +37,6 @@ public void AlphaFS_Directory_GetFileSystemEntryInfo_LocalAndNetwork_Success() } - [TestMethod] - public void AlphaFS_Directory_GetFileSystemEntryInfo_LogicalDrives_Local_Success() - { - Directory_GetFileSystemEntryInfo_LogicalDrives(); - } - - - [TestMethod] - public void AlphaFS_Directory_GetFileSystemEntryInfo_CatchDirectoryNotFoundException_FileExistsWithSameNameAsDirectory_LocalAndNetwork_Success() - { - Directory_GetFileSystemEntryInfo_CatchDirectoryNotFoundException_FileExistsWithSameNameAsDirectory(false); - Directory_GetFileSystemEntryInfo_CatchDirectoryNotFoundException_FileExistsWithSameNameAsDirectory(true); - } - - private void Directory_GetFileSystemEntryInfo(bool isNetwork) @@ -80,85 +64,6 @@ private void Directory_GetFileSystemEntryInfo(bool isNetwork) 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."); - Console.WriteLine(); - } - - - private void Directory_GetFileSystemEntryInfo_LogicalDrives() - { - UnitTestConstants.PrintUnitTestHeader(false); - - - var drives = Alphaleonis.Win32.Filesystem.Directory.EnumerateLogicalDrives().ToList(); - - foreach (var drive in drives) - { - Console.WriteLine("\nInput Logical Drive: [{0}]", drive.Name); - - try - { - var fsei = Alphaleonis.Win32.Filesystem.Directory.GetFileSystemEntryInfo(drive.Name); - 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."); - - - // Fixed local drives should have these attributes. - if (new Alphaleonis.Win32.Filesystem.DriveInfo(drive.Name).DriveType == System.IO.DriveType.Fixed) - { - Assert.IsTrue((fsei.Attributes & System.IO.FileAttributes.Hidden) != 0, "The Hidden attribute is not found, but is expected."); - Assert.IsTrue((fsei.Attributes & System.IO.FileAttributes.System) != 0, "The System attribute is not found, but is expected."); - } - - - Assert.AreEqual(".", fsei.FileName, "The file names are not equal, but are expected to be."); - Assert.AreEqual(drive.Name, fsei.FullPath, "The full paths are not equal, but are expected to be."); - } - catch (Exception ex) - { - Console.WriteLine("\n\tCaught UNEXPECTED Exception: [{0}] {1}", ex.GetType().Name, ex.Message); - } - - - Console.WriteLine(); - } - } - - - private void Directory_GetFileSystemEntryInfo_CatchDirectoryNotFoundException_FileExistsWithSameNameAsDirectory(bool isNetwork) - { - var path = UnitTestConstants.NotepadExe; - - if (!System.IO.File.Exists(path)) - Assert.Inconclusive("Test ignored because {0} was not found.", path); - - - UnitTestConstants.PrintUnitTestHeader(isNetwork); - - var tempPath = path; - if (isNetwork) - tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath); - - - Console.WriteLine("\nInput Directory Path: [{0}]", tempPath); - - - var gotException = false; - try - { - Alphaleonis.Win32.Filesystem.Directory.GetFileSystemEntryInfo(tempPath); - } - catch (Exception ex) - { - var exName = ex.GetType().Name; - gotException = exName.Equals("DirectoryNotFoundException", StringComparison.OrdinalIgnoreCase); - Console.WriteLine("\n\tCaught {0} Exception: [{1}] {2}", gotException ? "EXPECTED" : "UNEXPECTED", exName, ex.Message); - } - Assert.IsTrue(gotException, "The exception is not caught, but is expected to."); - - Console.WriteLine(); } } diff --git a/AlphaFS.UnitTest/AlphaFS FileSystemEntryInfo Class/AlphaFS_Directory.GetFileSystemEntryInfo_CatchDirectoryNotFoundException_FileExistsWithSameNameAsDirectory.cs b/AlphaFS.UnitTest/AlphaFS FileSystemEntryInfo Class/AlphaFS_Directory.GetFileSystemEntryInfo_CatchDirectoryNotFoundException_FileExistsWithSameNameAsDirectory.cs new file mode 100644 index 000000000..315b7f778 --- /dev/null +++ b/AlphaFS.UnitTest/AlphaFS FileSystemEntryInfo Class/AlphaFS_Directory.GetFileSystemEntryInfo_CatchDirectoryNotFoundException_FileExistsWithSameNameAsDirectory.cs @@ -0,0 +1,81 @@ +/* Copyright (C) 2008-2018 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; + +namespace AlphaFS.UnitTest +{ + public partial class AlphaFS_FileSystemEntryInfoTest + { + // Pattern: ___ + + + [TestMethod] + public void AlphaFS_Directory_GetFileSystemEntryInfo_CatchDirectoryNotFoundException_FileExistsWithSameNameAsDirectory_LocalAndNetwork_Success() + { + Directory_GetFileSystemEntryInfo_CatchDirectoryNotFoundException_FileExistsWithSameNameAsDirectory(false); + Directory_GetFileSystemEntryInfo_CatchDirectoryNotFoundException_FileExistsWithSameNameAsDirectory(true); + } + + + + + private void Directory_GetFileSystemEntryInfo_CatchDirectoryNotFoundException_FileExistsWithSameNameAsDirectory(bool isNetwork) + { + var path = UnitTestConstants.NotepadExe; + + if (!System.IO.File.Exists(path)) + Assert.Inconclusive("Test ignored because {0} was not found.", path); + + + UnitTestConstants.PrintUnitTestHeader(isNetwork); + + var tempPath = path; + if (isNetwork) + tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath); + + + Console.WriteLine("\nInput Directory Path: [{0}]", tempPath); + + + var gotException = false; + try + { + Alphaleonis.Win32.Filesystem.Directory.GetFileSystemEntryInfo(tempPath); + } + catch (Exception ex) + { + var exType = ex.GetType(); + + gotException = exType == typeof(System.IO.DirectoryNotFoundException); + + Console.WriteLine("\n\tCaught {0} Exception: [{1}] {2}", gotException ? "EXPECTED" : "UNEXPECTED", exType.Name, ex.Message); + } + + + Assert.IsTrue(gotException, "The exception is not caught, but is expected to."); + + + Console.WriteLine(); + } + } +} diff --git a/AlphaFS.UnitTest/AlphaFS FileSystemEntryInfo Class/AlphaFS_Directory.GetFileSystemEntryInfo_LogicalDrives.cs b/AlphaFS.UnitTest/AlphaFS FileSystemEntryInfo Class/AlphaFS_Directory.GetFileSystemEntryInfo_LogicalDrives.cs new file mode 100644 index 000000000..2dd3fcd84 --- /dev/null +++ b/AlphaFS.UnitTest/AlphaFS FileSystemEntryInfo Class/AlphaFS_Directory.GetFileSystemEntryInfo_LogicalDrives.cs @@ -0,0 +1,85 @@ +/* Copyright (C) 2008-2018 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +using System; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace AlphaFS.UnitTest +{ + public partial class AlphaFS_FileSystemEntryInfoTest + { + // Pattern: ___ + + + + [TestMethod] + public void AlphaFS_Directory_GetFileSystemEntryInfo_LogicalDrives_Local_Success() + { + Directory_GetFileSystemEntryInfo_LogicalDrives(); + } + + + + + private void Directory_GetFileSystemEntryInfo_LogicalDrives() + { + UnitTestConstants.PrintUnitTestHeader(false); + + + var drives = Alphaleonis.Win32.Filesystem.Directory.EnumerateLogicalDrives().ToList(); + + foreach (var drive in drives) + { + Console.WriteLine("\nInput Logical Drive: [{0}]", drive.Name); + + try + { + var fsei = Alphaleonis.Win32.Filesystem.Directory.GetFileSystemEntryInfo(drive.Name); + 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."); + + + // Fixed local drives should have these attributes. + if (new Alphaleonis.Win32.Filesystem.DriveInfo(drive.Name).DriveType == System.IO.DriveType.Fixed) + { + Assert.IsTrue((fsei.Attributes & System.IO.FileAttributes.Hidden) != 0, "The Hidden attribute is not found, but is expected."); + Assert.IsTrue((fsei.Attributes & System.IO.FileAttributes.System) != 0, "The System attribute is not found, but is expected."); + } + + + Assert.AreEqual(".", fsei.FileName, "The file names are not equal, but are expected to be."); + Assert.AreEqual(drive.Name, fsei.FullPath, "The full paths are not equal, but are expected to be."); + } + catch (Exception ex) + { + Console.WriteLine("\n\tCaught UNEXPECTED Exception: [{0}] {1}", ex.GetType().Name, ex.Message); + } + + + Console.WriteLine(); + } + } + } +} diff --git a/AlphaFS.UnitTest/AlphaFS FileSystemEntryInfo Class/AlphaFS_File.GetFileSystemEntryInfo.cs b/AlphaFS.UnitTest/AlphaFS FileSystemEntryInfo Class/AlphaFS_File.GetFileSystemEntryInfo.cs index ffec4c73c..e6969331c 100644 --- a/AlphaFS.UnitTest/AlphaFS FileSystemEntryInfo Class/AlphaFS_File.GetFileSystemEntryInfo.cs +++ b/AlphaFS.UnitTest/AlphaFS FileSystemEntryInfo Class/AlphaFS_File.GetFileSystemEntryInfo.cs @@ -36,16 +36,7 @@ public void AlphaFS_File_GetFileSystemEntryInfo_LocalAndNetwork_Success() File_GetFileSystemEntryInfo(true); } - - - [TestMethod] - public void AlphaFS_File_GetFileSystemEntryInfo_CatchFileNotFoundException_DirectoryExistsWithSameNameAsFile_LocalAndNetwork_Success() - { - File_GetFileSystemEntryInfo_CatchFileNotFoundException_DirectoryExistsWithSameNameAsFile(false); - File_GetFileSystemEntryInfo_CatchFileNotFoundException_DirectoryExistsWithSameNameAsFile(true); - } - - + private void File_GetFileSystemEntryInfo(bool isNetwork) @@ -70,43 +61,6 @@ private void File_GetFileSystemEntryInfo(bool isNetwork) 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(); - } - - - private void - File_GetFileSystemEntryInfo_CatchFileNotFoundException_DirectoryExistsWithSameNameAsFile(bool isNetwork) - { - var path = UnitTestConstants.SysRoot; - - if (!System.IO.Directory.Exists(path)) - Assert.Inconclusive("Test ignored because {0} was not found.", path); - - - UnitTestConstants.PrintUnitTestHeader(isNetwork); - - var tempPath = path; - if (isNetwork) - tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath); - - - Console.WriteLine("\nInput File Path: [{0}]", tempPath); - - - var gotException = false; - try - { - Alphaleonis.Win32.Filesystem.File.GetFileSystemEntryInfo(tempPath); - } - catch (Exception ex) - { - var exName = ex.GetType().Name; - gotException = exName.Equals("FileNotFoundException", StringComparison.OrdinalIgnoreCase); - Console.WriteLine("\n\tCaught {0} Exception: [{1}] {2}", gotException ? "EXPECTED" : "UNEXPECTED", exName, ex.Message); - } - Assert.IsTrue(gotException, "The exception is not caught, but is expected to."); - - Console.WriteLine(); } } diff --git a/AlphaFS.UnitTest/AlphaFS FileSystemEntryInfo Class/AlphaFS_File.GetFileSystemEntryInfo_CatchFileNotFoundException_DirectoryExistsWithSameNameAsFile.cs b/AlphaFS.UnitTest/AlphaFS FileSystemEntryInfo Class/AlphaFS_File.GetFileSystemEntryInfo_CatchFileNotFoundException_DirectoryExistsWithSameNameAsFile.cs new file mode 100644 index 000000000..25fedb33e --- /dev/null +++ b/AlphaFS.UnitTest/AlphaFS FileSystemEntryInfo Class/AlphaFS_File.GetFileSystemEntryInfo_CatchFileNotFoundException_DirectoryExistsWithSameNameAsFile.cs @@ -0,0 +1,81 @@ +/* Copyright (C) 2008-2018 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; + +namespace AlphaFS.UnitTest +{ + public partial class AlphaFS_FileSystemEntryInfoTest + { + // Pattern: ___ + + + [TestMethod] + public void AlphaFS_File_GetFileSystemEntryInfo_CatchFileNotFoundException_DirectoryExistsWithSameNameAsFile_LocalAndNetwork_Success() + { + File_GetFileSystemEntryInfo_CatchFileNotFoundException_DirectoryExistsWithSameNameAsFile(false); + File_GetFileSystemEntryInfo_CatchFileNotFoundException_DirectoryExistsWithSameNameAsFile(true); + } + + + + + private void File_GetFileSystemEntryInfo_CatchFileNotFoundException_DirectoryExistsWithSameNameAsFile(bool isNetwork) + { + var path = UnitTestConstants.SysRoot; + + if (!System.IO.Directory.Exists(path)) + Assert.Inconclusive("Test ignored because {0} was not found.", path); + + + UnitTestConstants.PrintUnitTestHeader(isNetwork); + + var tempPath = path; + if (isNetwork) + tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath); + + + Console.WriteLine("\nInput File Path: [{0}]", tempPath); + + + var gotException = false; + try + { + Alphaleonis.Win32.Filesystem.File.GetFileSystemEntryInfo(tempPath); + } + catch (Exception ex) + { + var exType = ex.GetType(); + + gotException = exType == typeof(System.IO.FileNotFoundException); + + Console.WriteLine("\n\tCaught {0} Exception: [{1}] {2}", gotException ? "EXPECTED" : "UNEXPECTED", exType.Name, ex.Message); + } + + + Assert.IsTrue(gotException, "The exception is not caught, but is expected to."); + + + Console.WriteLine(); + } + } +} diff --git a/AlphaFS.UnitTest/AlphaFS.UnitTest.csproj b/AlphaFS.UnitTest/AlphaFS.UnitTest.csproj index e1da6cdac..a292d065d 100644 --- a/AlphaFS.UnitTest/AlphaFS.UnitTest.csproj +++ b/AlphaFS.UnitTest/AlphaFS.UnitTest.csproj @@ -163,7 +163,10 @@ + + + diff --git a/AlphaFS/Filesystem/FindFileSystemEntryInfo.cs b/AlphaFS/Filesystem/FindFileSystemEntryInfo.cs index a739b3b5a..527a09a27 100644 --- a/AlphaFS/Filesystem/FindFileSystemEntryInfo.cs +++ b/AlphaFS/Filesystem/FindFileSystemEntryInfo.cs @@ -297,10 +297,9 @@ private SafeFindFileHandle FindFirstFile(string pathLp, out NativeMethods.WIN32_ ThrowPossibleException((uint) lastError, pathLp); } - // When the handle is null and we are still here, it means the ErrorHandler is active, - // preventing the Exception from being thrown. + // 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) + if (null != handle && lastError != Win32Errors.NO_ERROR) VerifyInstanceType(win32FindData); } diff --git a/CHANGELOG.md b/CHANGELOG.md index 0786994be..305f6d8fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ Version 2.2.2 (2018-XX-XX) - Issue #434: `Directory.Move` operation worked in v2.0.1, but now fails in v.2.2.1 - Issue #436: `Directory.GetFiles()` with relative path (Thx stellarbear) - Issue #437: Fixed `PathTooLongException` for boundary case of directory name length in `Path.NormalizePath` (Thx okrushelnitsky) +- Issue #441: `InvalidOperationException` on `Directory.EnumerateFileSystemEntries()` + Version 2.2.1 (2018-04-05) -------------