-
-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathPathHelpersTests.cs
More file actions
95 lines (80 loc) · 3.47 KB
/
Copy pathPathHelpersTests.cs
File metadata and controls
95 lines (80 loc) · 3.47 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
using ModularPipelines.FileSystem;
using ModularPipelines.Helpers;
using ModularPipelines.UnitTests.Extensions;
namespace ModularPipelines.UnitTests;
public class PathHelpersTests
{
[Test]
public async Task Get_Directory()
{
var outputDirectory = new DirectoryInfo(new Folder(TestContext.WorkingDirectory).FindAncestorContainingProject()!);
var fooTxt = outputDirectory.EnumerateFiles("*Foo.txt", SearchOption.AllDirectories).First();
await Assert.That(fooTxt.FullName.GetDirectory()).IsEqualTo(fooTxt.Directory!.FullName);
}
[Test]
public async Task File_Path_Type()
{
var outputDirectory = new DirectoryInfo(new Folder(TestContext.WorkingDirectory).FindAncestorContainingProject()!);
var fooTxt = outputDirectory.EnumerateFiles("*Foo.txt", SearchOption.AllDirectories).First();
await Assert.That(fooTxt.FullName.GetPathType()).IsEqualTo(PathType.File);
}
[Test]
public async Task File_Path_Type2()
{
var path = Path.Combine(TestContext.WorkingDirectory, "Blah", "Foo", "Bar", "Foo.txt");
await Assert.That(path.GetPathType()).IsEqualTo(PathType.File);
}
[Test]
public async Task Directory_Path_Type()
{
var outputDirectory = new DirectoryInfo(TestContext.WorkingDirectory);
await Assert.That(outputDirectory.FullName.GetPathType()).IsEqualTo(PathType.Directory);
}
[Test]
public async Task Directory_Path_Type2()
{
var path = Path.Combine(TestContext.WorkingDirectory, "Blah", "Foo", "Bar", "Foo");
await Assert.That(path.GetPathType()).IsEqualTo(PathType.Directory);
}
[Test]
public async Task Directory_Path_Type_With_Trailing_Separator()
{
var path = Path.Combine(TestContext.WorkingDirectory, "Blah", "Foo") + Path.DirectorySeparatorChar;
await Assert.That(path.GetPathType()).IsEqualTo(PathType.Directory);
}
[Test]
public async Task Directory_Path_Type_With_Dots_And_Trailing_Separator()
{
// A directory with dots in the name should be detected as directory when it has a trailing separator
var path = Path.Combine(TestContext.WorkingDirectory, "my.folder") + Path.DirectorySeparatorChar;
await Assert.That(path.GetPathType()).IsEqualTo(PathType.Directory);
}
[Test]
public async Task EndsWithDirectorySeparator_Returns_True_For_Trailing_Separator()
{
var path = Path.Combine(TestContext.WorkingDirectory, "foo") + Path.DirectorySeparatorChar;
await Assert.That(PathHelpers.EndsWithDirectorySeparator(path)).IsTrue();
}
[Test]
public async Task EndsWithDirectorySeparator_Returns_True_For_Alt_Separator()
{
var path = Path.Combine(TestContext.WorkingDirectory, "foo") + Path.AltDirectorySeparatorChar;
await Assert.That(PathHelpers.EndsWithDirectorySeparator(path)).IsTrue();
}
[Test]
public async Task EndsWithDirectorySeparator_Returns_False_For_No_Separator()
{
var path = Path.Combine(TestContext.WorkingDirectory, "foo");
await Assert.That(PathHelpers.EndsWithDirectorySeparator(path)).IsFalse();
}
[Test]
public async Task EndsWithDirectorySeparator_Returns_False_For_Empty_String()
{
await Assert.That(PathHelpers.EndsWithDirectorySeparator(string.Empty)).IsFalse();
}
[Test]
public async Task EndsWithDirectorySeparator_Returns_False_For_Null()
{
await Assert.That(PathHelpers.EndsWithDirectorySeparator(null!)).IsFalse();
}
}