Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EquivalentTo Struct Fix #1384

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading