Added Equal(object) to ServiceTarget so FluentAssertions of equality work correctly #1323
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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