diff --git a/Tests/Realm.Tests/Sync/DataTypeSynchronizationTests.cs b/Tests/Realm.Tests/Sync/DataTypeSynchronizationTests.cs index 4d55c43431..0beb8fd7e0 100644 --- a/Tests/Realm.Tests/Sync/DataTypeSynchronizationTests.cs +++ b/Tests/Realm.Tests/Sync/DataTypeSynchronizationTests.cs @@ -367,10 +367,7 @@ private void TestListCore(Func> getter, T ite var realm1 = await GetIntegrationRealmAsync(partition); var realm2 = await GetIntegrationRealmAsync(partition); - var obj1 = realm1.Write(() => - { - return realm1.Add(new SyncCollectionsObject()); - }); + var obj1 = realm1.Write(() => realm1.Add(new SyncCollectionsObject())); var obj2 = await WaitForObjectAsync(obj1, realm2); @@ -423,10 +420,7 @@ private void TestSetCore(Func> getter, T item1 var realm1 = await GetIntegrationRealmAsync(partition); var realm2 = await GetIntegrationRealmAsync(partition); - var obj1 = realm1.Write(() => - { - return realm1.Add(new SyncCollectionsObject()); - }); + var obj1 = realm1.Write(() => realm1.Add(new SyncCollectionsObject())); var obj2 = await WaitForObjectAsync(obj1, realm2); @@ -471,10 +465,8 @@ private void TestSetCore(Func> getter, T item1 private void TestDictionaryCore(Func> getter, T item1, T item2, Func? equalsOverride = null) { - var comparer = new Func, KeyValuePair, bool>((a, b) => - { - return a.Key == b.Key && (equalsOverride?.Invoke(a.Value, b.Value) ?? a.Value?.Equals(b.Value) == true); - }); + Func, KeyValuePair, bool> comparer = + (a, b) => a.Key == b.Key && (equalsOverride?.Invoke(a.Value, b.Value) ?? a.Value?.Equals(b.Value) == true); SyncTestHelpers.RunBaasTestAsync(async () => { @@ -482,10 +474,7 @@ private void TestDictionaryCore(Func - { - return realm1.Add(new SyncCollectionsObject()); - }); + var obj1 = realm1.Write(() => realm1.Add(new SyncCollectionsObject())); var obj2 = await WaitForObjectAsync(obj1, realm2, "initial obj from 1 shows up in 2"); @@ -562,10 +551,7 @@ private void TestPropertyCore(Func getter, Action()); }); - var obj1 = realm1.Write(() => - { - return realm1.Add(new SyncAllTypesObject()); - }); + var obj1 = realm1.Write(() => realm1.Add(new SyncAllTypesObject())); var obj2 = await WaitForObjectAsync(obj1, realm2); @@ -598,7 +584,7 @@ private void TestPropertyCore(Func getter, Action { @@ -670,7 +656,7 @@ await TestHelpers.WaitForConditionAsync(() => realm2.FindCore }); } - public static readonly IList RealmValueCollectionTestValues = new List() + private static readonly RealmValue[] RealmValueCollectionTestValues = { "abc", new ObjectId("5f63e882536de46d71877979"), @@ -730,7 +716,7 @@ await TestHelpers.WaitForConditionAsync(() => realm2.FindCore }; [Test] - public void ListManipulations() + public void NestedCollections_ListManipulations() { SyncTestHelpers.RunBaasTestAsync(async () => { @@ -765,7 +751,7 @@ public void ListManipulations() } // Remove elements one by one and verify that changes are synced - for (int index = 0; index < RealmValueCollectionTestValues.Count; index++) + for (var i = 0; i < RealmValueCollectionTestValues.Length; i++) { realm1.Write(() => { @@ -804,7 +790,7 @@ public void ListManipulations() } [Test] - public void DictionaryManipulations() + public void NestedCollections_DictionaryManipulations() { SyncTestHelpers.RunBaasTestAsync(async () => { @@ -854,8 +840,7 @@ public void DictionaryManipulations() } [Test] - [Ignore("Crashes until https://github.com/realm/realm-core/issues/7488 is fixed")] - public void CollectionMerge() + public void NestedCollections_Merge() { SyncTestHelpers.RunBaasTestAsync(async () => { @@ -942,7 +927,7 @@ private static RealmValue Clone(RealmValue original) var robj = original.AsIRealmObject(); var clone = (IRealmObjectBase)Activator.CreateInstance(robj.GetType())!; var properties = robj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance) - .Where(p => p.CanWrite && p.CanRead && !p.HasCustomAttribute()); + .Where(p => p is { CanWrite: true, CanRead: true } && !p.HasCustomAttribute()); foreach (var prop in properties) { @@ -970,7 +955,7 @@ private static T CloneOrLookup(T value, Realm targetRealm) } // If RealmValue that is holding an object, call CloneOrLookup - if (value is RealmValue rvalue && rvalue.Type == RealmValueType.Object) + if (value is RealmValue { Type: RealmValueType.Object } rvalue) { var cloned = CloneOrLookup(rvalue.AsIRealmObject(), targetRealm); return Operator.Convert(cloned); @@ -1000,15 +985,9 @@ private static bool RealmValueEquals(RealmValue a, RealmValue b) return false; } - foreach (var prop in objA.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(o => o.CanWrite && o.CanRead)) - { - if (prop.GetValue(objA)?.Equals(prop.GetValue(objB)) != true) - { - return false; - } - } - - return true; + return objA.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance) + .Where(o => o is { CanWrite: true, CanRead: true }) + .All(prop => prop.GetValue(objA)?.Equals(prop.GetValue(objB)) == true); } private static async Task WaitForPropertyChangedAsync(IRealmObject realmObject, int timeout = 10 * 1000) @@ -1030,8 +1009,6 @@ void RealmObject_PropertyChanged(object? sender, PropertyChangedEventArgs? e) private static async Task WaitForCollectionAsync(IEnumerable first, IEnumerable second, Func comparer, string message) { - comparer ??= EqualityComparer.Default.Equals; - await TestHelpers.WaitForConditionAsync(() => IsEquivalent(first, second, comparer), errorMessage: message); Assert.That(first, Is.EquivalentTo(second).Using(comparer)); }