Skip to content

Commit

Permalink
Fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
nirinchev committed Apr 26, 2024
1 parent f48542c commit d1dd670
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 38 deletions.
1 change: 1 addition & 0 deletions Realm.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Staline/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Stalinism/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Stfld/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=subprecision/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=subscriptionset/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=syncsession/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=syncuser/@EntryIndexedValue">True</s:Boolean>
Expand Down
6 changes: 4 additions & 2 deletions Tests/Realm.Tests/Sync/MongoClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2108,7 +2108,8 @@ public void MongoCollection_FindOneAndDelete_FilterSortProjection()
var projection = BsonDocument.Parse("{ LongValue: 1 }");
var result = await collection.FindOneAndDeleteAsync(filter, sort, projection);
Assert.That(result.Id, Is.EqualTo(inserted[1].Id));
Assert.That(result, Is.Not.Null);
Assert.That(result!.Id, Is.EqualTo(inserted[1].Id));
Assert.That(result.StringValue, Is.Null);
Assert.That(result.LongValue, Is.EqualTo(inserted[1].LongValue));
Expand All @@ -2126,7 +2127,8 @@ public void MongoCollection_FindOne_Remapped()
var inserted = await InsertRemappedData(collection);
var result = await collection.FindOneAsync();
Assert.That(result.Id, Is.EqualTo(inserted[0].Id));
Assert.That(result, Is.Not.Null);
Assert.That(result!.Id, Is.EqualTo(inserted[0].Id));
Assert.That(result.StringValue, Is.EqualTo(inserted[0].StringValue));
Assert.That(result.MappedLink!.Id, Is.EqualTo(inserted[1].Id));
Assert.That(result.MappedList[0].Id, Is.EqualTo(inserted[2].Id));
Expand Down
72 changes: 36 additions & 36 deletions Tests/Realm.Tests/Sync/StaticQueriesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
using Realms.Schema;
using Realms.Sync;
using Realms.Sync.Exceptions;

using static Realms.Tests.TestHelpers;

namespace Realms.Tests.Sync
Expand Down Expand Up @@ -63,15 +62,15 @@ public void RealmObjectAPI_Collections()
var syncObj1 = syncObjects.Single();
AssertProps(obj1, syncObj1);
AssertCollectionProps(obj1, syncObj1);
realm.Write(() => realm.Add(syncObj2));
var filter = new { _id = syncObj2.Id };
var obj2 = await WaitForConditionAsync(() => collection.FindOneAsync(filter), item => Task.FromResult(item != null));
var obj2 = await WaitForNonNullObjectAsync(() => collection.FindOneAsync(filter));
AssertProps(syncObj2, obj2);
AssertCollectionProps(syncObj2, obj2);
void FillCollectionProps(SyncCollectionsObject obj)
{
Expand All @@ -81,7 +80,7 @@ void FillCollectionProps(SyncCollectionsObject obj)
}
}
void AssertProps(SyncCollectionsObject expected, SyncCollectionsObject actual)
void AssertCollectionProps(SyncCollectionsObject expected, SyncCollectionsObject actual)
{
foreach (var prop in props)
{
Expand All @@ -94,7 +93,7 @@ void AssertProps(SyncCollectionsObject expected, SyncCollectionsObject actual)
}, timeout: 120000);
}

public static readonly object[] PrimitiveTestCases = new[]
public static readonly object[] PrimitiveTestCases =
{
new object[] { CreateTestCase("Empty object", new SyncAllTypesObject()) },
new object[]
Expand Down Expand Up @@ -175,7 +174,7 @@ public void RealmObjectAPI_Primitive_RealmToAtlas(TestCaseData<SyncAllTypesObjec
var filter = new { _id = obj.Id };
var syncObj = await WaitForConditionAsync(() => collection.FindOneAsync(filter), item => Task.FromResult(item != null));
var syncObj = await WaitForNonNullObjectAsync(() => collection.FindOneAsync(filter));
AssertProps(props, obj, syncObj);
}, timeout: 120000);
Expand All @@ -189,7 +188,7 @@ public void RealmObjectAPI_Primitive_RealmToAtlas(TestCaseData<SyncAllTypesObjec
* This means that there is an issue when going from Realm to Atlas and then deserializing from Atlas, as there will be a difference
* of 1 millisecond when the original DateTimeOffset has sub-millisecond precision.
*/
public static readonly object[] DateTimeTestCasesAtlasToRealm = new[]
public static readonly object[] DateTimeTestCasesAtlasToRealm =
{
new object[] { CreateTestCase("PostEpoch", new DateTimeOffset(638404890727190000, TimeSpan.Zero)) },
new object[] { CreateTestCase("PostEpoch-subprecision", new DateTimeOffset(638404890727196472, TimeSpan.Zero)) },
Expand Down Expand Up @@ -217,7 +216,7 @@ public void RealmObjectAPI_DateTime_AtlasToRealm(TestCaseData<DateTimeOffset> te
}, timeout: 120000);
}

public static readonly object[] DateTimeTestCasesRealmToAtlas = new[]
public static readonly object[] DateTimeTestCasesRealmToAtlas =
{
new object[] { CreateTestCase("PostEpoch", new DateTimeOffset(638404890727190000, TimeSpan.Zero)) },
new object[] { CreateTestCase("PostEpoch-subprecision", new DateTimeOffset(638404890727196472, TimeSpan.Zero)) },
Expand All @@ -238,7 +237,7 @@ public void RealmObjectAPI_DateTime_RealmToAtlas(TestCaseData<DateTimeOffset> te
var filter = new { _id = obj.Id };
var syncObj = await WaitForConditionAsync(() => collection.FindOneAsync(filter), item => Task.FromResult(item != null));
var syncObj = await WaitForNonNullObjectAsync(() => collection.FindOneAsync(filter));
AssertAreEqual(syncObj.DateTimeOffsetProperty, obj.DateTimeOffsetProperty);
}, timeout: 120000);
Expand All @@ -261,7 +260,7 @@ public void RealmObjectAPI_DateTime_RealmToAtlas_SpecialCase()
var filter = new { _id = obj.Id };
var syncObj = await WaitForConditionAsync(() => collection.FindOneAsync(filter), item => Task.FromResult(item != null));
var syncObj = await WaitForNonNullObjectAsync(() => collection.FindOneAsync(filter));
var originalUnixMs = obj.DateTimeOffsetProperty.ToUnixTimeMilliseconds();
var expectedUnixMs = syncObj.DateTimeOffsetProperty.ToUnixTimeMilliseconds();
Expand All @@ -270,7 +269,7 @@ public void RealmObjectAPI_DateTime_RealmToAtlas_SpecialCase()
}, timeout: 120000);
}

public static readonly object[] CounterTestCases = new[]
public static readonly object[] CounterTestCases =
{
new object[]
{
Expand Down Expand Up @@ -342,13 +341,13 @@ public void RealmObjectAPI_Counter_RealmToAtlas(TestCaseData<CounterObject> test
var filter = new { _id = obj.Id };
var syncObj = await WaitForConditionAsync(() => collection.FindOneAsync(filter), item => Task.FromResult(item != null));
var syncObj = await WaitForNonNullObjectAsync(() => collection.FindOneAsync(filter));
AssertProps(props, obj, syncObj);
}, timeout: 120000);
}

public static readonly object[] AsymmetricTestCases = new[]
public static readonly object[] AsymmetricTestCases =
{
new object[]
{
Expand All @@ -370,13 +369,13 @@ public void RealmObjectAPI_Asymmetric_RealmToAtlas(TestCaseData<BasicAsymmetricO
using var realm = await GetFLXIntegrationRealmAsync();
realm.Write(() => realm.Add(obj));
var syncObj = await WaitForConditionAsync(() => collection.FindOneAsync(filter), item => Task.FromResult(item != null));
var syncObj = await WaitForNonNullObjectAsync(() => collection.FindOneAsync(filter));
Assert.That(stringProperty, Is.EqualTo(syncObj.PartitionLike));
}, timeout: 120000);
}

public static readonly object[] ObjectTestCases = new[]
public static readonly object[] ObjectTestCases =
{
new object[]
{
Expand Down Expand Up @@ -433,8 +432,8 @@ public void RealmObjectAPI_Object_RealmToAtlas(TestCaseData<SyncAllTypesObject>
await realm.All<IntPropertyObject>().Where(o => o.Id == obj.ObjectProperty!.Id).SubscribeAsync();
realm.Write(() => realm.Add(obj));
var syncAllTypeObj = await WaitForConditionAsync(() => syncAllTypesCollection.FindOneAsync(new { _id = obj.Id }), item => Task.FromResult(item != null));
var intPropertyObj = await WaitForConditionAsync(() => intPropertyCollection.FindOneAsync(new { _id = obj.ObjectProperty!.Id }), item => Task.FromResult(item != null));
var syncAllTypeObj = await WaitForNonNullObjectAsync(() => syncAllTypesCollection.FindOneAsync(new { _id = obj.Id }));
var intPropertyObj = await WaitForNonNullObjectAsync(() => intPropertyCollection.FindOneAsync(new { _id = obj.ObjectProperty!.Id }));
Assert.That(syncAllTypeObj.ObjectProperty!.Id, Is.EqualTo(obj.ObjectProperty!.Id));
Assert.That(syncAllTypeObj.ObjectProperty!.Int, Is.Not.EqualTo(obj.ObjectProperty!.Int));
Expand All @@ -444,7 +443,7 @@ public void RealmObjectAPI_Object_RealmToAtlas(TestCaseData<SyncAllTypesObject>
}, timeout: 120000);
}

public static readonly object[] LinksTestCases = new[]
public static readonly object[] LinksTestCases =
{
new object[]
{
Expand Down Expand Up @@ -536,7 +535,7 @@ public void RealmObjectAPI_Links_AtlasToRealm(TestCaseData<LinksObject> testCase
await collection.InsertManyAsync(elementsToInsert!);
// How many objects we expect
var totalCount = obj.List.Count + obj.Set.Count + obj.Dictionary.Where(d => d.Value != null).Count() + 1 + (obj.Link is null ? 0 : 1);
var totalCount = obj.List.Count + obj.Set.Count + obj.Dictionary.Count(d => d.Value != null) + 1 + (obj.Link is null ? 0 : 1);
using var realm = await GetFLXIntegrationRealmAsync();
var linkObjs = await realm.All<LinksObject>().SubscribeAsync();
Expand Down Expand Up @@ -582,8 +581,8 @@ static void AssertEqual(LinksObject? retrieved, LinksObject? original)
else
{
Assert.That(retrieved, Is.Not.Null);
Assert.That(retrieved!.Id, Is.EqualTo(original!.Id));
Assert.That(retrieved!.Value, Is.EqualTo(original!.Value));
Assert.That(retrieved!.Id, Is.EqualTo(original.Id));
Assert.That(retrieved.Value, Is.EqualTo(original.Value));
}
}
}, timeout: 120000);
Expand All @@ -606,7 +605,7 @@ public void RealmObjectAPI_Links_RealmToAtlas(TestCaseData<LinksObject> testCase
realm.Write(() => realm.Add(obj));
await WaitForUploadAsync(realm);
var linkObj = await WaitForConditionAsync(() => collection.FindOneAsync(new { _id = obj.Id }), item => Task.FromResult(item != null));
var linkObj = await WaitForNonNullObjectAsync(() => collection.FindOneAsync(new { _id = obj.Id }));
await AssertEqual(collection, linkObj.Link, obj.Link);
Expand Down Expand Up @@ -646,15 +645,15 @@ static async Task AssertEqual(MongoClient.Collection<LinksObject> collection, Li
Assert.That(partiallyRetrieved!.Id, Is.EqualTo(original.Id));
Assert.That(partiallyRetrieved.Value, Is.Not.EqualTo(original.Value));
var fullyRetrieved = await WaitForConditionAsync(() => collection.FindOneAsync(new { _id = original.Id }), item => Task.FromResult(item != null));
var fullyRetrieved = await WaitForNonNullObjectAsync(() => collection.FindOneAsync(new { _id = original.Id }));
Assert.That(fullyRetrieved.Id, Is.EqualTo(original.Id));
Assert.That(fullyRetrieved.Value, Is.EqualTo(original.Value));
}
}, timeout: 120000);
}

public static readonly object[] RealmValueLinkTestCases = new[]
public static readonly object[] RealmValueLinkTestCases =
{
new object[]
{
Expand Down Expand Up @@ -734,18 +733,18 @@ public void RealmObjectAPI_RealmValueLinks_AtlasToRealm(TestCaseData<RealmValueO
await realmValCollection.InsertOneAsync(obj);
var elementsToInsert = obj.RealmValueList.Select(o => o.As<IntPropertyObject>())
.Concat(obj.RealmValueSet.Select(o => o.As<IntPropertyObject>())
.Concat(obj.RealmValueDictionary.Values.Select(o => o.As<IntPropertyObject>()).Where(v => v is not null)));
.Concat(obj.RealmValueSet.Select(o => o.As<IntPropertyObject>())
.Concat(obj.RealmValueDictionary.Values.Select(o => o.As<IntPropertyObject>()).Where(v => v is not null)));
if (obj.RealmValueProperty != RealmValue.Null)
{
elementsToInsert = elementsToInsert.Concat(new[] { obj.RealmValueProperty.As<IntPropertyObject>() });
}
await intCollection.InsertManyAsync(elementsToInsert!);
await intCollection.InsertManyAsync(elementsToInsert);
// How many objects we expect
var totalCount = obj.RealmValueList.Count + obj.RealmValueSet.Count + obj.RealmValueDictionary.Where(d => d.Value != RealmValue.Null).Count();
var totalCount = obj.RealmValueList.Count + obj.RealmValueSet.Count + obj.RealmValueDictionary.Count(d => d.Value != RealmValue.Null);
using var realm = await GetFLXIntegrationRealmAsync();
var intObjs = await realm.All<IntPropertyObject>().SubscribeAsync();
Expand Down Expand Up @@ -820,7 +819,7 @@ public void RealmObjectAPI_RealmValueLinks_RealmToAtlas(TestCaseData<RealmValueO
realm.Write(() => realm.Add(obj));
await WaitForUploadAsync(realm);
var realmValObj = await WaitForConditionAsync(() => realmValCollection.FindOneAsync(new { _id = obj.Id }), item => Task.FromResult(item != null));
var realmValObj = await WaitForNonNullObjectAsync(() => realmValCollection.FindOneAsync(new { _id = obj.Id }));
await AssertEqual(intCollection, realmValObj.RealmValueProperty, obj.RealmValueProperty);
Expand Down Expand Up @@ -864,7 +863,7 @@ static async Task AssertEqual(MongoClient.Collection<IntPropertyObject> collecti
Assert.That(retrievedAsObj.Id, Is.EqualTo(originalAsObj.Id));
Assert.That(retrievedAsObj.Int, Is.Not.EqualTo(originalAsObj.Int));
var fullyRetrieved = await WaitForConditionAsync(() => collection.FindOneAsync(new { _id = originalAsObj.Id }), item => Task.FromResult(item != null));
var fullyRetrieved = await WaitForNonNullObjectAsync(() => collection.FindOneAsync(new { _id = originalAsObj.Id }));
Assert.That(fullyRetrieved.Id, Is.EqualTo(originalAsObj.Id));
Assert.That(fullyRetrieved.Int, Is.EqualTo(originalAsObj.Int));
Expand Down Expand Up @@ -1059,7 +1058,7 @@ public void RealmObjectAPI_Embedded_RealmToAtlas(TestCaseData<ObjectWithEmbedded
realm.Write(() => realm.Add(obj));
await WaitForUploadAsync(realm);
var syncObj = await WaitForConditionAsync(() => collection.FindOneAsync(new { _id = obj.PrimaryKey }), item => Task.FromResult(item != null));
var syncObj = await WaitForNonNullObjectAsync(() => collection.FindOneAsync(new { _id = obj.PrimaryKey }));
AssertEmbedded(syncObj, obj);
}, timeout: 120000);
Expand Down Expand Up @@ -1132,7 +1131,7 @@ public void RealmObjectAPI_ExtraFields_IgnoredWhenUsingTypedCollection()
var retrieved = await typedCollection.FindOneAsync(new { _id = primaryKey });
Assert.That(retrieved, Is.Not.Null);
Assert.That(retrieved.Value, Is.EqualTo(doc["Value"].AsString));
Assert.That(retrieved!.Value, Is.EqualTo(doc["Value"].AsString));
}, timeout: 120000);
}

Expand All @@ -1151,7 +1150,7 @@ public void RealmObjectAPI_MismatchedType_ThrowsOnInsertWhenCollectionInSchema()
{ "Value", ObjectId.GenerateNewId() }, // Wrong type
};
var ex = await TestHelpers.AssertThrows<AppException>(() => collection.InsertOneAsync(doc));
var ex = await AssertThrows<AppException>(() => collection.InsertOneAsync(doc));
Assert.That(ex.Message, Does.Contain("insert not permitted"));
}, timeout: 120000);
}
Expand Down Expand Up @@ -1206,7 +1205,7 @@ public void RealmObjectAPI_MissingField_ThrowsOnInsertWhenCollectionInSchema()
{ "Int", 23 }, // Missing the GuidProperty field
};
var ex = await TestHelpers.AssertThrows<Realms.Sync.Exceptions.AppException>(() => collection.InsertOneAsync(doc));
var ex = await AssertThrows<AppException>(() => collection.InsertOneAsync(doc));
Assert.That(ex.Message, Does.Contain("insert not permitted"));
}, timeout: 120000);
}
Expand Down Expand Up @@ -1242,7 +1241,8 @@ public void RealmObjectAPI_MissingField_GetsDefaultValueWhenDeserialized()
var typedCollection = db.GetCollection<IntPropertyObject>(collectionName);
var retrieved = await typedCollection.FindOneAsync(new { _id = primaryKey });
Assert.That(retrieved.Id, Is.EqualTo(primaryKey));
Assert.That(retrieved, Is.Not.Null);
Assert.That(retrieved!.Id, Is.EqualTo(primaryKey));
Assert.That(retrieved.Int, Is.EqualTo(doc["Int"].AsInt32));
Assert.That(retrieved.GuidProperty, Is.EqualTo(default(Guid)));
}, timeout: 120000);
Expand Down
7 changes: 7 additions & 0 deletions Tests/Realm.Tests/TestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,13 @@ public static async Task<T> WaitForConditionAsync<T>(Func<Task<T>> producer, Fun
return value;
}

public static async Task<T> WaitForNonNullObjectAsync<T>(Func<Task<T?>> producer)
{
var value = await WaitForConditionAsync(producer, v => Task.FromResult(v != null));
Assert.That(value, Is.Not.Null);
return value!;
}

public static void RunAsyncTest(Func<Task> testFunc, int timeout = 30000, Task? errorTask = null)
{
AsyncContext.Run(async () =>
Expand Down

0 comments on commit d1dd670

Please sign in to comment.