Skip to content

Commit

Permalink
#2767: Verify types match when comparing FileSystemInfo values (v3)
Browse files Browse the repository at this point in the history
  • Loading branch information
bradwilson committed Sep 3, 2023
1 parent 77274be commit 3c0ff59
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
40 changes: 37 additions & 3 deletions src/xunit.v3.assert.tests/Asserts/EquivalenceAssertsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1477,7 +1477,7 @@ public void DateTimeOffset_Failure()
);
}

// DirectoryInfo
// FileSystemInfo-derived types

[Fact]
public void DirectoryInfo_Success()
Expand Down Expand Up @@ -1509,8 +1509,6 @@ public void DirectoryInfo_Failure()
Assert.StartsWith("Assert.Equivalent() Failure: Mismatched value on member 'FullName'" + Environment.NewLine, ex.Message);
}

// FileInfo

[Fact]
public void FileInfo_Success()
{
Expand All @@ -1532,6 +1530,42 @@ public void FileInfo_Failure()
Assert.IsType<EquivalentException>(ex);
Assert.StartsWith("Assert.Equivalent() Failure: Mismatched value on member 'FullName'" + Environment.NewLine, ex.Message);
}

[Fact]
public void FileInfoToDirectoryInfo_Failure_TopLevel()
{
var location = typeof(SpecialCases).Assembly.Location;
var expected = new FileInfo(location);
var actual = new DirectoryInfo(location);

var ex = Record.Exception(() => Assert.Equivalent(expected, actual));

Assert.IsType<EquivalentException>(ex);
Assert.Equal(
"Assert.Equivalent() Failure: Types did not match" + Environment.NewLine +
"Expected type: System.IO.FileInfo" + Environment.NewLine +
"Actual type: System.IO.DirectoryInfo",
ex.Message
);
}

[Fact]
public void FileInfoToDirectoryInfo_Failure_Embedded()
{
var location = typeof(SpecialCases).Assembly.Location;
var expected = new { Info = new FileInfo(location) };
var actual = new { Info = new DirectoryInfo(location) };

var ex = Record.Exception(() => Assert.Equivalent(expected, actual));

Assert.IsType<EquivalentException>(ex);
Assert.Equal(
"Assert.Equivalent() Failure: Types did not match in member 'Info'" + Environment.NewLine +
"Expected type: System.IO.FileInfo" + Environment.NewLine +
"Actual type: System.IO.DirectoryInfo",
ex.Message
);
}
}

public class CircularReferences
Expand Down
2 changes: 1 addition & 1 deletion src/xunit.v3.assert/Asserts

0 comments on commit 3c0ff59

Please sign in to comment.