Skip to content

Commit

Permalink
Improved testing and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
rorbech committed Mar 15, 2024
1 parent a7aef39 commit 40dfeb3
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 43 deletions.
85 changes: 44 additions & 41 deletions Tests/Realm.Tests/Database/RealmValueWithCollections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public void List_AfterCreation_CanBeAssigned([Values(true, false)] bool isManage
[Test]
public void List_AfterCreation_CanBeReassigned([Values(true, false)] bool isManaged)
{
var initialList = (RealmValue)new List<RealmValue>{ 1, 2, 3};
var initialList = (RealmValue)new List<RealmValue> { 1, 2, 3 };
var rvo = new RealmValueObject { RealmValueProperty = initialList };

if (isManaged)
Expand All @@ -267,24 +267,24 @@ public void List_AfterCreation_CanBeReassigned([Values(true, false)] bool isMana
});
}

var actual = rvo.RealmValueProperty.AsList();
Assert.AreEqual(initialList.AsList().Count, actual.Count);
var actualList = rvo.RealmValueProperty;
Assert.That(initialList, Is.EqualTo(actualList).Using(_rvComparer));

var updatedList = (RealmValue)new List<RealmValue>{4, 5, 6};
var updatedList = (RealmValue)new List<RealmValue> { 4, 5 };
_realm.Write(() =>
{
rvo.RealmValueProperty = updatedList;
});

actual = rvo.RealmValueProperty.AsList();
Assert.AreEqual(updatedList.AsList().Count, actual.Count);
actualList = rvo.RealmValueProperty;
Assert.That(updatedList, Is.EqualTo(actualList).Using(_rvComparer));
}

[Test]
public void List_AfterCreation_EmbeddedListCanBeReassigned([Values(true, false)] bool isManaged)
{
var embeddedList = new List<RealmValue>{ new List<RealmValue>{1, 2, 3}};
var rvo = new RealmValueObject { RealmValueProperty = new List<RealmValue>{ embeddedList} };
var initialList = (RealmValue)new List<RealmValue> { new List<RealmValue> { 1, 2, 3 } };
var rvo = new RealmValueObject { RealmValueProperty = new List<RealmValue> { initialList } };

if (isManaged)
{
Expand All @@ -294,24 +294,24 @@ public void List_AfterCreation_EmbeddedListCanBeReassigned([Values(true, false)]
});
}

var actualEmbedded = rvo.RealmValueProperty.AsList()[0].AsList();
Assert.AreEqual(embeddedList.Count, actualEmbedded.Count);
var actualEmbeddedList = rvo.RealmValueProperty.AsList()[0];
Assert.That(initialList, Is.EqualTo(actualEmbeddedList).Using(_rvComparer));

var updatedList = (RealmValue)new List<RealmValue>{4, 5, 6};
var updatedList = (RealmValue)new List<RealmValue> { 4, 5, 6 };
_realm.Write(() =>
{
rvo.RealmValueProperty.AsList()[0] = updatedList;
});

actualEmbedded = rvo.RealmValueProperty.AsList()[0].AsList();
Assert.AreEqual(updatedList.AsList().Count, actualEmbedded.Count);
actualEmbeddedList = rvo.RealmValueProperty.AsList()[0];
Assert.That(updatedList, Is.EqualTo(actualEmbeddedList).Using(_rvComparer));
}

[Test]
public void List_AfterCreation_EmbeddedDictionaryCanBeReassigned([Values(true, false)] bool isManaged)
{
var embeddedDictionary = new Dictionary<string, RealmValue>{{ "key1", 1}};
var rvo = new RealmValueObject { RealmValueProperty = new List<RealmValue>{ embeddedDictionary} };
var initialDictionary = (RealmValue)new Dictionary<string, RealmValue> { { "key1", 1 } };
var rvo = new RealmValueObject { RealmValueProperty = new List<RealmValue> { initialDictionary } };

if (isManaged)
{
Expand All @@ -321,20 +321,19 @@ public void List_AfterCreation_EmbeddedDictionaryCanBeReassigned([Values(true, f
});
}

var actualEmbedded = rvo.RealmValueProperty.AsList()[0].AsDictionary();
Assert.AreEqual(embeddedDictionary.Count, actualEmbedded.Count);
var actualDictionary = rvo.RealmValueProperty.AsList()[0];
Assert.That(initialDictionary, Is.EqualTo(actualDictionary).Using(_rvComparer));

var updatedDictionary = new Dictionary<string, RealmValue>{{ "key2", 2}};
var updatedDictionary = (RealmValue)new Dictionary<string, RealmValue> { { "key2", 2 } };
_realm.Write(() =>
{
rvo.RealmValueProperty.AsList()[0] = updatedDictionary;
});

actualEmbedded = rvo.RealmValueProperty.AsList()[0].AsDictionary();
Assert.AreEqual(updatedDictionary.Count, actualEmbedded.Count);
actualDictionary = rvo.RealmValueProperty.AsList()[0];
Assert.That(updatedDictionary, Is.EqualTo(actualDictionary).Using(_rvComparer));
}


[Test]
public void List_WhenManaged_CanBeModified()
{
Expand Down Expand Up @@ -533,7 +532,6 @@ public void List_WhenManaged_WorksWithNotifications()

callbacks.Clear();
}

#endregion

#region Dictionary
Expand Down Expand Up @@ -736,7 +734,7 @@ public void Dictionary_AfterCreation_CanBeAssigned([Values(true, false)] bool is
[Test]
public void Dictionary_AfterCreation_CanBeReassigned([Values(true, false)] bool isManaged)
{
var initialDictionary = (RealmValue) new Dictionary<string, RealmValue> { {"key1" , 1 } };
var initialDictionary = (RealmValue)new Dictionary<string, RealmValue> { { "key1", 1 } };
var rvo = new RealmValueObject { RealmValueProperty = initialDictionary };

if (isManaged)
Expand All @@ -747,24 +745,27 @@ public void Dictionary_AfterCreation_CanBeReassigned([Values(true, false)] bool
});
}

var actual = rvo.RealmValueProperty.AsDictionary();
Assert.AreEqual(initialDictionary.AsDictionary().Count, actual.Count);
var actualDictionary = rvo.RealmValueProperty;
Assert.That(initialDictionary, Is.EqualTo(actualDictionary).Using(_rvComparer));

var updatedDictionary = (RealmValue) new Dictionary<string, RealmValue> { {"key2" , 2 } };
var updatedDictionary = (RealmValue)new Dictionary<string, RealmValue> { { "key2", 2 } };
_realm.Write(() =>
{
rvo.RealmValueProperty = updatedDictionary;
});

actual = rvo.RealmValueProperty.AsDictionary();
Assert.AreEqual(updatedDictionary.AsDictionary().Count, actual.Count);
actualDictionary = rvo.RealmValueProperty;
Assert.That(updatedDictionary, Is.EqualTo(actualDictionary).Using(_rvComparer));
}

[Test]
public void Dictionary_AfterCreation_EmbeddedListCanBeReassigned([Values(true, false)] bool isManaged)
{
var embeddedList = new List<RealmValue>{ new List<RealmValue>{1, 2, 3}};
var rvo = new RealmValueObject { RealmValueProperty = new Dictionary<string, RealmValue>{ { "key", embeddedList}} };
var initialList = new List<RealmValue> { new List<RealmValue> { 1, 2, 3 } };
var rvo = new RealmValueObject
{
RealmValueProperty = new Dictionary<string, RealmValue> { { "key", initialList } }
};

if (isManaged)
{
Expand All @@ -774,24 +775,27 @@ public void Dictionary_AfterCreation_EmbeddedListCanBeReassigned([Values(true, f
});
}

var actualEmbedded = rvo.RealmValueProperty.AsDictionary()["key"].AsList();
Assert.AreEqual(embeddedList.Count, actualEmbedded.Count);
var actualEmbeddedList = rvo.RealmValueProperty.AsDictionary()["key"].AsList();
Assert.That(initialList, Is.EqualTo(actualEmbeddedList).Using(_rvComparer));

var updatedList = (RealmValue)new List<RealmValue>{4, 5, 6};
var updatedList = (RealmValue)new List<RealmValue> { 4, 5, 6 };
_realm.Write(() =>
{
rvo.RealmValueProperty.AsDictionary()["key"] = updatedList;
});

actualEmbedded = rvo.RealmValueProperty.AsDictionary()["key"].AsList();
Assert.AreEqual(updatedList.AsList().Count, actualEmbedded.Count);
actualEmbeddedList = rvo.RealmValueProperty.AsDictionary()["key"].AsList();
Assert.AreEqual(updatedList.AsList().Count, actualEmbeddedList.Count);
}

[Test]
public void Dict_AfterCreation_EmbeddedDictionaryCanBeReassigned([Values(true, false)] bool isManaged)
{
var embeddedDictionary = new Dictionary<string, RealmValue>{{ "key1", 1}};
var rvo = new RealmValueObject { RealmValueProperty = new Dictionary<string, RealmValue>{ { "key", embeddedDictionary} } };
var embeddedDictionary = new Dictionary<string, RealmValue> { { "key1", 1 } };
var rvo = new RealmValueObject
{
RealmValueProperty = new Dictionary<string, RealmValue> { { "key", embeddedDictionary } }
};

if (isManaged)
{
Expand All @@ -802,19 +806,18 @@ public void Dict_AfterCreation_EmbeddedDictionaryCanBeReassigned([Values(true, f
}

var actualEmbedded = rvo.RealmValueProperty.AsDictionary()["key"].AsDictionary();
Assert.AreEqual(embeddedDictionary.Count, actualEmbedded.Count);
Assert.That(embeddedDictionary, Is.EqualTo(actualEmbedded).Using(_rvComparer));

var updatedDictionary = new Dictionary<string, RealmValue>{{ "key2", 2}};
var updatedDictionary = new Dictionary<string, RealmValue> { { "key2", 2 } };
_realm.Write(() =>
{
rvo.RealmValueProperty.AsDictionary()["key"] = updatedDictionary;
});

actualEmbedded = rvo.RealmValueProperty.AsDictionary()["key"].AsDictionary();
Assert.AreEqual(updatedDictionary.Count, actualEmbedded.Count);
Assert.That(updatedDictionary, Is.EqualTo(actualEmbedded).Using(_rvComparer));
}


[Test]
public void Dictionary_WhenManaged_CanBeModified()
{
Expand Down
1 change: 0 additions & 1 deletion Tests/Realm.Tests/Sync/SyncTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ private static T UpdateConfig<T>(T config)
typeof(SyncAllTypesObject),
typeof(ObjectWithPartitionValue),
typeof(RemappedTypeObject),
typeof(RealmValueObject),
};

if (config is FlexibleSyncConfiguration)
Expand Down
6 changes: 5 additions & 1 deletion Tools/DeployApps/BaasClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ public async Task SetAutomaticRecoveryEnabled(BaasApp app, bool enabled)
{
development_mode_enabled = true,
});

// Retrieve feature flags
// var features = await GetPrivateAsync<BsonDocument>($"groups/{_groupId}/apps/{app}/features");
// ENABLE LEGACY MIXED SUPPORT
Expand All @@ -568,7 +569,6 @@ public async Task SetAutomaticRecoveryEnabled(BaasApp app, bool enabled)
// DISABLE LEGACY MIXED SUPPORT - Default on latest test server - https://github.com/10gen/baas/blob/master/etc/configs/test_config.json#L303
// await PostPrivateAsync<BsonDocument>($"features/legacy_mixed_type", new { app_ids = new []{$"{appId}"}, action = "disable"} );
// await PostPrivateAsync<BsonDocument>($"features/bypass_legacy_mixed_type", new { app_ids = new []{$"{appId}"}, action = "enable"} );

return (app, mongoServiceId);
}

Expand Down Expand Up @@ -712,12 +712,15 @@ private async Task RefreshAccessTokenAsync()
}

private Task<T?> PostAsync<T>(string relativePath, object obj) => SendAsync<T>(HttpMethod.Post, relativePath, obj);

private Task<T?> PostPrivateAsync<T>(string relativePath, object obj) => SendPrivateAsync<T>(HttpMethod.Post, relativePath, obj);

private Task<T?> GetAsync<T>(string relativePath) => SendAsync<T>(HttpMethod.Get, relativePath);

private Task<T?> GetPrivateAsync<T>(string relativePath) => SendPrivateAsync<T>(HttpMethod.Get, relativePath);

private Task<T?> PutAsync<T>(string relativePath, object obj) => SendAsync<T>(HttpMethod.Put, relativePath, obj);

private Task<T?> PutPrivateAsync<T>(string relativePath, object obj) => SendPrivateAsync<T>(HttpMethod.Put, relativePath, obj);

private Task<T?> PatchAsync<T>(string relativePath, object obj) => SendAsync<T>(new HttpMethod("PATCH"), relativePath, obj);
Expand Down Expand Up @@ -752,6 +755,7 @@ private async Task RefreshAccessTokenAsync()

return default;
}

private async Task<T?> SendPrivateAsync<T>(HttpMethod method, string relativePath, object? payload = null)
{
using var message = new HttpRequestMessage(method, new Uri(relativePath, UriKind.Relative));
Expand Down

0 comments on commit 40dfeb3

Please sign in to comment.