public async Task GetContinuousChangesAsync_WithIdsFilter()
        {
            using var httpTest = new HttpTest();

            // Arrange
            var tokenSource = new CancellationTokenSource();
            var docId       = SetFeedResponse(httpTest);

            httpTest.RespondWithJson(new { ok = true });

            var filter = ChangesFeedFilter.DocumentIds(new[]
            {
                docId
            });

            // Act
            await foreach (var change in _rebels.GetContinuousChangesAsync(null, filter, tokenSource.Token))
            {
                Assert.Equal(docId, change.Id);
                tokenSource.Cancel();
            }

            // Assert
            httpTest
            .ShouldHaveCalled("http://localhost/rebels/_changes")
            .WithQueryParamValue("feed", "continuous")
            .WithQueryParamValue("filter", "_doc_ids")
            .WithJsonBody <ChangesFeedFilterDocuments>(f => f.DocumentIds.Contains(docId))
            .WithVerb(HttpMethod.Post);
        }
Ejemplo n.º 2
0
        public async Task ContinuousChanges()
        {
            using (var client = new CouchClient("http://localhost:5984"))
            {
                IEnumerable <string> dbs = await client.GetDatabasesNamesAsync().ConfigureAwait(false);

                CouchDatabase <Rebel> rebels = client.GetDatabase <Rebel>();

                if (dbs.Contains(rebels.Database))
                {
                    await client.DeleteDatabaseAsync <Rebel>().ConfigureAwait(false);
                }

                rebels = await client.CreateDatabaseAsync <Rebel>().ConfigureAwait(false);

                Rebel luke = await rebels.CreateAsync(new Rebel { Name = "Luke", Age = 19 }).ConfigureAwait(false);

                Assert.Equal("Luke", luke.Name);


                luke.Surname = "Vader";
                _            = Task.Run(async() =>
                {
                    await Task.Delay(2000);
                    await rebels.CreateOrUpdateAsync(luke);
                });

                var ids    = new[] { luke.Id };
                var option = new ChangesFeedOptions
                {
                    Since = "now"
                };
                var filter = ChangesFeedFilter.DocumentIds(ids);
                using var cancelSource = new CancellationTokenSource();
                await foreach (var _ in rebels.GetContinuousChangesAsync(option, filter, cancelSource.Token))
                {
                    cancelSource.Cancel();
                }

                await client.DeleteDatabaseAsync <Rebel>().ConfigureAwait(false);
            }
        }
Ejemplo n.º 3
0
        public async Task GetChangesAsync_WithIdsFilter()
        {
            using var httpTest = new HttpTest();

            // Arrange
            SetFeedResponse(httpTest);
            httpTest.RespondWithJson(new { ok = true });

            var docId  = Guid.NewGuid().ToString();
            var filter = ChangesFeedFilter.DocumentIds(new[]
            {
                docId
            });

            // Act
            var newR = await _rebels.GetChangesAsync(null, filter);

            // Assert
            httpTest
            .ShouldHaveCalled("http://localhost/rebels/_changes")
            .WithQueryParamValue("filter", "_doc_ids")
            .WithJsonBody <ChangesFeedFilterDocuments>(f => f.DocumentIds.Contains(docId))
            .WithVerb(HttpMethod.Post);
        }