Skip to content
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

RNET-1133: Fixed equality comparison for collections in mixed #3573

Merged
merged 5 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Realm/Realm/DatabaseTypes/RealmValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1533,6 +1533,8 @@ public bool Equals(RealmValue other)
RealmValueType.ObjectId => AsObjectId() == other.AsObjectId(),
RealmValueType.Guid => AsGuid() == other.AsGuid(),
RealmValueType.Object => AsIRealmObject().Equals(other.AsIRealmObject()),
RealmValueType.List => AsList().Equals(other.AsList()),
RealmValueType.Dictionary => AsDictionary().Equals(other.AsDictionary()),
Comment on lines +1536 to +1537
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

RealmValueType.Null => true,
_ => false,
};
Expand Down
18 changes: 12 additions & 6 deletions Tests/Realm.Tests/Database/RealmValueWithCollections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void List_WhenRetrieved_WorksWithAllTypes([Values(true, false)] bool isMa
}

[Test]
public void List_InRealmValue_NotEqualToAnything([Values(true, false)] bool isManaged)
public void List_InRealmValue_Equality([Values(true, false)] bool isManaged)
{
var innerList = ListGenerator(1);
var innerDict = DictGenerator(1);
Expand Down Expand Up @@ -120,8 +120,11 @@ public void List_InRealmValue_NotEqualToAnything([Values(true, false)] bool isMa
rv = PersistAndFind(rv).RealmValueProperty;
}

Assert.That(rv == originalList, Is.False);
Assert.That(rv.Equals(originalList), Is.False);
#pragma warning disable CS1718 // Comparison made to same variable
Assert.That(rv == rv, Is.True);
#pragma warning restore CS1718 // Comparison made to same variable
Assert.That(rv == originalList, isManaged ? Is.False : Is.True);
rorbech marked this conversation as resolved.
Show resolved Hide resolved
Assert.That(rv.Equals(originalList), isManaged ? Is.False : Is.True);
}

[Test]
Expand Down Expand Up @@ -577,7 +580,7 @@ public void Dictionary_WhenRetrieved_WorksWithAllTypes([Values(true, false)] boo
}

[Test]
public void Dictionary_InRealmValue_NotEqualToAnything([Values(true, false)] bool isManaged)
public void Dictionary_InRealmValue_Equality([Values(true, false)] bool isManaged)
{
var innerList = ListGenerator(1);
var innerDict = DictGenerator(1);
Expand All @@ -596,8 +599,11 @@ public void Dictionary_InRealmValue_NotEqualToAnything([Values(true, false)] boo
rv = PersistAndFind(rv).RealmValueProperty;
}

Assert.That(rv == originalDict, Is.False);
Assert.That(rv.Equals(originalDict), Is.False);
#pragma warning disable CS1718 // Comparison made to same variable
Assert.That(rv == rv, Is.True);
#pragma warning restore CS1718 // Comparison made to same variable
Assert.That(rv == originalDict, isManaged ? Is.False : Is.True);
Assert.That(rv.Equals(originalDict), isManaged ? Is.False : Is.True);
}

[Test]
Expand Down
Loading