Ensure IdentityComparer.AreEqual Usage is Properly Asserted#3151
Ensure IdentityComparer.AreEqual Usage is Properly Asserted#3151omidmloo wants to merge 6 commits intoAzureAD:devfrom
Conversation
|
@microsoft-github-policy-service agree |
|
@microsoft-github-policy-service agree |
|
Thanks for the contribution @omidmloo |
|
Thanks for the review, @jennyf19 ! During the fix for issue #3130, I encountered a failing test due to incorrect test data in To ensure this gets addressed properly, I have raised issue #3159 to track and resolve the test data mismatch. |
| configuration2 = await configManager.GetConfigurationAsync(); | ||
|
|
||
| if (IdentityComparer.AreEqual(configuration.Issuer, configuration2.Issuer)) | ||
| if (IdentityComparer.AreEqual(configuration.Issuer, configuration2.Issuer, CompareContext.Default)) |
There was a problem hiding this comment.
Here, but elsewhere as well, what is the thinking of using CompareContext.Default when there is a compare context available?
There was a problem hiding this comment.
Here, the for loop ensures the configuration refresh has taken effect before validation. Since updates may be delayed due to caching or async behavior, it retries up to 5 times, waiting 1 second between attempts until a change in Issuer is detected. Using context here might falsely impact the test result.
The next use of CompareContext.Default is to verify a negative test case, ensuring the values are different. While this aligns with the current test structure, the test could be improved by adding TestUtilities.AssertFailIfNoErrors to enforce proper assertions.
Fixes: #3130
This PR addresses issue #3130 by ensuring that IdentityComparer.AreEqual(object object1, object object2) is used correctly across the codebase.
Changes Made:
✅ Replaced usages of IdentityComparer.AreEqual(object, object) with the overload that accepts CompareContext, ensuring proper validation.
✅ Removed the parameterless overload where possible to enforce assertion of the comparison result.
✅ In cases where removal wasn’t possible, I explicitly added CompareContext.Default.
✅ Verified and updated all affected test methods to ensure correctness.
Testing & Validation:
I ran all relevant unit tests to confirm that there were no regressions.
Verified that all assertions are now explicitly checked.