forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArgs.RenamedEventArgs.cs
More file actions
103 lines (84 loc) · 4.9 KB
/
Args.RenamedEventArgs.cs
File metadata and controls
103 lines (84 loc) · 4.9 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
// 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 RenamedEventArgsTests
{
[Theory]
[InlineData(WatcherChangeTypes.Changed, "C:\\bar", "foo.txt", "bar.txt")]
[InlineData(WatcherChangeTypes.All, "C:\\bar", "foo.txt", "bar.txt")]
[InlineData((WatcherChangeTypes)0, "C:\\bar", "", "")]
[InlineData((WatcherChangeTypes)0, "C:\\bar", null, null)]
public static void RenamedEventArgs_ctor_NonPathPropertiesAreSetCorrectly(WatcherChangeTypes changeType, string directory, string name, string oldName)
{
RenamedEventArgs args = new RenamedEventArgs(changeType, directory, name, oldName);
Assert.Equal(changeType, args.ChangeType);
Assert.Equal(name, args.Name);
Assert.Equal(oldName, args.OldName);
// FullPath is tested as part of the base class FileSystemEventArgs tests
}
[Theory]
[PlatformSpecific(TestPlatforms.Windows)]
[InlineData("D:\\", "foo.txt", "bar.txt", "D:\\bar.txt")]
[InlineData("E:\\bar", "foo.txt", "bar.txt", "E:\\bar\\bar.txt")]
public static void RenamedEventArgs_ctor_OldFullPath_DirectoryIsAnAbsolutePath_Windows(string directory, string name, string oldName, string expectedOldFullPath)
{
RenamedEventArgs args = new RenamedEventArgs(WatcherChangeTypes.All, directory, name, oldName);
Assert.Equal(expectedOldFullPath, args.OldFullPath);
}
[Theory]
[PlatformSpecific(TestPlatforms.AnyUnix)]
[InlineData("/", "foo.txt", "bar.txt", "/bar.txt")]
[InlineData("/bar", "foo.txt", "bar.txt", "/bar/bar.txt")]
public static void RenamedEventArgs_ctor_OldFullPath_DirectoryIsAnAbsolutePath_Unix(string directory, string name, string oldName, string expectedOldFullPath)
{
RenamedEventArgs args = new RenamedEventArgs(WatcherChangeTypes.All, directory, name, oldName);
Assert.Equal(expectedOldFullPath, args.OldFullPath);
}
[Theory]
[PlatformSpecific(TestPlatforms.Windows)]
[InlineData("bar", "foo.txt", "bar.txt")]
[InlineData("bar\\baz", "foo.txt", "bar.txt")]
public static void RenamedEventArgs_ctor_OldFullPath_DirectoryIsRelativePath_Windows(string directory, string name, string oldName)
{
RenamedEventArgs args = new RenamedEventArgs(WatcherChangeTypes.All, directory, name, oldName);
directory = PathInternal.EnsureTrailingSeparator(directory);
Assert.Equal(PathInternal.EnsureTrailingSeparator(Directory.GetCurrentDirectory()) + directory + oldName, args.OldFullPath);
}
[Theory]
[PlatformSpecific(TestPlatforms.AnyUnix)]
[InlineData("bar", "foo.txt", "bar.txt")]
[InlineData("bar/baz", "foo.txt", "bar.txt")]
public static void RenamedEventArgs_ctor_OldFullPath_DirectoryIsRelativePath_Unix(string directory, string name, string oldName)
{
RenamedEventArgs args = new RenamedEventArgs(WatcherChangeTypes.All, directory, name, oldName);
directory = PathInternal.EnsureTrailingSeparator(directory);
Assert.Equal(PathInternal.EnsureTrailingSeparator(Directory.GetCurrentDirectory()) + directory + oldName, args.OldFullPath);
}
[Theory]
[PlatformSpecific(TestPlatforms.Windows)]
[InlineData("C:", "foo.txt", "bar.txt")]
public static void RenamedEventArgs_ctor_OldFullPath_DirectoryIsRelativePathFromCurrentDirectoryInGivenDrive(string directory, string name, string oldName)
{
RenamedEventArgs args = new RenamedEventArgs(WatcherChangeTypes.All, directory, name, oldName);
Assert.Equal(PathInternal.EnsureTrailingSeparator(Directory.GetCurrentDirectory()) + oldName, args.OldFullPath);
}
[Theory]
[InlineData( "bar", "", "")]
[InlineData( "bar", null, null)]
[InlineData( "bar", "foo.txt", null)]
public static void RenamedEventArgs_ctor_When_EmptyOldFileName_Then_OldFullPathReturnsTheDirectoryFullPath_WithTrailingSeparator(string directory, string name, string oldName)
{
RenamedEventArgs args = new RenamedEventArgs(WatcherChangeTypes.All, directory, name, oldName);
directory = PathInternal.EnsureTrailingSeparator(directory);
Assert.Equal(PathInternal.EnsureTrailingSeparator(Directory.GetCurrentDirectory()) + directory, args.OldFullPath);
}
[Fact]
public static void RenamedEventArgs_ctor_Invalid()
{
Assert.Throws<ArgumentException>(() => new RenamedEventArgs((WatcherChangeTypes)0, "", "foo.txt", "bar.txt"));
Assert.Throws<ArgumentNullException>(() => new RenamedEventArgs((WatcherChangeTypes)0, null, "foo.txt", "bar.txt"));
}
}
}