Exemplo n.º 1
0
        public async Task PutDocument_ShouldSucceed()
        {
            var doc1     = new { _key = "test", stuff = "test" };
            var response = await _docClient.PostDocumentAsync("TestCollection", doc1);

            var updateResponse = await _docClient.PutDocumentAsync(
                response._id,
                new { stuff = "new" });

            Assert.NotNull(response._rev);
            Assert.NotNull(updateResponse._rev);
            Assert.NotEqual(response._rev, updateResponse._rev);
        }
        public async Task PutDocument_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.PutAsync(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.PutDocumentAsync(
                "mycollection/0123456789",
                new { },
                new PutDocumentQuery
            {
                IgnoreRevs  = true,
                ReturnOld   = true,
                ReturnNew   = true,
                Silent      = true,
                WaitForSync = true
            });

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