Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ public class FileSystemEventArgs : EventArgs
/// </devdoc>
public FileSystemEventArgs(WatcherChangeTypes changeType, string directory, string? name)
{
ArgumentNullException.ThrowIfNull(directory);

_changeType = changeType;
_name = name;
_fullPath = Path.Join(Path.GetFullPath(directory), name);

if (string.IsNullOrWhiteSpace(name))
_fullPath = Path.GetFullPath((string.IsNullOrWhiteSpace(directory), string.IsNullOrWhiteSpace(name)) switch
{
_fullPath = PathInternal.EnsureTrailingSeparator(_fullPath);
}
(true, true) => "." + PathInternal.DirectorySeparatorCharAsString,
(true, false) => name!,
(false, true) => PathInternal.EnsureTrailingSeparator(directory),
(false, false) => Path.Join(directory, name),
});
}

/// <devdoc>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ public RenamedEventArgs(WatcherChangeTypes changeType, string directory, string?
: base(changeType, directory, name)
{
_oldName = oldName;
_oldFullPath = Path.Join(Path.GetFullPath(directory), oldName);

if (string.IsNullOrWhiteSpace(oldName))
_oldFullPath = Path.GetFullPath((string.IsNullOrWhiteSpace(directory), string.IsNullOrWhiteSpace(oldName)) switch
{
_oldFullPath = PathInternal.EnsureTrailingSeparator(_oldFullPath);
}
(true, true) => "." + PathInternal.DirectorySeparatorCharAsString,
(true, false) => oldName!,
(false, true) => PathInternal.EnsureTrailingSeparator(directory),
(false, false) => Path.Join(directory, oldName),
});
}

/// <devdoc>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@ public static void FileSystemEventArgs_ctor_NonPathPropertiesAreSetCorrectly(Wat

[Theory]
[PlatformSpecific(TestPlatforms.Windows)]
[InlineData("D:\\", null, "D:\\")]
[InlineData("D:\\", "", "D:\\")]
[InlineData("D:\\", "foo.txt", "D:\\foo.txt")]
[InlineData("E:\\bar", null, "E:\\bar\\")]
[InlineData("E:\\bar", "", "E:\\bar\\")]
[InlineData("E:\\bar", "foo.txt", "E:\\bar\\foo.txt")]
[InlineData("E:\\bar\\", null, "E:\\bar\\")]
[InlineData("E:\\bar\\", "", "E:\\bar\\")]
[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);
Expand All @@ -33,8 +40,15 @@ public static void FileSystemEventArgs_ctor_DirectoryIsAbsolutePath_Windows(stri

[Theory]
[PlatformSpecific(TestPlatforms.AnyUnix)]
[InlineData("/", null, "/")]
[InlineData("/", "", "/")]
[InlineData("/", "foo.txt", "/foo.txt")]
[InlineData("/bar", null, "/bar/")]
[InlineData("/bar", "", "/bar/")]
[InlineData("/bar", "foo.txt", "/bar/foo.txt")]
[InlineData("/bar/", null, "/bar/")]
[InlineData("/bar/", "", "/bar/")]
[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);
Expand All @@ -44,24 +58,30 @@ public static void FileSystemEventArgs_ctor_DirectoryIsAbsolutePath_Unix(string

[Theory]
[PlatformSpecific(TestPlatforms.Windows)]
[InlineData("", "")]
[InlineData("", "foo.txt")]
[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);

Assert.Equal(Path.Combine(Directory.GetCurrentDirectory(), directory, name), args.FullPath);
var expectedDirectory = PathInternal.EnsureTrailingSeparator(Path.Combine(Directory.GetCurrentDirectory(), directory));
Assert.Equal(Path.Combine(expectedDirectory, name), args.FullPath);
}

[Theory]
[PlatformSpecific(TestPlatforms.AnyUnix)]
[InlineData("", "")]
[InlineData("", "foo.txt")]
[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);

Assert.Equal(Path.Combine(Directory.GetCurrentDirectory(), directory, name), args.FullPath);
var expectedDirectory = PathInternal.EnsureTrailingSeparator(Path.Combine(Directory.GetCurrentDirectory(), directory));
Assert.Equal(Path.Combine(expectedDirectory, name), args.FullPath);
}

[Theory]
Expand All @@ -80,7 +100,6 @@ public static void FileSystemEventArgs_ctor_When_EmptyFileName_Then_FullPathRetu
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"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,30 @@ public static void RenamedEventArgs_ctor_OldFullPath_DirectoryIsAnAbsolutePath_U

[Theory]
[PlatformSpecific(TestPlatforms.Windows)]
[InlineData("", "", "")]
[InlineData("", "foo.txt", "bar.txt")]
[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);

Assert.Equal(Path.Combine(Directory.GetCurrentDirectory(), directory, oldName), args.OldFullPath);
var expectedDirectory = PathInternal.EnsureTrailingSeparator(Path.Combine(Directory.GetCurrentDirectory(), directory));
Assert.Equal(Path.Combine(expectedDirectory, oldName), args.OldFullPath);
}

[Theory]
[PlatformSpecific(TestPlatforms.AnyUnix)]
[InlineData("", "", "")]
[InlineData("", "foo.txt", "bar.txt")]
[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);

Assert.Equal(Path.Combine(Directory.GetCurrentDirectory(), directory, oldName), args.OldFullPath);
var expectedDirectory = PathInternal.EnsureTrailingSeparator(Path.Combine(Directory.GetCurrentDirectory(), directory));
Assert.Equal(Path.Combine(expectedDirectory, oldName), args.OldFullPath);
}

[Theory]
Expand All @@ -83,7 +89,6 @@ public static void RenamedEventArgs_ctor_When_EmptyOldFileName_Then_OldFullPathR
[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"));
}
}
Expand Down