예제 #1
0
        public async Task InvokeAsync_ExpectedResponseHeaders()
        {
            TestHttpMessageHandler handler = new TestHttpMessageHandler
            {
                RequestHandler = (HttpRequestMessage message) =>
                {
                    Assert.AreEqual("POST", message.Method.Method);
                    string body = Task.Run(() => message.Content.ReadAsStringAsync()).Result;
                    Assert.AreEqual("{\"testproperty\":\"testvalue\"}", body);
                },
                Headers = new Dictionary <string, string>()
                {
                    { "Test-Header-1", "TestValue1" }
                }
            };

            ClientRequest request = new ClientRequest()
            {
                Resource = "testresource",
                Method   = ClientRequestMethod.POST,
                Body     = new { testproperty = "testvalue" }
            };

            TestClientConnection connection = new TestClientConnection(handler);

            var response = await connection.InvokeAsync <object>(request);

            Assert.AreEqual(1, response.Headers.Count);
            Assert.AreEqual("TestValue1", response.Headers["Test-Header-1"].First());
        }
예제 #2
0
        public void Dispose_DisposesClient()
        {
            TestClientConnection connection = new TestClientConnection();

            connection.Dispose();

            Assert.IsTrue(((TestHttpClient)connection.Client).Disposed);
        }
예제 #3
0
        public void ComposeUri_EmptyQuery_ExpectedURI()
        {
            ClientRequest request = new ClientRequest()
            {
                Resource = "testresource",
                Query    = null
            };

            TestClientConnection client = new TestClientConnection();

            string uri = client.ComposeUri_Exposed(request);

            Assert.AreEqual("testresource", uri);
        }
예제 #4
0
        public async Task DeleteAsync_ExpectedRequest()
        {
            TestHttpMessageHandler handler = new TestHttpMessageHandler
            {
                RequestHandler = (HttpRequestMessage message) =>
                {
                    Assert.AreEqual("DELETE", message.Method.Method);
                    Assert.AreEqual("/testresource", message.RequestUri.AbsolutePath);
                }
            };

            TestClientConnection connection = new TestClientConnection(handler);

            await connection.DeleteAsync <object>("testresource");
        }
예제 #5
0
        public void ComposeUri_WithKeyNullValueQuery_ExpectedURI()
        {
            ClientRequest request = new ClientRequest()
            {
                Resource = "testresource",
                Query    = new Dictionary <string, string>()
                {
                    { "testkey", null }
                }
            };

            TestClientConnection client = new TestClientConnection();

            string uri = client.ComposeUri_Exposed(request);

            Assert.AreEqual("testresource?testkey", uri);
        }
예제 #6
0
        public async Task InvokeAsync_ExpectedRequest()
        {
            TestHttpMessageHandler handler = new TestHttpMessageHandler
            {
                RequestHandler = (HttpRequestMessage message) =>
                {
                    Assert.AreEqual("POST", message.Method.Method);
                    Assert.AreEqual("/testresource", message.RequestUri.AbsolutePath);
                    string body = Task.Run(() => message.Content.ReadAsStringAsync()).Result;
                    Assert.AreEqual("{\"testproperty\":\"testvalue\"}", body);
                }
            };

            TestClientConnection connection = new TestClientConnection(handler);

            await connection.InvokeAsync <object>("testresource", ClientRequestMethod.POST, new { testproperty = "testvalue" });
        }
예제 #7
0
        public async Task InvokeAsync_InvalidJsonResponse_ThrowsUKFastClientRequestException()
        {
            TestHttpMessageHandler handler = new TestHttpMessageHandler
            {
                Content = "invalidjson"
            };

            ClientRequest request = new ClientRequest()
            {
                Resource = "testresource",
                Method   = ClientRequestMethod.GET
            };

            TestClientConnection connection = new TestClientConnection(handler);

            await Assert.ThrowsExceptionAsync <UKFastClientRequestException>(() => connection.InvokeAsync <object>(request));
        }
예제 #8
0
        public void ComposeUri_WithMultipleQuery_ExpectedURI()
        {
            ClientRequest request = new ClientRequest()
            {
                Resource = "testresource",
                Query    = new Dictionary <string, string>()
                {
                    { "testkey1", "testvalue1" },
                    { "testkey2", "testvalue2" }
                }
            };

            TestClientConnection client = new TestClientConnection();

            string uri = client.ComposeUri_Exposed(request);

            Assert.AreEqual("testresource?testkey1=testvalue1&testkey2=testvalue2", uri);
        }
예제 #9
0
        public async Task InvokeAsync_ExpectedMethod()
        {
            TestHttpMessageHandler handler = new TestHttpMessageHandler
            {
                RequestHandler = (HttpRequestMessage message) =>
                {
                    Assert.AreEqual("GET", message.Method.Method);
                }
            };

            ClientRequest request = new ClientRequest()
            {
                Resource = "testresource",
                Method   = ClientRequestMethod.GET,
            };

            TestClientConnection connection = new TestClientConnection(handler);

            await connection.InvokeAsync <object>(request);
        }