public void GetAsync_RejectsCorruptJSONContent()
        {
            var u           = new Uri("http://test.com/test");
            var mockHandler = new MockHttpMessageHandler();
            var subject     = CreateWrapper(mockHandler);

            mockHandler.Add(u, Ok("=--%^&*{}{}{}{}{{@bgnffsegnj"));
            Assert.That(() => subject.GetAsync <TestObject>(u.ToString(), p), Throws.TypeOf <TexunaApiSystemException>());
        }
        public void GetAsync_PropagatesInternalServerError()
        {
            var u           = new Uri("http://test.com/test");
            var mockHandler = new MockHttpMessageHandler();
            var subject     = CreateWrapper(mockHandler);

            mockHandler.Add(u, new HttpResponseMessage(HttpStatusCode.InternalServerError));
            Assert.That(() => subject.GetAsync <TestObject>(u.ToString(), p), Throws.TypeOf <TexunaApiSystemException>());
        }
        public void GetAsync_RejectsNonJSONContent()
        {
            var u           = new Uri("http://test.com/test");
            var mockHandler = new MockHttpMessageHandler();
            var subject     = CreateWrapper(mockHandler);

            mockHandler.Add(u, Ok("<html><head><title>system exception</title></head></html>", mimeTypeHtml));
            Assert.That(() => subject.GetAsync <TestObject>(u.ToString(), p), Throws.TypeOf <TexunaApiSystemException>());
        }
        public async Task GetAsync_SuccessfullyReturnsPrimitives()
        {
            var mockHandler = new MockHttpMessageHandler();
            var subject     = CreateWrapper(mockHandler);

            var u1 = new Uri("http://test.com/test/int");

            mockHandler.Add(u1, Ok("1"));

            var u2 = new Uri("http://test.com/test/string");

            mockHandler.Add(u2, Ok("bob"));

            var result1 = await subject.GetAsync <int?>(u1.ToString(), p, false);

            var result2 = await subject.GetAsync <string>(u2.ToString(), p, false);

            Assert.That(result1.Response, Is.EqualTo(1));
            Assert.That(result2.Response, Is.EqualTo("bob"));
        }
        public async Task GetAsync_SuccessfullyReturnsObject()
        {
            var u           = new Uri("http://test.com/test");
            var mockHandler = new MockHttpMessageHandler();
            var subject     = CreateWrapper(mockHandler);
            var r           = Ok(JsonConvert.SerializeObject(new TestObject()
            {
                Int1 = 1
            }));

            mockHandler.Add(u, r);
            var result = await subject.GetAsync <TestObject>(u.ToString(), p, false);

            Assert.That(result.Response.Int1, Is.EqualTo(1));
        }