-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
SpecialDirectoryTests.cs
82 lines (69 loc) · 2.84 KB
/
SpecialDirectoryTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections.Generic;
using System.IO.Enumeration;
using System.Linq;
using Xunit;
namespace System.IO.Tests.Enumeration
{
public class SpecialDirectoryTests : FileSystemTest
{
private class DirectoryRecursed : FileSystemEnumerator<string>
{
public int ShouldRecurseCalls { get; private set; }
public DirectoryRecursed(string directory, EnumerationOptions options)
: base(directory, options)
{
}
protected override string TransformEntry(ref FileSystemEntry entry)
=>new string(entry.FileName);
protected override bool ShouldRecurseIntoEntry(ref FileSystemEntry entry)
{
ShouldRecurseCalls++;
return base.ShouldRecurseIntoEntry(ref entry);
}
}
[Fact]
public void SpecialDirectoriesAreNotUpForRecursion()
{
using (var recursed = new DirectoryRecursed(TestDirectory, new EnumerationOptions { ReturnSpecialDirectories = true, RecurseSubdirectories = true, AttributesToSkip = 0 }))
{
List<string> results = new List<string>();
while (recursed.MoveNext())
results.Add(recursed.Current);
Assert.Equal(0, recursed.ShouldRecurseCalls);
Assert.Contains("..", results);
}
}
}
public class SpecialDirectoryTests_Enumerable : FileSystemTest
{
protected virtual string[] GetNames(string directory, EnumerationOptions options)
{
return new FileSystemEnumerable<string>(
directory,
(ref FileSystemEntry entry) => new string(entry.FileName),
options).ToArray();
}
[Fact]
public void SkippingHiddenFiles()
{
// Files that begin with periods are considered hidden on Unix
string[] paths = GetNames(TestDirectory, new EnumerationOptions { ReturnSpecialDirectories = true, AttributesToSkip = 0 });
if (!PlatformDetection.IsWindows10Version22000OrGreater)
{
// Sometimes this is not returned - presumably an OS bug.
// This occurs often on Windows 11, very rarely otherwise.
Assert.Contains(".", paths);
}
Assert.Contains("..", paths);
}
}
public class SpecialDirectoryTests_DirectoryInfo_GetDirectories : SpecialDirectoryTests_Enumerable
{
protected override string[] GetNames(string directory, EnumerationOptions options)
{
return new DirectoryInfo(directory).GetDirectories("*", options).Select(i => i.Name).ToArray();
}
}
}