Skip to content

InvalidCastException from EqualityComparerEquivalencyStep #1302

@jnyrup

Description

@jnyrup

When running
When_the_subjects_property_type_is_different_from_the_equality_comparer_it_should_throw
with a debugger attached
EqualityComparerEquivalencyStep<T> throws an InvalidCastException when context.Subject is T fails as the second ForCondition is executed with (T)context.Subject.

The second ForCondition is executed because:

  • Execute.Assertion uses the AssertionScope from EquivalencyValidator.AssertEquality,
  • that is constructed using new AssertionScope(),
  • which defaults to CollectingAssertionStrategy,
  • which does not throw on first failure.

Even though the failure message is correct, Exceptions are not nice.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions