private async Task <Uri> CreateRealm(Action <Realm> assignRoles = null, bool addObjects = true)
        {
            var uri   = SyncTestHelpers.RealmUri(Guid.NewGuid().ToString());
            var admin = await SyncTestHelpers.GetAdminUserAsync();

            var config = new QueryBasedSyncConfiguration(uri, admin)
            {
                ObjectClasses = new[] { typeof(ObjectWithPermissions) }
            };

            using (var realm = GetRealm(config))
            {
                var objects      = realm.All <ObjectWithPermissions>();
                var subscription = await SubscribeToObjectsAsync(realm);

                if (addObjects)
                {
                    Assert.That(subscription.Results.Count(), Is.EqualTo(0));
                    AddObjectsToRealm(realm, new[] { 1, 2, 3 });

                    await SyncTestHelpers.WaitForSyncAsync(realm);

                    Assert.That(subscription.Results.Count(), Is.EqualTo(3));
                }

                if (assignRoles != null)
                {
                    realm.Write(() =>
                    {
                        assignRoles(realm);
                    });
                }

                await SyncTestHelpers.WaitForSyncAsync(realm);
            }

            return(uri);
        }