示例#1
0
        public async Task DeleteDocuments_ShouldSucceed()
        {
            var docTasks = new[] {
                new Dictionary <string, object> {
                    ["Message"] = "first"
                },
                new Dictionary <string, object> {
                    ["Message"] = "second"
                }
            }
            .Select(item => _docClient.PostDocumentAsync(_testCollection, item))
            .ToList();

            PostDocumentResponse <Dictionary <string, object> >[] docs =
                await Task.WhenAll(docTasks);

            Assert.Collection(docs,
                              (item) => Assert.NotNull(item._id),
                              (item) => Assert.NotNull(item._id));

            var response = await _docClient.DeleteDocumentsAsync(_testCollection, docs.Select(d => d._id).ToList());

            Assert.Collection(response,
                              (item) => Assert.NotNull(item._id),
                              (item) => Assert.NotNull(item._id));

            // Should get "not found" for deleted docs
            Assert.Collection(docs,
                              async(item) =>
            {
                var ex = await Assert.ThrowsAsync <ApiErrorException>(async() =>
                                                                      await _docClient.GetDocumentAsync <object>(item._id));

                Assert.Equal(NOT_FOUND_NUM, ex.ApiError.ErrorNum);     // document not found)
            },
                              async(item) =>
            {
                var ex = await Assert.ThrowsAsync <ApiErrorException>(async() =>
                                                                      await _docClient.GetDocumentAsync <object>(item._id));

                Assert.Equal(NOT_FOUND_NUM, ex.ApiError.ErrorNum);     // document not found)
            });
        }
        public async Task DeleteDocuments_ShouldUseQueryParameters_WhenProvided()
        {
            var mockTransport = new Mock <IApiClientTransport>();

            var mockResponse = new Mock <IApiClientResponse>();

            var mockResponseContent = new Mock <IApiClientResponseContent>();

            mockResponse.Setup(x => x.Content)
            .Returns(mockResponseContent.Object);

            mockResponse.Setup(x => x.IsSuccessStatusCode)
            .Returns(true);

            string requestUri = null;

            mockTransport.Setup(x => x.DeleteAsync(It.IsAny <string>(), It.IsAny <byte[]>()))
            .Returns((string uri, byte[] content) =>
            {
                requestUri = uri;
                return(Task.FromResult(mockResponse.Object));
            });

            var client = new DocumentApiClient(mockTransport.Object);

            await client.DeleteDocumentsAsync(
                "mycollection",
                new List <string>() { "0123456789" },
                new DeleteDocumentsQuery
            {
                IgnoreRevs  = true,
                ReturnOld   = true,
                Silent      = true,
                WaitForSync = true
            });

            Assert.NotNull(requestUri);
            Assert.Contains("ignoreRevs=true", requestUri);
            Assert.Contains("returnOld=true", requestUri);
            Assert.Contains("silent=true", requestUri);
            Assert.Contains("waitForSync=true", requestUri);
        }