Example #1
0
        public async void GetAllDbNamesAsync_Request(
            bool?conflicts,
            bool?descending,
            string endKey,
            string endkey_docid,
            bool?include_docs,
            bool?inclusive_end,
            string key,
            IEnumerable <string> keys,
            int?limit,
            int?skip,
            ListQueryParams.StaleOption?stale,
            string startKey,
            string startkey_docid,
            bool?update_seq
            )
        {
            //arrange.
            var queryParams = new ListQueryParams
            {
                Conflicts    = conflicts, Descending = descending, EndKey = endKey, EndKey_DocId = endkey_docid,
                Include_Docs = include_docs, Inclusive_End = inclusive_end, Key = key, Keys = keys,
                Limit        = limit, Skip = skip, Stale = stale, StartKey = startKey, StartKey_DocId = startkey_docid,
                Update_Seq   = update_seq
            };

            //act.
            await _sut.GetAllDbNamesAsync(queryParams);

            //assert.
            var expectedRelativeUrl = QueryParams.AppendQueryParams("_all_dbs", queryParams);

            _handler.Verify(h => h.SendRequestAsync(expectedRelativeUrl, RequestMethod.GET, RequestIs.Empty()), Times.Once);
        }
Example #2
0
        public void AppendQueryParams_RequiresUrl()
        {
            //arrange.
            string url = null;

            //act / assert.
            Assert.Throws <ArgumentNullException>(() => QueryParams.AppendQueryParams(url, new ListQueryParams {
            }));
        }
Example #3
0
        public async Task GetAllDocumentsAsync_Request_Passes_Include_Docs_Even_For_Empty_Params()
        {
            //act.
            await _sut.GetAllStringDocumentsAsync(null);

            //assert.
            var expectedUrl = QueryParams.AppendQueryParams("_all_docs", new ListQueryParams());

            _handler.Verify(h => h.SendRequestAsync(expectedUrl, RequestMethod.GET, It.IsAny <Request>()), Times.Once);
        }
Example #4
0
        public void AppendQueryParams_DoesNotAppend_IfQueryParamsIsNull()
        {
            //arrange.
            var url = "url";

            //act.
            var newUrl = QueryParams.AppendQueryParams(url, null);

            //assert.
            Assert.Equal(url, newUrl);
        }
Example #5
0
        public void AppendQueryParams_DoesNotAppend_IfQueryParamsIsEmpty()
        {
            //arrange.
            var url         = "url";
            var queryParams = ListQueryParams.CreateEmpty();

            //act.
            var newUrl = QueryParams.AppendQueryParams(url, queryParams);

            //assert.
            Assert.Equal(url, newUrl);
        }
Example #6
0
        public void AppendQueryParams_AddsQueryWithoutQMark_IfQMarkAtTheEnd()
        {
            //arrange.
            var url         = "url?";
            var queryParams = new ListQueryParams {
                EndKey = "end-key"
            };

            //act.
            var newUrl = QueryParams.AppendQueryParams(url, queryParams);

            //assert.
            Assert.Equal($"{url}{queryParams.ToQueryString()}", newUrl);
        }
Example #7
0
        public void AppendQueryParam_AppendsQueryWithoutQMark_IfQMarkPresent()
        {
            //arrange.
            var url         = "url?param1=value1";
            var queryParams = new ListQueryParams {
                EndKey = "end-key"
            };

            //act.
            var newUrl = QueryParams.AppendQueryParams(url, queryParams);

            //assert.
            Assert.Equal($"{url}&{queryParams.ToQueryString()}", newUrl);
        }
Example #8
0
        public void AppendQueryParams_AppendsQueryWithQMark_IfNoneYet()
        {
            //arrange.
            var url         = "url";
            var queryParams = new ListQueryParams {
                EndKey = "end-key"
            };

            //act.
            var newUrl = QueryParams.AppendQueryParams(url, queryParams);

            //assert.
            Assert.Equal($"{url}?{queryParams.ToQueryString()}", newUrl);
        }
Example #9
0
        public async Task SaveDocumentAsync_Request(string documentJson, bool batch, bool newEdits)
        {
            //arrange.
            var docQueryParams = new DocUpdateParams {
                Batch = batch, New_Edits = newEdits
            };

            //act.
            await _sut.SaveStringDocumentAsync(documentJson, docQueryParams);

            //assert.
            var expectedUrl = QueryParams.AppendQueryParams(string.Empty, docQueryParams);

            _handler.Verify(h => h.SendRequestAsync(expectedUrl, RequestMethod.POST, RequestIs.JsonString(documentJson)));
        }
Example #10
0
        public async Task SaveAttachmentAsync_Request()
        {
            //arrange.
            string docId = "123", attName = "234", revision = "345";
            var    attachment = new byte[] { 1, 3, 2 };

            //act.
            await _sut.SaveAttachmentAsync(docId, attName, revision, attachment);

            //assert.
            var expectedUrl = QueryParams.AppendQueryParams($"{docId}/{attName}", new AttachmentQueryParams {
                Rev = revision
            });

            _handler.Verify(h => h.SendRequestAsync(expectedUrl, RequestMethod.PUT, RequestIs.ByteArray(attachment)), Times.Once);
        }
Example #11
0
        public async Task DeleteDocumentAsync_Request(bool batch)
        {
            //arrange.
            var docId    = "some doc id 123";
            var revision = "some revision 321";

            //act.
            await _sut.DeleteDocumentAsync(docId, revision, batch);

            //assert.
            var expectedUrl = QueryParams.AppendQueryParams(docId, new DeleteDocParams {
                Batch = batch, Revision = revision
            });

            _handler.Verify(h => h.SendRequestAsync(expectedUrl, RequestMethod.DELETE, RequestIs.Empty()), Times.Once);
        }
Example #12
0
        public async Task DeleteAttachmentAsync_Request(bool batch)
        {
            //arrange.
            var docId    = "docid-123";
            var attName  = "attName-234";
            var revision = "rev-543";

            //act.
            await _sut.DeleteAttachmentAsync(docId, attName, revision, batch);

            //assert.
            var expectedUrl = QueryParams.AppendQueryParams($"{docId}/{attName}", new DeleteDocParams {
                Revision = revision, Batch = batch
            });

            _handler.Verify(h => h.SendRequestAsync(expectedUrl, RequestMethod.DELETE, RequestIs.Empty()), Times.Once);
        }
Example #13
0
        public async Task GetDocumentsAsync_Request(
            bool?conflicts,
            bool?descending,
            string endKey,
            string endKey_DocId,
            bool?include_Docs,
            bool?inclusive_End,
            string key,
            IEnumerable <string> keys,
            int?limit,
            int?skip,
            ListQueryParams.StaleOption?stale,
            string startKey,
            string startKey_DocId,
            bool?update_Seq)
        {
            //arrange.
            var docIdList = new[] { "1", "2", "3" };

            var queryParams = new ListQueryParams
            {
                Conflicts      = conflicts,
                Descending     = descending,
                EndKey         = endKey,
                EndKey_DocId   = endKey_DocId,
                Include_Docs   = include_Docs,
                Inclusive_End  = inclusive_End,
                Key            = key,
                Keys           = keys,
                Limit          = limit,
                Skip           = skip,
                Stale          = stale,
                StartKey       = startKey,
                StartKey_DocId = startKey_DocId,
                Update_Seq     = update_Seq
            };

            //act.
            await _sut.GetStringDocumentsAsync(docIdList, queryParams);

            //assrert.
            var expectedUrl = QueryParams.AppendQueryParams("_all_docs", queryParams);

            _handler.Verify(h => h.SendRequestAsync(expectedUrl, RequestMethod.POST,
                                                    RequestIs.JsonObject(new { keys = docIdList })), Times.Once);
        }
Example #14
0
        public async Task GetDocumentAsync_Request(
            string docId,
            bool?attachments = null,
            System.Collections.Generic.IEnumerable <string> attr_since = null,
            bool?attr_encoding_info = null,
            bool?conflicts          = null,
            bool?deleted_conflicts  = null,
            bool?latest             = null,
            bool?local_seq          = null,
            bool?meta      = null,
            string rev     = null,
            bool?revs      = null,
            bool?revs_info = null)
        {
            //arrange.
            var docQueryParams = new DocQueryParams
            {
                Attachments       = attachments,
                Atts_Since        = attr_since,
                Att_Encoding_Info = attr_encoding_info,
                Conflicts         = conflicts,
                Deleted_Conflicts = deleted_conflicts,
                Latest            = latest,
                Local_Seq         = local_seq,
                Meta      = meta,
                Rev       = rev,
                Revs      = revs,
                Revs_Info = revs_info
            };

            //act.
            await _sut.GetStringDocumentAsync(docId, docQueryParams);

            //assert.
            var expectedUrl = QueryParams.AppendQueryParams(docId, docQueryParams);

            _handler.Verify(h => h.SendRequestAsync(expectedUrl, RequestMethod.GET, RequestIs.Empty()), Times.Once);
        }