Пример #1
0
        public async Task DeleteDocument_ShouldSucceed()
        {
            Dictionary <string, object> document = new Dictionary <string, object> {
                ["key"] = "value"
            };
            var response = await _docClient.PostDocumentAsync(_testCollection, document);

            Assert.NotNull(response._id);

            var deleteResponse = await _docClient.DeleteDocumentAsync(response._id);

            Assert.Null(deleteResponse.Old); // we didn't request `Old` so it should be null
            Assert.Equal(response._id, deleteResponse._id);
            Assert.Equal(response._key, deleteResponse._key);
            Assert.Equal(response._rev, deleteResponse._rev);

            var getDocumentResponse = await _docClient.GetDocumentAsync <object>(response._id);

            Assert.False(getDocumentResponse.IsSuccess);
            Assert.Equal(NOT_FOUND_NUM, getDocumentResponse.ResponseDetails.ErrorNum);
            Assert.Equal(HttpStatusCode.NotFound, getDocumentResponse.ResponseDetails.Code);

            _docClient.ThrowErrorsAsExceptions = true;
            var ex = await Assert.ThrowsAsync <ApiErrorException>(async() =>
                                                                  await _docClient.GetDocumentAsync <object>(response._id));

            Assert.Equal(NOT_FOUND_NUM, ex.ResponseDetails.ErrorNum); // document not found
        }
Пример #2
0
        public async Task DeleteDocument_ShouldSucceed()
        {
            Dictionary <string, object> document = new Dictionary <string, object> {
                ["key"] = "value"
            };
            var response = await _docClient.PostDocumentAsync("TestCollection", document);

            Assert.NotNull(response._id);

            var deleteResponse = await _docClient.DeleteDocumentAsync(response._id);

            Assert.Null(deleteResponse.Old); // we didn't request `Old` so it should be null
            Assert.Equal(response._id, deleteResponse._id);
            Assert.Equal(response._key, deleteResponse._key);
            Assert.Equal(response._rev, deleteResponse._rev);

            var ex = await Assert.ThrowsAsync <ApiErrorException>(async() =>
                                                                  await _docClient.GetDocumentAsync <object>(response._id));

            Assert.Equal(NOT_FOUND_NUM, ex.ApiError.ErrorNum); // document not found
        }
        public async Task DeleteDocument_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>()))
            .Returns((string uri) =>
            {
                requestUri = uri;
                return(Task.FromResult(mockResponse.Object));
            });

            var client = new DocumentApiClient(mockTransport.Object);

            await client.DeleteDocumentAsync(
                "mycollection/0123456789",
                new DeleteDocumentQuery
            {
                ReturnOld   = true,
                Silent      = true,
                WaitForSync = true
            });

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