public void Test_RealmUpdate() { SyncTestHelpers.RequiresRos(); AsyncContext.Run(async() => { var userA = await SyncTestHelpers.GetUserAsync(); var userB = await SyncTestHelpers.GetUserAsync(); var realmUri = await CreateRealm(r => { CreatePermissions(RealmPermission.Get(r).Permissions); var reader = PermissionRole.Get(r, "reader"); reader.Users.Add(userA); reader.Users.Add(userB); var writer = PermissionRole.Get(r, "writer"); writer.Users.Add(userA); }); using (var realm = GetRealm(userA, realmUri)) { var subscription = await SubscribeToObjectsAsync(realm); AssertRealmPrivileges(realm, RealmPrivileges.Read | RealmPrivileges.Update); AssertClassPrivileges(realm, ClassPrivileges.Read | ClassPrivileges.Subscribe | ClassPrivileges.Create | ClassPrivileges.SetPermissions | ClassPrivileges.Update); AssertObjectPrivileges(realm, ObjectPrivileges.Read | ObjectPrivileges.Delete | ObjectPrivileges.SetPermissions | ObjectPrivileges.Update); Assert.That(subscription.Results.Count(), Is.EqualTo(3)); AddObjectsToRealm(realm, new[] { 4, 5, 6 }); Assert.That(subscription.Results.Count(), Is.EqualTo(6)); await WaitForSyncAsync(realm); Assert.That(subscription.Results.Count(), Is.EqualTo(6)); } using (var realm = GetRealm(userB, realmUri)) { var subscription = await SubscribeToObjectsAsync(realm); AssertRealmPrivileges(realm, RealmPrivileges.Read); AssertClassPrivileges(realm, ClassPrivileges.Read | ClassPrivileges.Subscribe); AssertObjectPrivileges(realm, ObjectPrivileges.Read); Assert.That(subscription.Results.Count(), Is.EqualTo(6)); AddObjectsToRealm(realm, new[] { 7, 8, 9 }); Assert.That(subscription.Results.Count(), Is.EqualTo(9)); await WaitForSyncAsync(realm); Assert.That(subscription.Results.Count(), Is.EqualTo(6)); } }); }
public void Test_RealmRead() { SyncTestHelpers.RequiresRos(); AsyncContext.Run(async() => { var userA = await SyncTestHelpers.GetUserAsync(); var userB = await SyncTestHelpers.GetUserAsync(); var realmUri = await CreateRealm(r => { CreatePermissions(RealmPermission.Get(r).Permissions); var role = PermissionRole.Get(r, "reader"); role.Users.Add(userA); }); using (var realm = GetRealm(userA, realmUri)) { var query = realm.All <ObjectWithPermissions>(); var subscription = query.Subscribe(); await subscription.WaitForSynchronizationAsync().Timeout(2000); AssertRealmPrivileges(realm, RealmPrivileges.Read); AssertClassPrivileges(realm, ClassPrivileges.Read | ClassPrivileges.Subscribe); AssertObjectPrivileges(realm, ObjectPrivileges.Read); Assert.That(subscription.Results.Count(), Is.EqualTo(3)); AddObjectsToRealm(realm, new[] { 4, 5, 6 }); Assert.That(subscription.Results.Count(), Is.EqualTo(6)); await WaitForSyncAsync(realm); Assert.That(subscription.Results.Count(), Is.EqualTo(3)); } using (var realm = GetRealm(userB, realmUri)) { var query = realm.All <ObjectWithPermissions>(); var subscription = query.Subscribe(); await subscription.WaitForSynchronizationAsync().Timeout(2000); AssertRealmPrivileges(realm, 0); AssertClassPrivileges(realm, 0); Assert.That(subscription.Results.Count(), Is.Zero); } }); }