forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArgs.FileSystemEventArgs.cs
More file actions
100 lines (81 loc) · 4.35 KB
/
Args.FileSystemEventArgs.cs
File metadata and controls
100 lines (81 loc) · 4.35 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
96
97
98
99
100
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Xunit;
namespace System.IO.Tests
{
public class FileSystemEventArgsTests
{
[Theory]
[InlineData(WatcherChangeTypes.Changed, "C:\\bar", "foo.txt")]
[InlineData(WatcherChangeTypes.All, "C:\\bar", "foo.txt")]
[InlineData((WatcherChangeTypes)0, "C:\\bar", "")]
[InlineData((WatcherChangeTypes)0, "C:\\bar", null)]
public static void FileSystemEventArgs_ctor_NonPathPropertiesAreSetCorrectly(WatcherChangeTypes changeType, string directory, string name)
{
FileSystemEventArgs args = new FileSystemEventArgs(changeType, directory, name);
Assert.Equal(changeType, args.ChangeType);
Assert.Equal(name, args.Name);
}
[Theory]
[PlatformSpecific(TestPlatforms.Windows)]
[InlineData("D:\\", "foo.txt", "D:\\foo.txt")]
[InlineData("E:\\bar", "foo.txt", "E:\\bar\\foo.txt")]
public static void FileSystemEventArgs_ctor_DirectoryIsAbsolutePath_Windows(string directory, string name, string expectedFullPath)
{
FileSystemEventArgs args = new FileSystemEventArgs(WatcherChangeTypes.All, directory, name);
Assert.Equal(expectedFullPath, args.FullPath);
}
[Theory]
[PlatformSpecific(TestPlatforms.AnyUnix)]
[InlineData("/", "foo.txt", "/foo.txt")]
[InlineData("/bar", "foo.txt", "/bar/foo.txt")]
public static void FileSystemEventArgs_ctor_DirectoryIsAbsolutePath_Unix(string directory, string name, string expectedFullPath)
{
FileSystemEventArgs args = new FileSystemEventArgs(WatcherChangeTypes.All, directory, name);
Assert.Equal(expectedFullPath, args.FullPath);
}
[Theory]
[PlatformSpecific(TestPlatforms.Windows)]
[InlineData("bar", "foo.txt")]
[InlineData("bar\\baz", "foo.txt")]
public static void FileSystemEventArgs_ctor_DirectoryIsRelativePath_Windows(string directory, string name)
{
FileSystemEventArgs args = new FileSystemEventArgs(WatcherChangeTypes.All, directory, name);
directory = PathInternal.EnsureTrailingSeparator(directory);
Assert.Equal(PathInternal.EnsureTrailingSeparator(Directory.GetCurrentDirectory()) + directory + name, args.FullPath);
}
[Theory]
[PlatformSpecific(TestPlatforms.AnyUnix)]
[InlineData("bar", "foo.txt")]
[InlineData("bar/baz", "foo.txt")]
public static void FileSystemEventArgs_ctor_DirectoryIsRelativePath_Unix(string directory, string name)
{
FileSystemEventArgs args = new FileSystemEventArgs(WatcherChangeTypes.All, directory, name);
directory = PathInternal.EnsureTrailingSeparator(directory);
Assert.Equal(PathInternal.EnsureTrailingSeparator(Directory.GetCurrentDirectory()) + directory + name, args.FullPath);
}
[Theory]
[PlatformSpecific(TestPlatforms.Windows)]
[InlineData("C:", "foo.txt")]
public static void FileSystemEventArgs_ctor_RelativePathFromCurrentDirectoryInGivenDrive(string directory, string name)
{
FileSystemEventArgs args = new FileSystemEventArgs(WatcherChangeTypes.All, directory, name);
Assert.Equal(PathInternal.EnsureTrailingSeparator(Directory.GetCurrentDirectory()) + name, args.FullPath);
}
[Theory]
[InlineData("bar", "")]
[InlineData("bar", null)]
public static void FileSystemEventArgs_ctor_When_EmptyFileName_Then_FullPathReturnsTheDirectoryFullPath_WithTrailingSeparator(string directory, string name)
{
FileSystemEventArgs args = new FileSystemEventArgs(WatcherChangeTypes.All, directory, name);
directory = PathInternal.EnsureTrailingSeparator(directory);
Assert.Equal(PathInternal.EnsureTrailingSeparator(Directory.GetCurrentDirectory()) + directory, args.FullPath);
}
[Fact]
public static void FileSystemEventArgs_ctor_Invalid()
{
Assert.Throws<ArgumentNullException>(() => new FileSystemEventArgs((WatcherChangeTypes)0, null, "foo.txt"));
Assert.Throws<ArgumentException>(() => new FileSystemEventArgs((WatcherChangeTypes)0, "", "foo.txt"));
}
}
}