-
-
Notifications
You must be signed in to change notification settings - Fork 80
Added Equal(object) to ServiceTarget so FluentAssertions of equality work correctly #1323
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
base: main
Are you sure you want to change the base?
Conversation
…t Assertions. Without this since ServiceTarget is a class the only check is if two objects are the SAME object (i.e. reference check only)
|
Noticed I hadn't added not equal test cases. Just to show that all not equal checks are just the negative of Equal(object). |
|
Do I also need to clean up the "empty" commit from resyncing my repo and squash the commits. I saw some comments in discord about commits not being signed but I don't understand the signing process. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1323 +/- ##
====================================
- Coverage 82% 82% -1%
====================================
Files 197 197
Lines 3871 3900 +29
Branches 429 442 +13
====================================
+ Hits 3194 3202 +8
- Misses 511 527 +16
- Partials 166 171 +5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
FrankBakkerNl
left a comment
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.
I think making ServiceTarget a record will do the same thing with less chance of mistakes. Not sure why I did not do that originally.
|
@FrankBakkerNl what do you think we should proceed with this PR? |
|
I think the record solution would be better. @edleno2 did you want to do this? |
Proposed change
When writing unit tests using Fluent Assertion I discovered that equality checks against ServiceTarget can only be done as reference equality. This would be extremely hard to use since the creation of ServiceTargets often happens in internal code. This code adds Equal(object) which matches the signature used by Fluent Assertions when CallService is used with a target of "object?".
Type of change
Additional information
This change did cause one regression of a unit test. The test relied on the LACK of an equals so that the comparison between a class (ServiceTarget) and a record (HassTarget) was done on a member by member basis. Once an equals was added this lead to the issue that neither the class nor the record could equate each other. Added an option to force member comparison. This is a known limitation with class to record comparisons (see answer 2 in this link)
Added unit tests to show which equal operators will work, and which will not. Keeping to the principle to make the least impactive change I did not override the == or != operator for actual ServiceTarget classes. Those type of comparisons will still default to checking object reference equality.
Checklist