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

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

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

            var filter = ChangesFeedFilter.Selector <Rebel>(rebel => rebel.Id == 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", "_selector")
            .WithContentType("application/json")
            .With(call => call.RequestBody == $"{{\"selector\":{{\"_id\":\"{docId}\"}}}}")
            .WithVerb(HttpMethod.Post);
        }
Beispiel #2
0
        public async Task Changes()
        {
            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);

                var options = new ChangesFeedOptions
                {
                    IncludeDocs = true
                };
                var filter        = ChangesFeedFilter.Selector <Rebel>(r => r.Name == "Luke" && r.Age == 19);
                var changesResult = await rebels.GetChangesAsync(options, filter);

                Assert.NotEmpty(changesResult.Results);
                Assert.Equal(changesResult.Results[0].Id, luke.Id);

                await client.DeleteDatabaseAsync <Rebel>().ConfigureAwait(false);
            }
        }
Beispiel #3
0
        public async Task GetChangesAsync_WithSelectorFilter()
        {
            using var httpTest = new HttpTest();

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

            var docId  = Guid.NewGuid().ToString();
            var filter = ChangesFeedFilter.Selector <Rebel>(rebel => rebel.Id == docId);

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

            // Assert
            httpTest
            .ShouldHaveCalled("http://localhost/rebels/_changes")
            .WithQueryParamValue("filter", "_selector")
            .WithContentType("application/json")
            .With(call => call.RequestBody == $"{{\"selector\":{{\"_id\":\"{docId}\"}}}}")
            .WithVerb(HttpMethod.Post);
        }