diff --git a/TUnit.Assertions.Tests/EnumTests.cs b/TUnit.Assertions.Tests/EnumTests.cs index 5596a044aa..dea4ad0fcd 100644 --- a/TUnit.Assertions.Tests/EnumTests.cs +++ b/TUnit.Assertions.Tests/EnumTests.cs @@ -167,4 +167,123 @@ await Assert.That(async () => await Assert.That(value).DoesNotHaveSameValueAs(value2) ).Throws(); } + + [Test] + public async Task IsEqualTo_Good() + { + var value = MyEnum.One; + + await Assert.That(value).IsEqualTo(MyEnum.One); + } + + [Test] + public async Task IsEqualTo_Bad() + { + var value = MyEnum.One; + + await Assert.That(async () => + await Assert.That(value).IsEqualTo(MyEnum.Two) + ).Throws(); + } + + [Test] + public async Task IsEqualTo_Nullable_Good() + { + MyEnum? value = MyEnum.One; + + await Assert.That(value).IsEqualTo(MyEnum.One); + } + + [Test] + public async Task IsEqualTo_Nullable_Bad() + { + MyEnum? value = MyEnum.One; + + await Assert.That(async () => + await Assert.That(value).IsEqualTo(MyEnum.Two) + ).Throws(); + } + + [Test] + public async Task IsEqualTo_Nullable_Null() + { + MyEnum? value = null; + + await Assert.That(async () => + await Assert.That(value).IsEqualTo(MyEnum.One) + ).Throws(); + } + + [Test] + public async Task IsTypeOf_Enum() + { + object value = MyEnum.One; + + await Assert.That(value).IsTypeOf(); + } + + [Test] + public async Task IsNotEqualTo_Good() + { + var value = MyEnum.One; + + await Assert.That(value).IsNotEqualTo(MyEnum.Two); + } + + [Test] + public async Task IsNotEqualTo_Bad() + { + var value = MyEnum.One; + + await Assert.That(async () => + await Assert.That(value).IsNotEqualTo(MyEnum.One) + ).Throws(); + } + + // Custom value type (struct) tests + public struct CustomValueType + { + public int Value { get; set; } + public string Name { get; set; } + + public CustomValueType(int value, string name) + { + Value = value; + Name = name; + } + } + + [Test] + public async Task CustomValueType_IsEqualTo_Good() + { + var value = new CustomValueType(42, "Test"); + + await Assert.That(value).IsEqualTo(new CustomValueType(42, "Test")); + } + + [Test] + public async Task CustomValueType_IsEqualTo_Bad() + { + var value = new CustomValueType(42, "Test"); + + await Assert.That(async () => + await Assert.That(value).IsEqualTo(new CustomValueType(99, "Different")) + ).Throws(); + } + + [Test] + public async Task CustomValueType_IsNotEqualTo_Good() + { + var value = new CustomValueType(42, "Test"); + + await Assert.That(value).IsNotEqualTo(new CustomValueType(99, "Different")); + } + + [Test] + public async Task CustomValueType_IsTypeOf() + { + object value = new CustomValueType(42, "Test"); + + await Assert.That(value).IsTypeOf(); + } } diff --git a/TUnit.Assertions/Extensions/AssertionExtensions.cs b/TUnit.Assertions/Extensions/AssertionExtensions.cs index 226f79d6a5..a845e9a273 100644 --- a/TUnit.Assertions/Extensions/AssertionExtensions.cs +++ b/TUnit.Assertions/Extensions/AssertionExtensions.cs @@ -206,9 +206,9 @@ public static EqualsAssertion IsEqualTo( /// Asserts that a struct implementing IEquatable<TExpected> is equal to the expected value. /// This enables direct equality comparisons for structs with cross-type IEquatable implementations. /// Example: A Wrapper struct implementing IEquatable<long> can be compared directly to a long value. - /// Priority 1: Higher priority than generic fallback, uses type-specific IEquatable.Equals. + /// Priority -1: Lower than generic fallback; only used for cross-type IEquatable scenarios (TActual != TExpected). /// - [OverloadResolutionPriority(1)] + [OverloadResolutionPriority(-1)] public static EquatableAssertion IsEqualTo( this IAssertionSource source, TExpected expected, @@ -222,9 +222,9 @@ public static EquatableAssertion IsEqualTo /// Asserts that a nullable struct implementing IEquatable<TExpected> is equal to the expected value. /// Handles nullable structs with cross-type IEquatable implementations. - /// Priority 1: Higher priority than generic fallback, uses type-specific IEquatable.Equals. + /// Priority -1: Lower than generic fallback; only used for cross-type IEquatable scenarios (TActual != TExpected). /// - [OverloadResolutionPriority(1)] + [OverloadResolutionPriority(-1)] public static NullableEquatableAssertion IsEqualTo( this IAssertionSource source, TExpected expected, diff --git a/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.DotNet10_0.verified.txt b/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.DotNet10_0.verified.txt index d93d0bf91d..6dc804c66b 100644 --- a/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.DotNet10_0.verified.txt +++ b/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.DotNet10_0.verified.txt @@ -1685,10 +1685,10 @@ namespace .Extensions public static . IsEqualTo(this . source, string expected, comparison, [.("expected")] string? expression = null) { } [.(0)] public static . IsEqualTo(this . source, TValue expected, [.("expected")] string? expression = null) { } - [.(1)] + [.(-1)] public static . IsEqualTo(this . source, TExpected expected, [.("expected")] string? expression = null) where TActual : struct, { } - [.(1)] + [.(-1)] public static . IsEqualTo(this . source, TExpected expected, [.("expected")] string? expression = null) where TActual : struct, { } public static . IsEquivalentTo(this . source, object? expected, [.("expected")] string? expression = null) { } diff --git a/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.DotNet9_0.verified.txt b/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.DotNet9_0.verified.txt index 9413a01ac5..c1e61d2657 100644 --- a/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.DotNet9_0.verified.txt +++ b/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.DotNet9_0.verified.txt @@ -1685,10 +1685,10 @@ namespace .Extensions public static . IsEqualTo(this . source, string expected, comparison, [.("expected")] string? expression = null) { } [.(0)] public static . IsEqualTo(this . source, TValue expected, [.("expected")] string? expression = null) { } - [.(1)] + [.(-1)] public static . IsEqualTo(this . source, TExpected expected, [.("expected")] string? expression = null) where TActual : struct, { } - [.(1)] + [.(-1)] public static . IsEqualTo(this . source, TExpected expected, [.("expected")] string? expression = null) where TActual : struct, { } public static . IsEquivalentTo(this . source, object? expected, [.("expected")] string? expression = null) { }