Improve not supported error messages when using `Equals()`
See original GitHub issueDescription
Running code like the below throws an error "Calling Equals on Assertion classes is not supported."
I understand that this by design and is a helpful guard rail to prevent someone from thinking they’re using an assertion but actually doing an equality operation and the result being thrown away. Nice job there.
I think this error message could be improved. For example, it would be nice in the example below if the exception message also said “Did you mean Be()?”.
Complete minimal example reproducing the issue
var x = 1;
var y = 2;
x.Should().Equals(y); // throws NotSupportedException
Expected behavior:
Expected the exception to point me in the right direction.
Actual behavior:
I had to search the Internet for the error, found this GitHub site, read the code, realized I was dumb and should have used Be()
.
Versions
Latest
Additional Information
I will put in a PR if you think that supplementing the Equals()
error messages to point the user in the right direction would be useful. For many of the assertions, this might be to suggest Be()
but perhaps there are others which would need to use something else? I haven’t looked yet. Many thanks for this very useful library.
Issue Analytics
- State:
- Created a year ago
- Comments:9 (9 by maintainers)
Top GitHub Comments
I like that. I will work on a PR when I get some time soon. Many thanks for being open to considering improving this error message.
Right, I forgot to add the point, which was that we e.g. want to add overrides of
Equals
to e.g.ObjectAssertions
andGenericCollectionAssertions
to properly suggestBe
andEquals
.