Skip to content

Commit

Permalink
Revert daec9dc (PR dotnet#68582)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffhandley committed May 4, 2022
1 parent 15d8c86 commit 04a7fc5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,14 @@ 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 (directory.Length == 0) // empty directory means current working dir
if (string.IsNullOrWhiteSpace(name))
{
directory = ".";
_fullPath = PathInternal.EnsureTrailingSeparator(_fullPath);
}

string fullDirectoryPath = Path.GetFullPath(directory);
_fullPath = string.IsNullOrEmpty(name) ? PathInternal.EnsureTrailingSeparator(fullDirectoryPath) : Path.Join(fullDirectoryPath, name);
}

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

if (directory.Length == 0) // empty directory means current working dir
if (string.IsNullOrWhiteSpace(oldName))
{
directory = ".";
_oldFullPath = PathInternal.EnsureTrailingSeparator(_oldFullPath);
}

string fullDirectoryPath = Path.GetFullPath(directory);
_oldFullPath = string.IsNullOrEmpty(oldName) ? PathInternal.EnsureTrailingSeparator(fullDirectoryPath) : Path.Join(fullDirectoryPath, oldName);
}

/// <devdoc>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,8 @@ 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 @@ -40,16 +33,8 @@ public static void FileSystemEventArgs_ctor_DirectoryIsAbsolutePath_Windows(stri

[Theory]
[PlatformSpecific(TestPlatforms.AnyUnix)]
[InlineData("/", null, "/")]
[InlineData("/", "", "/")]
[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 @@ -59,32 +44,24 @@ 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);

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

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

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

[Theory]
Expand All @@ -103,6 +80,7 @@ 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,30 +47,24 @@ 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);

var expectedDirectory = PathInternal.EnsureTrailingSeparator(Path.Combine(Directory.GetCurrentDirectory(), directory));
Assert.Equal(Path.Combine(expectedDirectory, oldName), args.OldFullPath);
Assert.Equal(Path.Combine(Directory.GetCurrentDirectory(), directory, 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);

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

[Theory]
Expand All @@ -89,6 +83,7 @@ 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

0 comments on commit 04a7fc5

Please sign in to comment.