public async Task PostCursorAsync_ShouldSucceed()
        {
            var response = await _cursorApi.PostCursorAsync <MyModel>(
                "RETURN { MyProperty: CONCAT('This is a ', @testString) }",
                new Dictionary <string, object> {
                ["testString"] = "robbery"
            });

            var result = response.Result;

            Assert.Equal(1, result.Count);
            Assert.Equal("This is a robbery", result.First().MyProperty);
        }
        public async Task PostCursorAsync_ShouldUseHeaderProperties()
        {
            // Mock the IApiClientTransport.
            var mockTransport = new Mock <IApiClientTransport>();

            // Mock the IApiClientResponse.
            var mockResponse = new Mock <IApiClientResponse>();

            // Mock the IApiClientResponseContent.
            var mockResponseContent = new Mock <IApiClientResponseContent>();

            // Setup the mocked api client response.
            mockResponse.Setup(x => x.Content)
            .Returns(mockResponseContent.Object);
            mockResponse.Setup(x => x.IsSuccessStatusCode)
            .Returns(true);

            // Setup the mocked api client transport.
            WebHeaderCollection requestHeader = null;

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

            string dummyTransactionId = "dummy transaction Id";

            // Call the method to create the cursor.
            var apiClient = new CursorApiClient(mockTransport.Object);
            await apiClient.PostCursorAsync <MyModel>(
                new PostCursorBody
            {
                Query    = "FOR doc IN [{ myProperty: CONCAT('This is a ', @testString) }] LIMIT 1 RETURN doc",
                BindVars = new Dictionary <string, object> {
                    ["testString"] = "robbery"
                }
            },
                new CursorHeaderProperties
            {
                TransactionId = dummyTransactionId
            });

            // Check that the header and values are there.
            Assert.NotNull(requestHeader);
            Assert.Contains(CustomHttpHeaders.StreamTransactionHeader, requestHeader.AllKeys);
            Assert.Equal(dummyTransactionId, requestHeader.Get(CustomHttpHeaders.StreamTransactionHeader));
        }
        public async Task PostCursorAsync_ShouldThrow_WhenErrorDeserializationFailed()
        {
            var mockTransport = new Mock <IApiClientTransport>();

            var mockResponse = new Mock <IApiClientResponse>();

            var mockResponseContent = new Mock <IApiClientResponseContent>();

            string mockJsonError = "{ errorNum: \"some_error\" }";

            mockResponseContent.Setup(x => x.ReadAsStreamAsync())
            .Returns(Task.FromResult <Stream>(
                         new MemoryStream(Encoding.UTF8.GetBytes(mockJsonError))));

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

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

            mockTransport.Setup(x => x.PostAsync(
                                    It.IsAny <string>(),
                                    It.IsAny <byte[]>(),
                                    It.IsAny <WebHeaderCollection>()))
            .Returns(Task.FromResult(mockResponse.Object));

            var cursorApi = new CursorApiClient(mockTransport.Object);

            var ex = await Assert.ThrowsAsync <SerializationException>(async() =>
            {
                await cursorApi.PostCursorAsync <object>("RETURN true");
            });

            Assert.NotNull(ex.Message);
            Assert.Contains("while Deserializing an error response", ex.Message);
            Assert.NotNull(ex.InnerException);
        }