Skip to content

Commit

Permalink
Clearly separated unix and windows test cases
Browse files Browse the repository at this point in the history
Implemented most of the code review suggestions.

Fix dotnet#62606
  • Loading branch information
slask committed Jan 17, 2022
1 parent f28bf24 commit a025928
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,76 +7,94 @@ namespace System.IO.Tests
{
public class FileSystemEventArgsTests
{
[Fact]
public static void FileSystemEventArgs_ctor_ChangeType_IsSetCorrectly()
{
FileSystemEventArgs args = new FileSystemEventArgs(WatcherChangeTypes.Deleted, "bar", "foo.txt");
Assert.Equal(WatcherChangeTypes.Deleted, args.ChangeType);
}

[Theory]
[PlatformSpecific(TestPlatforms.Windows)]
[InlineData(WatcherChangeTypes.Changed, "D:\\", "foo.txt", "D:\\foo.txt")]
[InlineData(WatcherChangeTypes.Changed, "E:\\bar", "foo.txt", "E:\\bar\\foo.txt")]
[InlineData(WatcherChangeTypes.All, "D:\\", "foo.txt", "D:\\foo.txt")]
[InlineData(WatcherChangeTypes.All, "E:\\bar", "foo.txt", "E:\\bar\\foo.txt")]
public static void FileSystemEventArgs_ctor_AbsolutePaths(WatcherChangeTypes changeType, string directory, string name, string expectedFullPath)
[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(changeType, directory, name);
FileSystemEventArgs args = new FileSystemEventArgs(WatcherChangeTypes.All, directory, name);

Assert.Equal(changeType, args.ChangeType);
Assert.Equal(expectedFullPath, args.FullPath);
Assert.Equal(name, args.Name);
}

[Theory]
[PlatformSpecific(TestPlatforms.Windows)]
[InlineData(WatcherChangeTypes.Changed, "C:", "foo.txt")]
[InlineData(WatcherChangeTypes.All, "C:", "foo.txt")]
public static void FileSystemEventArgs_ctor_RelativePathFromCurrentDirectoryInGivenDrive(WatcherChangeTypes changeType, string directory, string name)
[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(changeType, directory, name);
FileSystemEventArgs args = new FileSystemEventArgs(WatcherChangeTypes.All, directory, name);

Assert.Equal(changeType, args.ChangeType);
Assert.Equal(AppendDirectorySeparator(Directory.GetCurrentDirectory()) + name, args.FullPath);
Assert.Equal(expectedFullPath, args.FullPath);
Assert.Equal(name, args.Name);
}

[Theory]
[InlineData(WatcherChangeTypes.Changed, "bar", "foo.txt")]
[InlineData(WatcherChangeTypes.Changed, "bar\\baz", "foo.txt")]
[InlineData(WatcherChangeTypes.All, "bar", "foo.txt")]
[InlineData(WatcherChangeTypes.All, "bar\\baz", "foo.txt")]
public static void FileSystemEventArgs_ctor_DirectoryIsRelativePath(WatcherChangeTypes changeType, string directory, string name)
[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(changeType, directory, name);
FileSystemEventArgs args = new FileSystemEventArgs(WatcherChangeTypes.All, directory, name);

directory = AppendDirectorySeparator(directory);

Assert.Equal(changeType, args.ChangeType);
Assert.Equal(AppendDirectorySeparator(Directory.GetCurrentDirectory()) + directory + name, args.FullPath);
Assert.Equal(name, args.Name);
}

[Fact]
public static void FileSystemEventArgs_ctor_Invalid_EmptyDirectory()
[Theory]
[PlatformSpecific(TestPlatforms.AnyUnix)]
[InlineData("bar", "foo.txt")]
[InlineData("bar/baz", "foo.txt")]
public static void FileSystemEventArgs_ctor_DirectoryIsRelativePath_Unix(string directory, string name)
{
Assert.Throws<ArgumentException>(() => new FileSystemEventArgs((WatcherChangeTypes)0, "", "foo.txt"));
FileSystemEventArgs args = new FileSystemEventArgs(WatcherChangeTypes.All, directory, name);

directory = AppendDirectorySeparator(directory);

Assert.Equal(AppendDirectorySeparator(Directory.GetCurrentDirectory()) + directory + name, args.FullPath);
Assert.Equal(name, args.Name);
}

[Fact]
public static void FileSystemEventArgs_ctor_Invalid_NullDirectory()
[Theory]
[PlatformSpecific(TestPlatforms.Windows)]
[InlineData("C:", "foo.txt")]
public static void FileSystemEventArgs_ctor_RelativePathFromCurrentDirectoryInGivenDrive(string directory, string name)
{
Assert.Throws<ArgumentNullException>(() => new FileSystemEventArgs((WatcherChangeTypes)0, null, "foo.txt"));
FileSystemEventArgs args = new FileSystemEventArgs(WatcherChangeTypes.All, directory, name);

Assert.Equal(AppendDirectorySeparator(Directory.GetCurrentDirectory()) + name, args.FullPath);
Assert.Equal(name, args.Name);
}

[Theory]
[InlineData(WatcherChangeTypes.All, "bar", "")]
[InlineData(WatcherChangeTypes.All, "bar", null)]
[InlineData(WatcherChangeTypes.Changed, "bar", "")]
[InlineData(WatcherChangeTypes.Changed, "bar", null)]
public static void FileSystemEventArgs_ctor_When_EmptyFileName_Then_FullPathReturnsTheDirectoryFullPath(WatcherChangeTypes changeType, string directory, string name)
[InlineData("bar", "")]
[InlineData("bar", null)]
public static void FileSystemEventArgs_ctor_When_EmptyFileName_Then_FullPathReturnsTheDirectoryFullPath(string directory, string name)
{
FileSystemEventArgs args = new FileSystemEventArgs(changeType, directory, name);
FileSystemEventArgs args = new FileSystemEventArgs(WatcherChangeTypes.All, directory, name);

Assert.Equal(changeType, args.ChangeType);
Assert.Equal(AppendDirectorySeparator(Directory.GetCurrentDirectory()) + directory, args.FullPath);
Assert.Equal(name, args.Name);
}

[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"));
}

#region Test Helpers

private static string AppendDirectorySeparator(string directory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,78 +23,90 @@ public static void RenamedEventArgs_ctor_NonPathPropertiesAreSetCorrectly(Watche

[Theory]
[PlatformSpecific(TestPlatforms.Windows)]
[InlineData(WatcherChangeTypes.Changed, "D:\\", "foo.txt", "bar.txt", "D:\\bar.txt")]
[InlineData(WatcherChangeTypes.Changed, "E:\\bar", "foo.txt", "bar.txt", "E:\\bar\\bar.txt")]
[InlineData(WatcherChangeTypes.All, "D:\\", "foo.txt", "bar.txt", "D:\\bar.txt")]
[InlineData(WatcherChangeTypes.All, "E:\\bar", "foo.txt", "bar.txt", "E:\\bar\\bar.txt")]
public static void RenamedEventArgs_ctor_OldFullPath_DirectoryIsAnAbsolutePath(WatcherChangeTypes changeType, string directory, string name, string oldName, string expectedOldFullPath)
[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(changeType, directory, name, oldName);
RenamedEventArgs args = new RenamedEventArgs(WatcherChangeTypes.All, directory, name, oldName);

Assert.Equal(changeType, args.ChangeType);
Assert.Equal(expectedOldFullPath, args.OldFullPath);
Assert.Equal(name, args.Name);
Assert.Equal(oldName, args.OldName);
}

[Theory]
[PlatformSpecific(TestPlatforms.Windows)]
[InlineData(WatcherChangeTypes.Changed, "C:", "foo.txt", "bar.txt")]
[InlineData(WatcherChangeTypes.All, "C:", "foo.txt", "bar.txt")]
public static void RenamedEventArgs_ctor_OldFullPath_DirectoryIsRelativePathFromCurrentDirectoryInGivenDrive(WatcherChangeTypes changeType, string directory, string name, string oldName)
[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(changeType, directory, name, oldName);
RenamedEventArgs args = new RenamedEventArgs(WatcherChangeTypes.All, directory, name, oldName);

Assert.Equal(changeType, args.ChangeType);
Assert.Equal(AppendDirectorySeparator(Directory.GetCurrentDirectory()) + oldName, args.OldFullPath);
Assert.Equal(expectedOldFullPath, args.OldFullPath);
Assert.Equal(name, args.Name);
Assert.Equal(oldName, args.OldName);
}

[Theory]
[InlineData(WatcherChangeTypes.Changed, "bar", "foo.txt", "bar.txt")]
[InlineData(WatcherChangeTypes.Changed, "bar\\baz", "foo.txt", "bar.txt")]
[InlineData(WatcherChangeTypes.All, "bar", "foo.txt", "bar.txt")]
[InlineData(WatcherChangeTypes.All, "bar\\baz", "foo.txt", "bar.txt")]
public static void RenamedEventArgs_ctor_OldFullPath_DirectoryIsRelativePath(WatcherChangeTypes changeType, string directory, string name, string oldName)
[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(changeType, directory, name, oldName);
RenamedEventArgs args = new RenamedEventArgs(WatcherChangeTypes.All, directory, name, oldName);

directory = AppendDirectorySeparator(directory);

Assert.Equal(changeType, args.ChangeType);
Assert.Equal(AppendDirectorySeparator(Directory.GetCurrentDirectory()) + directory + oldName, args.OldFullPath);
Assert.Equal(name, args.Name);
Assert.Equal(oldName, args.OldName);
}

[Fact]
public static void RenamedEventArgs_ctor_Invalid_EmptyDirectory()
[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)
{
Assert.Throws<ArgumentException>(() => new RenamedEventArgs((WatcherChangeTypes)0, "", "foo.txt", "bar.txt"));
RenamedEventArgs args = new RenamedEventArgs(WatcherChangeTypes.All, directory, name, oldName);

directory = AppendDirectorySeparator(directory);

Assert.Equal(AppendDirectorySeparator(Directory.GetCurrentDirectory()) + directory + oldName, args.OldFullPath);
Assert.Equal(name, args.Name);
Assert.Equal(oldName, args.OldName);
}

[Fact]
public static void RenamedEventArgs_ctor_Invalid_NullDirectory()
[Theory]
[PlatformSpecific(TestPlatforms.Windows)]
[InlineData("C:", "foo.txt", "bar.txt")]
public static void RenamedEventArgs_ctor_OldFullPath_DirectoryIsRelativePathFromCurrentDirectoryInGivenDrive(string directory, string name, string oldName)
{
Assert.Throws<ArgumentNullException>(() => new RenamedEventArgs((WatcherChangeTypes)0, null, "foo.txt", "bar.txt"));
RenamedEventArgs args = new RenamedEventArgs(WatcherChangeTypes.All, directory, name, oldName);

Assert.Equal(AppendDirectorySeparator(Directory.GetCurrentDirectory()) + oldName, args.OldFullPath);
Assert.Equal(name, args.Name);
}

[Theory]
[InlineData(WatcherChangeTypes.All, "bar", "", "")]
[InlineData(WatcherChangeTypes.All, "bar", null, null)]
[InlineData(WatcherChangeTypes.Changed, "bar", "", "")]
[InlineData(WatcherChangeTypes.Changed, "bar", null, null)]
[InlineData(WatcherChangeTypes.All, "bar", "foo.txt", "")]
[InlineData(WatcherChangeTypes.Changed, "bar", "foo.txt", null)]
public static void RenamedEventArgs_ctor_When_EmptyOldFileName_Then_OldFullPathReturnsTheDirectoryFullPath(WatcherChangeTypes changeType, string directory, string name, string oldName)
[InlineData( "bar", "", "")]
[InlineData( "bar", null, null)]
[InlineData( "bar", "foo.txt", null)]
public static void RenamedEventArgs_ctor_When_EmptyOldFileName_Then_OldFullPathReturnsTheDirectoryFullPath(string directory, string name, string oldName)
{
RenamedEventArgs args = new RenamedEventArgs(changeType, directory, name, oldName);
RenamedEventArgs args = new RenamedEventArgs(WatcherChangeTypes.All, directory, name, oldName);

Assert.Equal(changeType, args.ChangeType);
Assert.Equal(AppendDirectorySeparator(Directory.GetCurrentDirectory()) + directory, args.OldFullPath);
Assert.Equal(name, args.Name);
}

[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"));
}

#region Test Helpers

private static string AppendDirectorySeparator(string directory)
Expand Down

0 comments on commit a025928

Please sign in to comment.