Skip to content

Commit

Permalink
refactor: Convert Classic Assert to Constraint Model (#1065)
Browse files Browse the repository at this point in the history
Convert NUnit asserts to the constraint model, to simplify the [migration to NUnit v4](https://docs.nunit.org/articles/nunit/release-notes/Nunit4.0-MigrationGuide.html).
  • Loading branch information
vbreuss committed Dec 7, 2023
1 parent 81f4082 commit 6dceee2
Show file tree
Hide file tree
Showing 53 changed files with 470 additions and 513 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void MyComponent_Validate_ShouldThrowNotSupportedExceptionIfTestingIsNotA
catch (NotSupportedException ex)
{
// Assert
Assert.AreEqual("We can't go on together. It's not me, it's you.", ex.Message);
Assert.That(ex.Message, Is.EqualTo("We can't go on together. It's not me, it's you."));
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void Operations_ShouldThrowArgumentNullExceptionIfPathIsNull(Action<IDire

// Assert
var exception = Assert.Throws<ArgumentNullException>(wrapped);
Assert.AreEqual("path", exception.ParamName);
Assert.That(exception.ParamName, Is.EqualTo("path"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public void MockDirectoryInfoFactory_Wrap_WithNull_ShouldReturnNull()

var result = fileSystem.DirectoryInfo.Wrap(null);

Assert.IsNull(result);
Assert.That(result, Is.Null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void MockDirectoryInfo_ResolveLinkTarget_ShouldReturnPathOfTargetLink()

var result = fileSystem.DirectoryInfo.New("foo").ResolveLinkTarget(false);

Assert.AreEqual("bar", result.Name);
Assert.That(result.Name, Is.EqualTo("bar"));
}

[Test]
Expand All @@ -36,7 +36,7 @@ public void MockDirectoryInfo_ResolveLinkTarget_WithFinalTarget_ShouldReturnPath

var result = fileSystem.DirectoryInfo.New("foo1").ResolveLinkTarget(true);

Assert.AreEqual("bar", result.Name);
Assert.That(result.Name, Is.EqualTo("bar"));
}

[Test]
Expand All @@ -49,7 +49,7 @@ public void MockDirectoryInfo_ResolveLinkTarget_WithoutFinalTarget_ShouldReturnF

var result = fileSystem.DirectoryInfo.New("foo1").ResolveLinkTarget(false);

Assert.AreEqual("foo", result.Name);
Assert.That(result.Name, Is.EqualTo("foo"));
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static IEnumerable<object[]> MockDirectoryInfo_GetExtension_Cases
}
}

[TestCaseSource("MockDirectoryInfo_GetExtension_Cases")]
[TestCaseSource(nameof(MockDirectoryInfo_GetExtension_Cases))]
public void MockDirectoryInfo_GetExtension_ShouldReturnEmptyString(string directoryPath)
{
// Arrange
Expand All @@ -30,7 +30,7 @@ public void MockDirectoryInfo_GetExtension_ShouldReturnEmptyString(string direct
var result = directoryInfo.Extension;

// Assert
Assert.AreEqual(string.Empty, result);
Assert.That(result, Is.Empty);
}

public static IEnumerable<object[]> MockDirectoryInfo_Exists_Cases
Expand All @@ -42,7 +42,7 @@ public static IEnumerable<object[]> MockDirectoryInfo_Exists_Cases
}
}

[TestCaseSource("MockDirectoryInfo_Exists_Cases")]
[TestCaseSource(nameof(MockDirectoryInfo_Exists_Cases))]
public void MockDirectoryInfo_Exists(string path, bool expected)
{
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
Expand Down Expand Up @@ -106,7 +106,7 @@ public void MockDirectoryInfo_GetFiles_ShouldWorkWithUNCPath()
var files = directoryInfo.GetFiles();

// Assert
Assert.AreEqual(fileName, files[0].FullName);
Assert.That(files[0].FullName, Is.EqualTo(fileName));
}

[Test]
Expand All @@ -129,7 +129,7 @@ public void MockDirectoryInfo_GetFiles_ShouldWorkWithUNCPath_WhenCurrentDirector
var files = directoryInfo.GetFiles();

// Assert
Assert.AreEqual(fileName, files[0].FullName);
Assert.That(files[0].FullName, Is.EqualTo(fileName));
}

[Test]
Expand Down Expand Up @@ -263,7 +263,7 @@ public void MockDirectoryInfo_GetParent_ShouldReturnDirectoriesAndNamesWithSearc
var result = directoryInfo.Parent;

// Assert
Assert.AreEqual(XFS.Path(@"c:\a\b"), result.FullName);
Assert.That(result.FullName, Is.EqualTo(XFS.Path(@"c:\a\b")));
}

[Test]
Expand All @@ -287,7 +287,7 @@ public void MockDirectoryInfo_EnumerateFiles_ShouldReturnAllFiles()
var directoryInfo = new MockDirectoryInfo(fileSystem, XFS.Path(@"c:\temp\folder"));

// Assert
Assert.AreEqual(new[] { "b.txt", "c.txt" }, directoryInfo.EnumerateFiles().ToList().Select(x => x.Name).ToArray());
Assert.That(directoryInfo.EnumerateFiles().ToList().Select(x => x.Name).ToArray(), Is.EqualTo(new[] { "b.txt", "c.txt" }));
}

[Test]
Expand All @@ -309,7 +309,7 @@ public void MockDirectoryInfo_EnumerateDirectories_ShouldReturnAllDirectories()
var directories = directoryInfo.EnumerateDirectories().Select(a => a.Name).ToArray();

// Assert
Assert.AreEqual(new[] { "b", "c" }, directories);
Assert.That(directories, Is.EqualTo(new[] { "b", "c" }));
}

[TestCase(@"\\unc\folder", @"\\unc\folder")]
Expand All @@ -327,7 +327,7 @@ public void MockDirectoryInfo_FullName_ShouldReturnNormalizedUNCPath(string dire
var actualFullName = directoryInfo.FullName;

// Assert
Assert.AreEqual(expectedFullName, actualFullName);
Assert.That(actualFullName, Is.EqualTo(expectedFullName));
}

[TestCase(@"c:\temp\\folder", @"c:\temp\folder")]
Expand All @@ -345,7 +345,7 @@ public void MockDirectoryInfo_FullName_ShouldReturnNormalizedPath(string directo
var actualFullName = directoryInfo.FullName;

// Assert
Assert.AreEqual(expectedFullName, actualFullName);
Assert.That(actualFullName, Is.EqualTo(expectedFullName));
}

[TestCase(@"c:\temp\folder ", @"c:\temp\folder")]
Expand All @@ -360,7 +360,7 @@ public void MockDirectoryInfo_FullName_ShouldReturnPathWithTrimmedTrailingSpaces
var actualFullName = directoryInfo.FullName;

// Assert
Assert.AreEqual(expectedFullName, actualFullName);
Assert.That(actualFullName, Is.EqualTo(expectedFullName));
}

[Test]
Expand All @@ -377,7 +377,7 @@ public void MockDirectoryInfo_MoveTo_ShouldUpdateFullName()
directoryInfo.MoveTo(destination);

// Assert
Assert.AreEqual(destination, directoryInfo.FullName);
Assert.That(directoryInfo.FullName, Is.EqualTo(destination));
}

[TestCase(@"c:\temp\\folder ", @"folder")]
Expand All @@ -392,7 +392,7 @@ public void MockDirectoryInfo_Name_ShouldReturnNameWithTrimmedTrailingSpaces(str
var actualName = directoryInfo.Name;

// Assert
Assert.AreEqual(expectedName, actualName);
Assert.That(actualName, Is.EqualTo(expectedName));
}

[TestCase(@"c:\", @"c:\")]
Expand All @@ -407,7 +407,7 @@ public void MockDirectoryInfo_Name_ShouldReturnPathRoot_IfDirectoryPathIsPathRoo
var actualName = directoryInfo.Name;

// Assert
Assert.AreEqual(expectedName, actualName);
Assert.That(actualName, Is.EqualTo(expectedName));
}

[Test]
Expand Down Expand Up @@ -462,7 +462,7 @@ public void MockDirectoryInfo_ToString_ShouldReturnDirectoryName(string director
var mockDirectoryInfo = new MockDirectoryInfo(new MockFileSystem(), directoryPath);

// Assert
Assert.AreEqual(directoryPath, mockDirectoryInfo.ToString());
Assert.That(mockDirectoryInfo.ToString(), Is.EqualTo(directoryPath));
}

[Test]
Expand All @@ -477,7 +477,7 @@ public void MockDirectoryInfo_Exists_ShouldReturnCachedData()
fileSystem.AddDirectory(path);

// Assert
Assert.IsFalse(directoryInfo.Exists);
Assert.That(directoryInfo.Exists, Is.False);
}

[Test]
Expand All @@ -493,7 +493,7 @@ public void MockDirectoryInfo_Exists_ShouldUpdateCachedDataOnRefresh()
directoryInfo.Refresh();

// Assert
Assert.IsTrue(directoryInfo.Exists);
Assert.That(directoryInfo.Exists, Is.True);
}

[Test]
Expand All @@ -507,7 +507,7 @@ public void Directory_exists_after_creation()
directoryInfo.Create();

// Assert
Assert.IsTrue(directoryInfo.Exists);
Assert.That(directoryInfo.Exists, Is.True);
}

[Test, WindowsOnly(WindowsSpecifics.AccessControlLists)]
Expand All @@ -521,7 +521,7 @@ public void Directory_exists_after_creation_with_security()
directoryInfo.Create(new DirectorySecurity());

Check warning on line 521 in tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

This call site is reachable on all platforms. 'DirectorySecurity' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 521 in tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

This call site is reachable on all platforms. 'DirectoryInfoAclExtensions.Create(IDirectoryInfo, DirectorySecurity)' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 521 in tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs

View workflow job for this annotation

GitHub Actions / Test (windows-latest)

This call site is reachable on all platforms. 'DirectoryInfoAclExtensions.Create(IDirectoryInfo, DirectorySecurity)' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 521 in tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs

View workflow job for this annotation

GitHub Actions / Test (windows-latest)

This call site is reachable on all platforms. 'DirectorySecurity' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 521 in tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs

View workflow job for this annotation

GitHub Actions / Test (macos-latest)

This call site is reachable on all platforms. 'DirectorySecurity' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 521 in tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs

View workflow job for this annotation

GitHub Actions / Test (macos-latest)

This call site is reachable on all platforms. 'DirectoryInfoAclExtensions.Create(IDirectoryInfo, DirectorySecurity)' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

// Assert
Assert.IsTrue(directoryInfo.Exists);
Assert.That(directoryInfo.Exists, Is.True);
}

[Test]
Expand All @@ -535,7 +535,7 @@ public void Directory_does_not_exist_after_delete()
directoryInfo.Delete();

// Assert
Assert.IsFalse(directoryInfo.Exists);
Assert.That(directoryInfo.Exists, Is.False);
}

[Test]
Expand All @@ -549,7 +549,7 @@ public void Directory_does_not_exist_after_recursive_delete()
directoryInfo.Delete(true);

// Assert
Assert.IsFalse(directoryInfo.Exists);
Assert.That(directoryInfo.Exists, Is.False);
}

[Test]
Expand All @@ -563,7 +563,7 @@ public void Directory_still_exists_after_move()
directoryInfo.MoveTo(XFS.Path(@"c:\abc2"));

// Assert
Assert.IsTrue(directoryInfo.Exists);
Assert.That(directoryInfo.Exists, Is.True);
}

[Test]
Expand All @@ -582,7 +582,7 @@ public void MockDirectoryInfo_LastAccessTime_ShouldReflectChangedValue()
directoryInfo.LastAccessTime = lastAccessTime;

// Assert
Assert.AreEqual(lastAccessTime, directoryInfo.LastAccessTime);
Assert.That(directoryInfo.LastAccessTime, Is.EqualTo(lastAccessTime));
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public void MockDirectory_CreateSymbolicLink_ShouldReturnFileSystemInfo()
IFileSystemInfo fileSystemInfo = fileSystem.Directory.CreateSymbolicLink(path, pathToTarget);

// Assert
Assert.AreEqual(path, fileSystemInfo.FullName);
Assert.AreEqual(pathToTarget, fileSystemInfo.LinkTarget);
Assert.That(fileSystemInfo.FullName, Is.EqualTo(path));
Assert.That(fileSystemInfo.LinkTarget, Is.EqualTo(pathToTarget));
}

[Test]
Expand All @@ -41,8 +41,8 @@ public void MockDirectory_CreateSymbolicLink_ShouldSucceedFromDirectoryInfo()
IDirectoryInfo directoryInfo = fileSystem.DirectoryInfo.New(path);

// Assert
Assert.AreEqual(path, directoryInfo.FullName);
Assert.AreEqual(pathToTarget, directoryInfo.LinkTarget);
Assert.That(directoryInfo.FullName, Is.EqualTo(path));
Assert.That(directoryInfo.LinkTarget, Is.EqualTo(pathToTarget));
}

[Test]
Expand Down Expand Up @@ -195,7 +195,7 @@ public void MockDirectory_CreateSymbolicLink_ShouldNotFailIfTargetDoesNotExist()
var fileSystemInfo = fileSystem.Directory.CreateSymbolicLink(path, pathToTarget);

// Assert
Assert.IsTrue(fileSystemInfo.Exists);
Assert.That(fileSystemInfo.Exists, Is.True);
}

[Test]
Expand All @@ -209,7 +209,7 @@ public void MockDirectory_CreateSymbolicLink_ShouldSetReparsePointAttribute()
fileSystem.Directory.CreateSymbolicLink(path, pathToTarget);

var attributes = fileSystem.DirectoryInfo.New(path).Attributes;
Assert.IsTrue(attributes.HasFlag(FileAttributes.ReparsePoint));
Assert.That(attributes.HasFlag(FileAttributes.ReparsePoint), Is.True);
}

[Test]
Expand All @@ -221,7 +221,7 @@ public void MockDirectory_ResolveLinkTarget_ShouldReturnPathOfTargetLink()

var result = fileSystem.Directory.ResolveLinkTarget("foo", false);

Assert.AreEqual("bar", result.Name);
Assert.That(result.Name, Is.EqualTo("bar"));
}

[Test]
Expand All @@ -242,7 +242,7 @@ public void MockDirectory_ResolveLinkTarget_WithFinalTarget_ShouldReturnPathOfTa

var result = fileSystem.Directory.ResolveLinkTarget(previousPath, true);

Assert.AreEqual("bar", result.Name);
Assert.That(result.Name, Is.EqualTo("bar"));
}

[Test]
Expand Down Expand Up @@ -275,7 +275,7 @@ public void MockDirectory_ResolveLinkTarget_WithoutFinalTarget_ShouldReturnFirst

var result = fileSystem.Directory.ResolveLinkTarget("foo1", false);

Assert.AreEqual("foo", result.Name);
Assert.That(result.Name, Is.EqualTo("foo"));
}

[Test]
Expand Down
Loading

0 comments on commit 6dceee2

Please sign in to comment.