Example #1
0
        public void MethodNotAllowedOnHttpPut()
        {
            if (Helper.IsNetworkAvailable())
            {
                var http = new DefaultHttpRequester();
                var request = new DefaultHttpRequest();
                request.Address = new Uri("http://httpbin.org/get");
                request.Method = HttpMethod.PUT;
                request.Content = Helper.StreamFromString("Should be ignored");

                var response = http.Request(request);
                Assert.IsNotNull(response);
                Assert.AreEqual(405, (int)response.StatusCode);
                Assert.IsTrue(response.Content.CanRead);
                Assert.IsTrue(response.Headers.Count > 0);
            }
        }
Example #2
0
        public void AsyncHttpGetRequest()
        {
            if (Helper.IsNetworkAvailable())
            {
                var http = new DefaultHttpRequester();
                var request = new DefaultHttpRequest();
                request.Address = new Uri("http://httpbin.org/robots.txt");
                request.Method = HttpMethod.GET;

                var response = http.RequestAsync(request);
                Assert.IsNotNull(response);
                Assert.IsFalse(response.IsCompleted);

                var result = response.Result;

                Assert.IsTrue(response.IsCompleted);
                Assert.IsTrue(result.Content.CanRead);
                Assert.IsTrue(result.Headers.Count > 0);

                var content = new StreamReader(result.Content);
                Assert.AreEqual("User-agent: *\nDisallow: /deny\n", content.ReadToEnd());
            }
        }
Example #3
0
        public void RequestUserAgentString()
        {
            if (Helper.IsNetworkAvailable())
            {
                var http = new DefaultHttpRequester();
                var request = new DefaultHttpRequest();
                request.Address = new Uri("http://httpbin.org/user-agent");
                request.Method = HttpMethod.GET;

                var response = http.Request(request);
                Assert.IsNotNull(response);
                Assert.AreEqual(200, (int)response.StatusCode);
                Assert.IsTrue(response.Content.CanRead);
                Assert.IsTrue(response.Headers.Count > 0);

                var stream = new StreamReader(response.Content);
                Assert.IsNotNull(stream);

                var content = stream.ReadToEnd();
                Assert.IsTrue(content.Length > 0);
                Assert.AreEqual("{\n  \"user-agent\": \"" + Info.Agent + "\"\n}", content);
            }
        }
Example #4
0
        public void StatusCode500OfHttpGetRequest()
        {
            if (Helper.IsNetworkAvailable())
            {
                var http = new DefaultHttpRequester();
                var request = new DefaultHttpRequest();
                request.Address = new Uri("http://httpbin.org/status/500");
                request.Method = HttpMethod.GET;

                var response = http.Request(request);
                Assert.IsNotNull(response);
                Assert.AreEqual(500, (int)response.StatusCode);
                Assert.IsTrue(response.Content.CanRead);
                Assert.IsTrue(response.Headers.Count > 0);
            }
        }
Example #5
0
        public void SimpleHttpPutRequest()
        {
            if (Helper.IsNetworkAvailable())
            {
                var http = new DefaultHttpRequester();
                var request = new DefaultHttpRequest();
                request.Address = new Uri("http://httpbin.org/put");
                request.Method = HttpMethod.PUT;
                request.Content = Helper.StreamFromString("PUT THIS THING BACK");

                var response = http.Request(request);
                Assert.IsNotNull(response);
                Assert.AreEqual(200, (int)response.StatusCode);
                Assert.IsTrue(response.Content.CanRead);
                Assert.IsTrue(response.Headers.Count > 0);

                var stream = new StreamReader(response.Content);
                Assert.IsNotNull(stream);

                var content = stream.ReadToEnd();
                Assert.IsTrue(content.Length > 0);
                Assert.IsTrue(content.Contains("\"data\": \"PUT THIS THING BACK\""));
            }
        }
Example #6
0
        public void SimpleHttpDeleteRequest()
        {
            if (Helper.IsNetworkAvailable())
            {
                var http = new DefaultHttpRequester();
                var request = new DefaultHttpRequest();
                request.Address = new Uri("http://httpbin.org/delete");
                request.Method = HttpMethod.DELETE;
                request.Content = Helper.StreamFromString("Should be ignored");

                var response = http.Request(request);
                Assert.IsNotNull(response);
                Assert.AreEqual(200, (int)response.StatusCode);
                Assert.IsTrue(response.Content.CanRead);
                Assert.IsTrue(response.Headers.Count > 0);
            }
        }