Don't override Equals, GetHashCode#3660
Conversation
This comment has been minimized.
This comment has been minimized.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #3660 +/- ##
==========================================
- Coverage 74.24% 73.26% -0.99%
==========================================
Files 285 285
Lines 11143 10629 -514
Branches 1373 1322 -51
==========================================
- Hits 8273 7787 -486
+ Misses 2476 2452 -24
+ Partials 394 390 -4
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:
|
c646051 to
79649c8
Compare
jasonleenaylor
left a comment
There was a problem hiding this comment.
I had two comments worth considering, but overall
Reviewed 33 of 47 files at r1, 14 of 14 files at r2, all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @imnasnainaec)
Backend/Services/WordService.cs line 109 at r2 (raw file):
var rmCount = wordWithAudioToDelete.Audio.RemoveAll(a => a.FileName == fileName); if (rmCount == 0)
There is nothing at all wrong with this change, but I found it less clear than the original. So unless we expect Audio to have duplicate entries with the same filename I would slightly prefer the original. Should be bring @andracc in as a tie breaker? 😄
Code quote:
var rmCount = wordWithAudioToDelete.Audio.RemoveAll(a => a.FileName == fileName);
if (rmCount == 0)Backend.Tests/Controllers/UserRoleControllerTests.cs line 241 at r2 (raw file):
[Test] public async Task TestUpdateUserRoleNoChange()
So this test no longer had any value?
| new MergeUndoIds { ParentIds = _parentIds1, ChildIds = _childIds1 }.GetHashCode(), | ||
| Is.EqualTo(new MergeUndoIds { ParentIds = _parentIds1, ChildIds = _childIds1 }.GetHashCode())); | ||
| var merge = new MergeUndoIds { ParentIds = ["parent1", "parent2"], ChildIds = ["child1", "child2"] }; | ||
| Assert.That(merge.Clone(), Is.EqualTo(merge).UsingPropertiesComparer()); |
There was a problem hiding this comment.
this test will pass even if the clone is not a deep clone. So you might want to check that Parent and Child Ids don't refer to the same lists. Just a thought though.
There was a problem hiding this comment.
Ah, yes. This is why you use
assertionChain
.ForCondition(!ReferenceEquals(comparands.Subject, comparands.Expectation))
.BecauseOf(context.Reason)
.FailWith("Subject and Expectation for {0} should not reference the same instance in memory.", context.CurrentNode.Description);
I think for now I'll leave it and make an issue for considering that with all our Clone tests. The main purpose of the tests is to make sure no property was left out, but it would be valuable to make sure they've all been truly cloned.
hahn-kev
left a comment
There was a problem hiding this comment.
I'll bet that felt good to delete all that code
imnasnainaec
left a comment
There was a problem hiding this comment.
Reviewable status: 44 of 47 files reviewed, 1 unresolved discussion (waiting on @hahn-kev and @jasonleenaylor)
Backend.Tests/Controllers/UserRoleControllerTests.cs line 241 at r2 (raw file):
Previously, jasonleenaylor (Jason Naylor) wrote…
So this test no longer had any value?
Very little. Most of our Repository Mocks don't have a "NotModified" case, and this test depends on the
if (foundUserRole.ContentEquals(userRole))
{
return Task.FromResult(ResultOfUpdate.NoChange);
}
case of the Update method in UserRoleRepositoryMock, which was the only reason we had UserRole.ContentEquals defined. So I thought I'd remove it to have UserRoleRepositoryMock more consistent with the other Mocks.
Backend/Services/WordService.cs line 109 at r2 (raw file):
Previously, jasonleenaylor (Jason Naylor) wrote…
There is nothing at all wrong with this change, but I found it less clear than the original. So unless we expect Audio to have duplicate entries with the same filename I would slightly prefer the original. Should be bring @andracc in as a tie breaker? 😄
Reverted.
| new MergeUndoIds { ParentIds = _parentIds1, ChildIds = _childIds1 }.GetHashCode(), | ||
| Is.EqualTo(new MergeUndoIds { ParentIds = _parentIds1, ChildIds = _childIds1 }.GetHashCode())); | ||
| var merge = new MergeUndoIds { ParentIds = ["parent1", "parent2"], ChildIds = ["child1", "child2"] }; | ||
| Assert.That(merge.Clone(), Is.EqualTo(merge).UsingPropertiesComparer()); |
There was a problem hiding this comment.
Ah, yes. This is why you use
assertionChain
.ForCondition(!ReferenceEquals(comparands.Subject, comparands.Expectation))
.BecauseOf(context.Reason)
.FailWith("Subject and Expectation for {0} should not reference the same instance in memory.", context.CurrentNode.Description);
I think for now I'll leave it and make an issue for considering that with all our Clone tests. The main purpose of the tests is to make sure no property was left out, but it would be valuable to make sure they've all been truly cloned.
jasonleenaylor
left a comment
There was a problem hiding this comment.
Reviewed 3 of 3 files at r3, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @hahn-kev)
imnasnainaec
left a comment
There was a problem hiding this comment.
Dismissed @hahn-kev from a discussion.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @imnasnainaec)
We thought they were only used in testing, but they snuck into production via 4 uses of
.Removeas well as uses of.Containsin other model methods.This change is