diff options
author | Jeremy Kuhne <jeremy.kuhne@microsoft.com> | 2018-03-12 04:59:23 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-12 04:59:23 +0300 |
commit | b4dfbadf5dd4410616061ddb1057f1bcee7bb41f (patch) | |
tree | 40d1f66d8d772bd31d882ca31b09ec95525933bb /src/System.IO.FileSystem | |
parent | 32bbfca77bb3e3d0c73a6954f1598cf8e91906a9 (diff) |
More FileSystem tests (#27955)
- Fix #27244 validation
- Add more enumerable tests
Fixes #27244
Diffstat (limited to 'src/System.IO.FileSystem')
-rw-r--r-- | src/System.IO.FileSystem/tests/Enumeration/ErrorHandlingTests.netcoreapp.cs | 34 | ||||
-rw-r--r-- | src/System.IO.FileSystem/tests/Enumeration/FileSystemNameTests.netcoreapp.cs (renamed from src/System.IO.FileSystem/tests/Enumeration/Win32MatcherTests.netcoreapp.cs) | 2 | ||||
-rw-r--r-- | src/System.IO.FileSystem/tests/Enumeration/RootTests.netcoreapp.cs | 10 | ||||
-rw-r--r-- | src/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj | 2 |
4 files changed, 38 insertions, 10 deletions
diff --git a/src/System.IO.FileSystem/tests/Enumeration/ErrorHandlingTests.netcoreapp.cs b/src/System.IO.FileSystem/tests/Enumeration/ErrorHandlingTests.netcoreapp.cs index 24f07f8911..1414156cf3 100644 --- a/src/System.IO.FileSystem/tests/Enumeration/ErrorHandlingTests.netcoreapp.cs +++ b/src/System.IO.FileSystem/tests/Enumeration/ErrorHandlingTests.netcoreapp.cs @@ -16,27 +16,55 @@ namespace System.IO.Tests { } public int ErrorCount { get; private set; } + public string DirectoryFinished { get; private set; } protected override string TransformEntry(ref FileSystemEntry entry) - { - throw new NotImplementedException(); - } + => entry.FileName.ToString(); protected override bool ContinueOnError(int error) { ErrorCount++; return true; } + + protected override void OnDirectoryFinished(ReadOnlySpan<char> directory) + => DirectoryFinished = directory.ToString(); } [Fact] public void OpenErrorDoesNotHappenAgainOnMoveNext() { + // What we're checking for here is that we don't try to enumerate when we + // couldn't even open the root directory (e.g. open the handle again, try + // to get data, etc.) using (IgnoreErrors ie = new IgnoreErrors(Path.GetRandomFileName())) { Assert.Equal(1, ie.ErrorCount); Assert.False(ie.MoveNext()); Assert.Equal(1, ie.ErrorCount); + + // Since we didn't start, the directory shouldn't finish. + Assert.Null(ie.DirectoryFinished); + } + } + + [Fact] + public void DeleteDirectoryAfterOpening() + { + // We shouldn't prevent the directory from being deleted, even though we've + // opened (and are holding) the handle. On Windows this means we've opened + // the handle with file share of delete. + DirectoryInfo info = Directory.CreateDirectory(GetTestFilePath()); + using (IgnoreErrors ie = new IgnoreErrors(info.FullName)) + { + Assert.Equal(0, ie.ErrorCount); + Directory.Delete(info.FullName); + Assert.False(ie.MoveNext()); + + // This doesn't cause an error as the directory is still valid until the + // the enumerator is closed (as we have an open handle) + Assert.Equal(0, ie.ErrorCount); + Assert.Equal(info.FullName, ie.DirectoryFinished); } } } diff --git a/src/System.IO.FileSystem/tests/Enumeration/Win32MatcherTests.netcoreapp.cs b/src/System.IO.FileSystem/tests/Enumeration/FileSystemNameTests.netcoreapp.cs index d7c764ac15..7076201e48 100644 --- a/src/System.IO.FileSystem/tests/Enumeration/Win32MatcherTests.netcoreapp.cs +++ b/src/System.IO.FileSystem/tests/Enumeration/FileSystemNameTests.netcoreapp.cs @@ -7,7 +7,7 @@ using Xunit; namespace System.IO.Tests { - public class Win32MatcherTests + public class FileSystemNameTests { [Theory, MemberData(nameof(SimpleMatchData)), diff --git a/src/System.IO.FileSystem/tests/Enumeration/RootTests.netcoreapp.cs b/src/System.IO.FileSystem/tests/Enumeration/RootTests.netcoreapp.cs index 002ea4376d..91b1376ede 100644 --- a/src/System.IO.FileSystem/tests/Enumeration/RootTests.netcoreapp.cs +++ b/src/System.IO.FileSystem/tests/Enumeration/RootTests.netcoreapp.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.IO.Enumeration; -using System.Linq; using Xunit; namespace System.IO.Tests.Enumeration @@ -32,11 +31,11 @@ namespace System.IO.Tests.Enumeration } } - [ActiveIssue(27244)] [Fact] public void CanRecurseFromRoot() { string root = Path.GetPathRoot(Path.GetTempPath()); + using (var recursed = new DirectoryRecursed(root, new EnumerationOptions { AttributesToSkip = FileAttributes.System, RecurseSubdirectories = true })) { while (recursed.MoveNext()) @@ -47,9 +46,10 @@ namespace System.IO.Tests.Enumeration return; } - // Should not get back a full path without a single separator (C:\foo.txt or /foo.txt) - int count = recursed.Current.Count(c => c == Path.DirectorySeparatorChar); - Assert.True(count <= 1, $"expected to find just one separator in '{recursed.Current}'"); + // Should start with the root and shouldn't have a separator after the root + Assert.StartsWith(root, recursed.Current); + Assert.True(recursed.Current.LastIndexOf(Path.DirectorySeparatorChar) < root.Length, + $"should have no separators pasth the root '{root}' in in '{recursed.Current}'"); } Assert.NotNull(recursed.LastDirectory); diff --git a/src/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj b/src/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj index 4bc153ab4a..c3b81a74b4 100644 --- a/src/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj +++ b/src/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj @@ -56,7 +56,7 @@ <Compile Include="Enumeration\ConstructionTests.netcoreapp.cs" /> <Compile Include="Enumeration\SpecialDirectoryTests.netcoreapp.cs" /> <Compile Include="Enumeration\SkipAttributeTests.netcoreapp.cs" /> - <Compile Include="Enumeration\Win32MatcherTests.netcoreapp.cs" /> + <Compile Include="Enumeration\FileSystemNameTests.netcoreapp.cs" /> <Compile Include="Enumeration\MatchCasingTests.netcoreapp.cs" /> <Compile Include="Enumeration\TrimmedPaths.netcoreapp.cs" /> <Compile Include="Enumeration\ErrorHandlingTests.netcoreapp.cs" /> |