New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Idiomatic assertions for IEqualityComparer<T>
#1194
Conversation
@Kralizek thank you for the contribution. I think this will make a nice addition to AutoFixture. There is a package that implements these same assertions and some more. I think fixing the issues from the appveyor build log and adding the tests would be the first step to moving forward with the PR. |
@aivascu Yep, appveyor went crazy on feedback. I'll work on it when I have some free time. |
8d41a0b
to
4d3b1b4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Kralizek The PR looks good, I've made only a few code style changes. Let me know if you're OK with them.
No worries! Nice changes. I didn't think about putting that ugly pattern match into its own method. |
@Kralizek Nice work, like how thorough we are testing it! Having more assertions of the quality you created could make library insanely useful! Thanks for your contribution! 🤝 |
Glad you like it! |
At my company we have ended up creating some implementations of
IEqualityComparer<T>
so I've worked on an idiomatic assertion to quickly check that they respect some basic requirements:Equals(a, a) == true
(reflexive property)Equals(a, b) == Equals(b, a)
(symmetric property)Equals(a, b) == Equals(b, c) == Equals(a, c)
(transitive property)Equals(a, null) == false
Equals(null, null) == true
GetHashCode(a) == GetHashCode(a)
I added to this PR all the code produced right now. If there is an interest, I can continue working on this PR.
Here is a sample on how to use it:
Given the following class implementing
IEqualityComparer<string>
Developers can use this assertion as simply as
I haven't gone added the unit tests I have in my own solution and decorated methods and property with documentation comments. Also, I have used few features from C# 8 but I'm not sure if the current build setup supports them.