Skip to content

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

edleno2
Copy link

@edleno2 edleno2 commented Aug 1, 2025

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

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

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

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • The code compiles without warnings (code quality check)
  • Tests have been added to verify that the new code works.

edleno2 and others added 3 commits July 31, 2025 16:37
…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)
@edleno2
Copy link
Author

edleno2 commented Aug 1, 2025

Noticed I hadn't added not equal test cases. Just to show that all not equal checks are just the negative of Equal(object).

@edleno2
Copy link
Author

edleno2 commented Aug 2, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant