Example #1
0
        public void GetInstanceAsync_ShouldDownloadRealm(bool singleTransaction)
        {
            AsyncContext.Run(async() =>
            {
                var user = await SyncTestHelpers.GetUser();

                var realmUri = new Uri(SyncTestHelpers.GetRealmUrl());

                var config      = new SyncConfiguration(user, realmUri);
                var asyncConfig = new SyncConfiguration(user, realmUri, config.DatabasePath + "_async");

                try
                {
                    using (var realm = Realm.GetInstance(config))
                    {
                        AddDummyData(realm, singleTransaction);

                        await realm.GetSession().WaitForUploadAsync();
                    }

                    using (var asyncRealm = await Realm.GetInstanceAsync(asyncConfig))
                    {
                        Assert.That(asyncRealm.All <IntPrimaryKeyWithValueObject>().Count(), Is.EqualTo(500));
                    }
                }
                finally
                {
                    Realm.DeleteRealm(config);
                    Realm.DeleteRealm(asyncConfig);
                }
            });
        }
 public void TrustedCA_WhenFileDoesntExist_Throws()
 {
     AsyncContext.Run(async() =>
     {
         var user   = await SyncTestHelpers.GetUser();
         var config = new SyncConfiguration(user, new Uri(SyncTestHelpers.GetRealmUrl()))
         {
             TrustedCAPath = "something.pem"
         };
         Assert.That(() => Realm.GetInstance(config), Throws.TypeOf <FileNotFoundException>());
     });
 }
Example #3
0
        public void GetInstanceAsync_OpensReadonlyRealm(bool singleTransaction)
        {
            AsyncContext.Run(async() =>
            {
                var alice = await SyncTestHelpers.GetUser();
                var bob   = await SyncTestHelpers.GetUser();

                var realmUrl    = SyncTestHelpers.GetRealmUrl(userId: alice.Identity);
                var aliceConfig = new SyncConfiguration(alice, new Uri(realmUrl));
                var aliceRealm  = Realm.GetInstance(aliceConfig);

                // TODO: replace with wrapper API
                await GrantPermissions(alice, bob, realmUrl);

                AddDummyData(aliceRealm, singleTransaction);

                var bobConfig = new SyncConfiguration(bob, new Uri(realmUrl));
                var bobRealm  = await Realm.GetInstanceAsync(bobConfig);

                var bobsObjects   = bobRealm.All <IntPrimaryKeyWithValueObject>();
                var alicesObjects = aliceRealm.All <IntPrimaryKeyWithValueObject>();
                Assert.That(bobsObjects.Count(), Is.EqualTo(alicesObjects.Count()));

                var bobTcs = new TaskCompletionSource <object>();
                bobsObjects.AsRealmCollection().CollectionChanged += (sender, e) =>
                {
                    bobTcs.TrySetResult(null);
                };

                aliceRealm.Write(() =>
                {
                    aliceRealm.Add(new IntPrimaryKeyWithValueObject
                    {
                        Id          = 9999,
                        StringValue = "Some value"
                    });
                });

                await bobTcs.Task.Timeout(1000);

                Assert.That(bobsObjects.Count(), Is.EqualTo(alicesObjects.Count()));

                var bobObject = bobRealm.Find <IntPrimaryKeyWithValueObject>(9999);
                Assert.That(bobObject, Is.Not.Null);
                Assert.That(bobObject.StringValue, Is.EqualTo("Some value"));
            });
        }
        private static void TestSSLCore(Action <SyncConfiguration> setupSecureConfig, bool openAsync)
        {
            AsyncContext.Run(async() =>
            {
                var user     = await SyncTestHelpers.GetUser();
                var realmUrl = SyncTestHelpers.GetRealmUrl();
                var config   = new SyncConfiguration(user, new Uri(realmUrl));

                var secureRealmUrl = realmUrl.Replace("realm://", "realms://").Replace("9080", "9443");
                var secureConfig   = new SyncConfiguration(user, new Uri(secureRealmUrl), config.DatabasePath + "2");
                setupSecureConfig(secureConfig);

                try
                {
                    using (var realm = Realm.GetInstance(config))
                    {
                        realm.Write(() =>
                        {
                            realm.Add(new IntPrimaryKeyWithValueObject
                            {
                                Id          = 1,
                                StringValue = "some value"
                            });
                        });

                        await realm.GetSession().WaitForUploadAsync();
                    }

                    using (var newRealm = await SyncTestHelpers.GetInstanceAsync(secureConfig, openAsync))
                    {
                        var items = newRealm.All <IntPrimaryKeyWithValueObject>();

                        Assert.That(items.Count(), Is.EqualTo(1));
                        Assert.That(items.Single().StringValue, Is.EqualTo("some value"));
                    }
                }
                finally
                {
                    Realm.DeleteRealm(config);
                    Realm.DeleteRealm(secureConfig);
                }
            });
        }