public void ShouldHandle_WhenRealmExists_InvokedOnStart()
        {
            SyncTestHelpers.RunRosTestAsync(async() =>
            {
                var paths   = new List <string>();
                var handler = new ProxyingHandler(path =>
                {
                    paths.Add(path);
                    return(false);
                }, null);

                var(_, userId1) = await CreateRandomRealmAsync("emails");
                var(_, userId2) = await CreateRandomRealmAsync("invoices");
                var(_, userId3) = await CreateRandomRealmAsync("invoices");
                var(_, userId4) = await CreateRandomRealmAsync("deep/folder/hierarchy");

                var config = await GetConfiguration(handler);
                using (var notifier = Notifier.StartAsync(config))
                {
                    var expectedPaths = new[]
                    {
                        $"/{userId1}/emails",
                        $"/{userId2}/invoices",
                        $"/{userId3}/invoices",
                        $"/{userId4}/deep/folder/hierarchy"
                    };

                    // ROS may contain other Realms and it takes some time to go over all.
                    // This will check if we've received ShouldHandle prompt for all expected ones
                    // every 100 ms for 10 seconds.
                    var containsExpected = await TestHelpers.EnsureAsync(() => expectedPaths.All(paths.Contains),
                                                                         retryDelay: 100,
                                                                         attempts: 100); // 10 seconds

                    Assert.True(containsExpected);

                    var(_, userId5) = await CreateRandomRealmAsync("newlyaddedrealm");

                    var containsNewRealm = await TestHelpers.EnsureAsync(() => paths.Contains($"/{userId5}/newlyaddedrealm"),
                                                                         retryDelay: 100,
                                                                         attempts: 100); // 10 seconds

                    Assert.True(containsNewRealm);
                }
            }, timeout: 30000);
        }
Exemple #2
0
        public void SmokeTest()
        {
            SyncTestHelpers.RunRosTestAsync(async() =>
            {
                var(realm, userId) = await CreateRandomRealmAsync("modifications");

                var changeDetails = new List <IChangeDetails>();
                var handler       = new ProxyingHandler(path => path == $"/{userId}/modifications",
                                                        details =>
                {
                    changeDetails.Add(details);
                    return(Task.CompletedTask);
                });

                var config = await GetConfiguration(handler);

                using (var notifier = await Notifier.StartAsync(config))
                    using (realm)
                    {
                        var obj = new IntPropertyObject {
                            Int = 3
                        };
                        realm.Write(() => realm.Add(obj));

                        var containsInsertion = await EnsureChangesAsync <IntPropertyObject>(changeDetails, 1, change =>
                        {
                            return(change.Insertions.Length == 1 &&
                                   change.Deletions.Length == 0 &&
                                   change.Modifications.Length == 0 &&
                                   change.Insertions[0].CurrentIndex == 0 &&
                                   change.Insertions[0].PreviousIndex == -1);
                        });

                        Assert.True(containsInsertion);

                        realm.Write(() => obj.Int = 4);

                        var containsModification = await EnsureChangesAsync <IntPropertyObject>(changeDetails, 2, change =>
                        {
                            return(change.Insertions.Length == 0 &&
                                   change.Deletions.Length == 0 &&
                                   change.Modifications.Length == 1 &&
                                   change.Modifications[0].CurrentIndex == 0 &&
                                   change.Modifications[0].PreviousIndex == 0);
                        });

                        Assert.True(containsModification);

                        realm.Write(() => realm.Remove(obj));

                        var containsDeletion = await EnsureChangesAsync <IntPropertyObject>(changeDetails, 3, change =>
                        {
                            return(change.Insertions.Length == 0 &&
                                   change.Deletions.Length == 1 &&
                                   change.Modifications.Length == 0 &&
                                   change.Deletions[0].CurrentIndex == -1 &&
                                   change.Deletions[0].PreviousIndex == 0);
                        });

                        Assert.True(containsDeletion);
                    }
            }, timeout: 1000000);
        }