Skip to content

EqualTo().Using() prevents caller from comparing strings to anything else #1897

Description

@tenwit

Given a suitable DateTimeComparer class that converts IConvertible objects to DateTime, I expect this code to not throw an assertion:

Assert.That(new DateTime(2016, 8, 2), Is.EqualTo("2 August 2016")
                                        .Using(DateTimeComparer.Instance));

But it does, because Using(DateTimeCompare.Instance) returns either a ComparerAdapter or an EqualityComparerAdapter, neither of which override the default implementation of CanCompare.

Since the person writing the test is taking responsibility for comparing the actual and expected values (due to calling Using), CanCompare should always return true for any ExternalComparer added when calling Using.

The original issue and MCVE is described at Stackoverflow.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions