forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileSystemWatcher.Directory.Create.cs
More file actions
122 lines (104 loc) · 4.89 KB
/
FileSystemWatcher.Directory.Create.cs
File metadata and controls
122 lines (104 loc) · 4.89 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// 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 Xunit;
namespace System.IO.Tests
{
public class Directory_Create_Tests : FileSystemWatcherTest
{
[Fact]
public void FileSystemWatcher_Directory_EmptyPath()
{
Assert.Throws<ArgumentException>(() =>
{
using (var watcher = new FileSystemWatcher(""))
{
}
});
}
[Fact]
public void FileSystemWatcher_Directory_PathNotExists()
{
Assert.Throws<ArgumentException>(() =>
{
using (var watcher = new FileSystemWatcher(GetTestFilePath()))
{
}
});
}
[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/103584", TestPlatforms.Windows)]
public void FileSystemWatcher_Directory_Create()
{
using (var watcher = new FileSystemWatcher(TestDirectory))
{
string dirName = Path.Combine(TestDirectory, "dir");
watcher.Filter = Path.GetFileName(dirName);
Action action = () => Directory.CreateDirectory(dirName);
Action cleanup = () => Directory.Delete(dirName);
ExpectEvent(watcher, WatcherChangeTypes.Created, action, cleanup, dirName);
}
}
[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/103630", TestPlatforms.Windows)]
public void FileSystemWatcher_Directory_Create_InNestedDirectory()
{
string nestedDir = CreateTestDirectory(TestDirectory, "dir1", "nested");
using (var watcher = new FileSystemWatcher(TestDirectory, "*"))
{
watcher.IncludeSubdirectories = true;
watcher.NotifyFilter = NotifyFilters.DirectoryName;
string dirName = Path.Combine(nestedDir, "dir");
Action action = () => Directory.CreateDirectory(dirName);
Action cleanup = () => Directory.Delete(dirName);
ExpectEvent(watcher, WatcherChangeTypes.Created, action, cleanup, dirName);
}
}
[Fact]
[OuterLoop("This test has a longer than average timeout and may fail intermittently")]
public void FileSystemWatcher_Directory_Create_DeepDirectoryStructure()
{
string deepDir = CreateTestDirectory(TestDirectory, "dir", "dir", "dir", "dir", "dir", "dir", "dir");
using (var watcher = new FileSystemWatcher(TestDirectory, "*"))
{
watcher.IncludeSubdirectories = true;
watcher.NotifyFilter = NotifyFilters.DirectoryName;
// Put a directory at the very bottom and expect it to raise an event
string dirPath = Path.Combine(deepDir, "leafdir");
Action action = () => Directory.CreateDirectory(dirPath);
Action cleanup = () => Directory.Delete(dirPath);
ExpectEvent(watcher, WatcherChangeTypes.Created, action, cleanup, dirPath, LongWaitTimeout);
}
}
[ConditionalFact(typeof(MountHelper), nameof(MountHelper.CanCreateSymbolicLinks))]
public void FileSystemWatcher_Directory_Create_SymLink()
{
string dir = CreateTestDirectory(TestDirectory, "dir");
string temp = CreateTestDirectory();
using (var watcher = new FileSystemWatcher(Path.GetFullPath(dir), "*"))
{
// Make the symlink in our path (to the temp folder) and make sure an event is raised
string symLinkPath = Path.Combine(dir, GetRandomLinkName());
Action action = () => Assert.True(MountHelper.CreateSymbolicLink(symLinkPath, temp, true));
Action cleanup = () => Directory.Delete(symLinkPath);
ExpectEvent(watcher, WatcherChangeTypes.Created, action, cleanup, symLinkPath);
}
}
[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/103584", TestPlatforms.Windows)]
public void FileSystemWatcher_Directory_Create_SynchronizingObject()
{
using (var watcher = new FileSystemWatcher(TestDirectory))
{
TestISynchronizeInvoke invoker = new TestISynchronizeInvoke();
watcher.SynchronizingObject = invoker;
string dirName = Path.Combine(TestDirectory, "dir");
watcher.Filter = Path.GetFileName(dirName);
Action action = () => Directory.CreateDirectory(dirName);
Action cleanup = () => Directory.Delete(dirName);
ExpectEvent(watcher, WatcherChangeTypes.Created, action, cleanup, dirName);
Assert.True(invoker.BeginInvoke_Called);
}
}
}
}