示例#1
0
        public void When_Http_Request_Times_Out_Then_Populate_Exception_Properties()
        {
            var message = "The operation has timed out";

            var webexception = new WebException(message, null, WebExceptionStatus.Timeout, null);

            var wrapper      = new HttpWebRequestWrapper();
            var restresponse = wrapper.ParseWebException(webexception);

            Assert.IsNotNull(restresponse.ErrorException);
            Assert.AreEqual(message, restresponse.ErrorMessage);
            Assert.AreEqual(ResponseStatus.Error, restresponse.ResponseStatus);
        }
示例#2
0
        public void When_Async_Http_Request_Is_Aborted_Then_Populate_Exception_Properties()
        {
            var message = "The request was aborted: The request was canceled.";

            var webexception = new WebException(message, null, WebExceptionStatus.RequestCanceled, null);

            var wrapper      = new HttpWebRequestWrapper();
            var restresponse = wrapper.ParseWebException(webexception, new TimeOutState()
            {
                TimedOut = false
            });

            Assert.IsNotNull(restresponse.ErrorException);
            Assert.AreEqual(message, restresponse.ErrorMessage);
            Assert.AreEqual(ResponseStatus.Aborted, restresponse.ResponseStatus);
        }
示例#3
0
        public void When_Http_Protocol_Error_Then_Response_Contains_Status_Code_And_Description()
        {
            FakeHttpWebResponse.InitializeHttpWebResponse(HttpStatusCode.BadRequest, "BAD REQUEST");
            var webexception = new WebException(
                "The remote server returned an error: (400) Bad Request.",
                null,
                WebExceptionStatus.ProtocolError,
                new FakeHttpWebResponse(new MemoryStream())
                );

            var wrapper      = new HttpWebRequestWrapper();
            var restresponse = wrapper.ParseWebException(webexception);

            Assert.AreEqual(HttpStatusCode.BadRequest, restresponse.StatusCode);
            Assert.AreEqual("BAD REQUEST", restresponse.StatusDescription);
            Assert.AreEqual(ResponseStatus.Completed, restresponse.ResponseStatus);
        }
示例#4
0
        public void When_Http_Protocol_Error_Then_Response_Contains_Content()
        {
            var sourcecontent = Encoding.ASCII.GetBytes("{\"code\": 90011, \"message\": \"Param From must be specified.\", \"more_info\": \"https://www.twilio.com/docs/errors/90011\", \"status\": 400}");
            var stream        = new MemoryStream(sourcecontent);

            FakeHttpWebResponse.InitializeHttpWebResponse(HttpStatusCode.BadRequest, "BAD REQUEST", (int)sourcecontent.Length);
            var webexception = new WebException(
                "The remote server returned an error: (400) Bad Request.",
                null,
                WebExceptionStatus.ProtocolError,
                new FakeHttpWebResponse(stream)
                );

            var wrapper      = new HttpWebRequestWrapper();
            var restresponse = wrapper.ParseWebException(webexception);

            Assert.AreEqual(HttpStatusCode.BadRequest, restresponse.StatusCode);
            Assert.AreEqual((int)sourcecontent.Length, restresponse.RawBytes.Length);
            CollectionAssert.AreEquivalent(sourcecontent, restresponse.RawBytes);
            Assert.AreEqual(ResponseStatus.Completed, restresponse.ResponseStatus);
        }