Пример #1
0
        public void MethodNotAllowedOnHttpPut()
        {
            if (Helper.IsNetworkAvailable())
            {
                var http = new DefaultRequester(new DefaultInfo());
                var request = new DefaultRequest();
                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);
            }
        }
Пример #2
0
        public void AsyncHttpGetRequest()
        {
            if (Helper.IsNetworkAvailable())
            {
                var http = new DefaultRequester(new DefaultInfo());
                var request = new DefaultRequest();
                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());
            }
        }
Пример #3
0
        public void RequestUserAgentString()
        {
            if (Helper.IsNetworkAvailable())
            {
                var info = new DefaultInfo();
                var http = new DefaultRequester(info);
                var request = new DefaultRequest();
                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);
            }
        }
Пример #4
0
        public void StatusCode500OfHttpGetRequest()
        {
            if (Helper.IsNetworkAvailable())
            {
                var http = new DefaultRequester(new DefaultInfo());
                var request = new DefaultRequest();
                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);
            }
        }
Пример #5
0
        public void SimpleHttpPutRequest()
        {
            if (Helper.IsNetworkAvailable())
            {
                var http = new DefaultRequester(new DefaultInfo());
                var request = new DefaultRequest();
                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\""));
            }
        }