Skip to content

Commit

Permalink
EquivalentTo Struct Fix (#1384)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomhurst authored Dec 10, 2024
1 parent 6bc8d8f commit 0a00c94
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
37 changes: 37 additions & 0 deletions TUnit.Assertions.UnitTests/EquivalentAssertionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,37 @@ public async Task Objects_With_Nested_Matches_Are_Equivalent()
await TUnitAssert.That(object1).IsEquivalentTo(object2);
}

[Test]
public async Task Struct_Objects_With_Nested_Matches_Are_Equivalent()
{
var object1 = new MyStruct
{
Value = "Foo",
Inner = new InnerClass
{
Value = "Bar",
Inner = new InnerClass
{
Value = "Baz"
}
}
};
var object2 = new MyStruct
{
Value = "Foo",
Inner = new InnerClass
{
Value = "Bar",
Inner = new InnerClass
{
Value = "Baz"
}
}
};

await TUnitAssert.That(object1).IsEquivalentTo(object2);
}

[Test]
public void Objects_With_Nested_Enumerable_Mismatch_Are_Not_Equivalent()
{
Expand Down Expand Up @@ -359,4 +390,10 @@ public class InnerClass

public IEnumerable<string>? Collection { get; set; }
}

public struct MyStruct
{
public string? Value { get; set; }
public InnerClass? Inner { get; set; }
}
}
1 change: 0 additions & 1 deletion TUnit.Assertions/Compare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ private static IEnumerable<ComparisonFailure> CheckEquivalent<

if (actual.GetType().IsPrimitive
|| actual.GetType().IsEnum
|| actual.GetType().IsValueType
|| actual is string)
{
yield return new ComparisonFailure
Expand Down

0 comments on commit 0a00c94

Please sign in to comment.