Skip to content

[BUG] IsEqualTo and IsTypeOf fail to compile for enums/value objects in TUnit 0.7x #3387

@koddek

Description

@koddek

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

  1. Add TUnit 0.7x to a .NET project
  2. Define a test with an enum/value object property (e.g., account.Country where Country is an enum in a value objects namespace).
  3. 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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions