Пример #1
0
        public void Given_a_request_and_no_socket_data_available_and_timeout_reached_When_requesting_Then_exception_thrown()
        {
            // setup
            var target = new HttpSocketBuilder()
                         .GivenNoSocketDataAvailable()
                         .GivenTimeoutReached()
                         .Build();

            TestDelegate method = () => target.Request(new HttpRequestBuilder()
                                                       .SetUrl("www.test.com")
                                                       .Build());

            // execution/assertion
            var exception = Assert.Throws(typeof(HttpTimeoutException), method);

            Assert.AreEqual("The host at www.test.com did not respond in a timely manner.",
                            exception.Message, "The exception's message was not correct");
        }
Пример #2
0
        public void Given_a_SocketException_is_thrown_When_requesting_Then_an_HttpSocketConnectionException_is_thrown()
        {
            // setup
            var target = new HttpSocketBuilder()
                .GivenAnHttpRequest()
                .GivenASocketExceptionIsThrown()
                .Build();

            var request = new HttpRequestBuilder()
                .SetUrl("")
                .Build();

            TestDelegate method = () => target.Request(request);

            // execution/assertion
            var exception = Assert.Throws(typeof(HttpSocketConnectionException), method);
            Assert.AreEqual("The socket threw a SocketException",
                exception.Message, "The exception message was not correct");
        }
Пример #3
0
        public void Given_a_SocketException_is_thrown_When_requesting_Then_an_HttpSocketConnectionException_is_thrown()
        {
            // setup
            var target = new HttpSocketBuilder()
                         .GivenAnHttpRequest()
                         .GivenASocketExceptionIsThrown()
                         .Build();

            var request = new HttpRequestBuilder()
                          .SetUrl("")
                          .Build();

            TestDelegate method = () => target.Request(request);

            // execution/assertion
            var exception = Assert.Throws(typeof(HttpSocketConnectionException), method);

            Assert.AreEqual("The socket threw a SocketException",
                            exception.Message, "The exception message was not correct");
        }
Пример #4
0
        public void Given_a_host_is_specified_And_the_host_cannot_be_found_When_requesting_Then_an_HttpUnknownHostException_is_thrown()
        {
            // setup
            var host = "mock host";
            var request = new HttpRequestBuilder()
                .SetUrl(host)
                .Build();

            var target = new HttpSocketBuilder()
                .GivenAnHttpRequest()
                .GivenAHostIsSpecified(host)
                .GivenTheHostCannotBeFound()
                .Build();

            TestDelegate method = () => target.Request(request);

            // execution/assertion
            var exception = Assert.Throws(typeof(HttpUnknownHostException), method);
            Assert.AreEqual("The host mock host could not be found.", exception.Message,
                "The exception message was not correct");
        }
Пример #5
0
        public void Given_a_host_is_specified_And_the_host_cannot_be_found_When_requesting_Then_an_HttpUnknownHostException_is_thrown()
        {
            // setup
            var host    = "mock host";
            var request = new HttpRequestBuilder()
                          .SetUrl(host)
                          .Build();

            var target = new HttpSocketBuilder()
                         .GivenAnHttpRequest()
                         .GivenAHostIsSpecified(host)
                         .GivenTheHostCannotBeFound()
                         .Build();

            TestDelegate method = () => target.Request(request);

            // execution/assertion
            var exception = Assert.Throws(typeof(HttpUnknownHostException), method);

            Assert.AreEqual("The host mock host could not be found.", exception.Message,
                            "The exception message was not correct");
        }
Пример #6
0
        public void Given_a_request_and_no_socket_data_available_and_timeout_reached_When_requesting_Then_exception_thrown()
        {
            // setup
            var target = new HttpSocketBuilder()
                .GivenNoSocketDataAvailable()
                .GivenTimeoutReached()
                .Build();

            TestDelegate method = () => target.Request(new HttpRequestBuilder()
                .SetUrl("www.test.com")
                .Build());

            // execution/assertion
            var exception = Assert.Throws(typeof(HttpTimeoutException), method);
            Assert.AreEqual("The host at www.test.com did not respond in a timely manner.",
                exception.Message, "The exception's message was not correct");
        }