-
-
Notifications
You must be signed in to change notification settings - Fork 95
Closed
Description
Description
IsEqualTo and IsTypeOf assertions do not compile when used on enum types or simple value objects (e.g., Country enum with .Undefined member). This appears tied to generic constraints requiring IEquatable<T> and type mismatches in assertion sources. Affects basic enum validation in tests.
Repro Steps
- Add TUnit 0.7x to a .NET project
- Define a test with an enum/value object property (e.g.,
account.CountrywhereCountryis an enum in a value objects namespace). - Add the following assertion lines.
Code Example 1:
await Assert.That(account.Country).IsEqualTo(Country.Undefined);Compiler Error 1:
The type 'Country' must be convertible to 'System.IEquatable<Country>' in order to use it as parameter 'TActual' in the generic method 'EquatableAssertion<TActual,TExpected> TUnit.Assertions.Extensions.AssertionExtensions.IsEqualTo<TActual,TExpected>(this IAssertionSource<TActual>, TExpected, string?)'
Code Example 2:
await Assert.That(account.Country).IsTypeOf<Country>();Compiler Error 2:
Cannot convert instance argument type 'TUnit.Assertions.Sources.ValueAssertion<Country>' to 'TUnit.Assertions.Core.IAssertionSource<object>'
Expected Behavior
Both assertions should compile and run, comparing the enum/value object as expected (e.g., equality check for IsEqualTo, type match for IsTypeOf). They worked in earlier version.
Actual Behavior
Compilation fails with the errors above.
Environment
- TUnit version: 0.7x
- .NET version: .NET 9
- OS: MAC
Metadata
Metadata
Assignees
Labels
No labels