Пример #1
0
        public void TranslatesWebExceptionsWhenThrown()
        {
            // arrange
            var uri     = "http://localhost/";
            var factory = new TestWebRequestFactory();

            factory.RegisterExceptionForUri <WebException>(uri);
            var handler = new TestBaseRequestHandler(factory);

            // act
            Assert.ThrowsAsync <ApiCommunicationException>(async() => await handler.MakeRequestAsync(uri));

            // assert
        }
        public void CallOnErrorIfError()
        {
            // arrange
            var uri = "http://localhost/";
            var factory = new TestWebRequestFactory();
            factory.RegisterExceptionForUri<WebException>(uri);
            var handler = new TestBaseRequestHandler(factory);

            // act
            var data = new object();
            handler.MakeRequest(uri, null, (exuri, exception) => data = exception);

            // assert
            Assert.IsNotNull(data);
        }
        public void CallOnSuccessIfNoError()
        {
            // arrange
            var uri = "http://localhost/";
            var factory = new TestWebRequestFactory();
            factory.RegisterResultForUri(uri, "null");
            var handler = new TestBaseRequestHandler(factory);

            // act
            var data = new object();
            handler.MakeRequest(uri, (code, location, response) => data = response, null);

            // assert
            Assert.IsNull(data);
        }
        public void CanExtractJsonEntity()
        {
            // arrange
            var uri = "http://localhost/";
            var factory = new TestWebRequestFactory();
            factory.RegisterResultForUri(uri, "{ \"Name\": \"Paul\" }");
            var handler = new TestBaseRequestHandler(factory);

            // act
            UserContract data = null;
            handler.MakeRequest(uri, (code, location, response) => data = response, null);

            // assert
            Assert.IsNotNull(data);
            Assert.AreEqual("Paul", data.Name);
        }
Пример #5
0
        async public Task CanExtractCompressedJsonEntityAsync()
        {
            // arrange
            var uri     = "http://localhost/";
            var factory = new TestWebRequestFactory();

            factory.RegisterCompressedResultForUri(uri, "{ \"Name\": \"Paul\" }");
            var handler = new TestBaseRequestHandler(factory);

            // act
            var res = await handler.MakeRequestAsync(uri);

            // assert
            Assert.IsNotNull(res.Item2);
            Assert.AreEqual("Paul", res.Item2.Name);
        }
Пример #6
0
        public void CallOnErrorIfError()
        {
            // arrange
            var uri     = "http://localhost/";
            var factory = new TestWebRequestFactory();

            factory.RegisterExceptionForUri <WebException>(uri);
            var handler = new TestBaseRequestHandler(factory);

            // act
            var data = new object();

            handler.MakeRequest(uri, null, (exuri, exception) => data = exception);

            // assert
            Assert.IsNotNull(data);
        }
Пример #7
0
        public void CallOnSuccessIfNoError()
        {
            // arrange
            var uri     = "http://localhost/";
            var factory = new TestWebRequestFactory();

            factory.RegisterResultForUri(uri, "null");
            var handler = new TestBaseRequestHandler(factory);

            // act
            var data = new object();

            handler.MakeRequest(uri, (code, location, response) => data = response, null);

            // assert
            Assert.IsNull(data);
        }
Пример #8
0
        public void CanExtractCompressedJsonEntity()
        {
            // arrange
            var uri     = "http://localhost/";
            var factory = new TestWebRequestFactory();

            factory.RegisterCompressedResultForUri(uri, "{ \"Name\": \"Paul\" }");
            var handler = new TestBaseRequestHandler(factory);

            // act
            UserContract data = null;

            handler.MakeRequest(uri, (code, location, response) => data = response, null);

            // assert
            Assert.IsNotNull(data);
            Assert.AreEqual("Paul", data.Name);
        }
        async public void CanExtractCompressedJsonEntityAsync()
        {
            // arrange
            var uri = "http://localhost/";
            var factory = new TestWebRequestFactory();
            factory.RegisterCompressedResultForUri(uri, "{ \"Name\": \"Paul\" }");
            var handler = new TestBaseRequestHandler(factory);

            // act
            var res = await handler.MakeRequestAsync(uri);

            // assert
            Assert.IsNotNull(res.Item2);
            Assert.AreEqual("Paul", res.Item2.Name);
        }