From 8e41cee10a0289346209c90b94c2dcf9f53d7faa Mon Sep 17 00:00:00 2001 From: Tom Longhurst <30480171+thomhurst@users.noreply.github.com> Date: Tue, 10 Dec 2024 17:48:01 +0000 Subject: [PATCH] EquivalentTo Struct Fix --- .../EquivalentAssertionTests.cs | 37 +++++++++++++++++++ TUnit.Assertions/Compare.cs | 1 - 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/TUnit.Assertions.UnitTests/EquivalentAssertionTests.cs b/TUnit.Assertions.UnitTests/EquivalentAssertionTests.cs index 47206e825d..ab08c9a308 100644 --- a/TUnit.Assertions.UnitTests/EquivalentAssertionTests.cs +++ b/TUnit.Assertions.UnitTests/EquivalentAssertionTests.cs @@ -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() { @@ -359,4 +390,10 @@ public class InnerClass public IEnumerable? Collection { get; set; } } + + public struct MyStruct + { + public string? Value { get; set; } + public InnerClass? Inner { get; set; } + } } \ No newline at end of file diff --git a/TUnit.Assertions/Compare.cs b/TUnit.Assertions/Compare.cs index f14d81d2e5..c482c5fecb 100644 --- a/TUnit.Assertions/Compare.cs +++ b/TUnit.Assertions/Compare.cs @@ -61,7 +61,6 @@ private static IEnumerable CheckEquivalent< if (actual.GetType().IsPrimitive || actual.GetType().IsEnum - || actual.GetType().IsValueType || actual is string) { yield return new ComparisonFailure