Beispiel #1
0
        public void TestSuccessWhenQueryDefined()
        {
            var query = new NameValueCollection {
                { "qp", "qv" }
            };

            using (var httpMock = HttpMocks.New(DefaultMockUrl))
            {
                httpMock
                .WhenRequestGet("/")
                .Query(query)
                .ThenResponse(200);
            }

            var responseA = Send(BuildUrl(DefaultMockUrl, "/"), "GET");

            responseA.StatusCode.ShouldBeEquivalentTo(500);

            var responseB = Send(BuildUrl(DefaultMockUrl, "/", query), "GET");

            responseB.StatusCode.ShouldBeEquivalentTo(200);

            HttpMocks.Invoking(m => m.VerifyAll())
            .ShouldThrowExactly <AssertHttpMockException>()
            .WithMessage("Actual request GET /, but not expected.");
        }
Beispiel #2
0
        public void TestSuccessWhenHeadersDefined()
        {
            var headers = new NameValueCollection {
                { "X-Header-Name", "Header_Value" }
            };

            using (var httpMock = HttpMocks.New(DefaultMockUrl))
            {
                httpMock
                .WhenRequestGet("/")
                .Headers(headers)
                .ThenResponse(200);
            }

            var url       = BuildUrl(DefaultMockUrl, "/");
            var responseA = Send(url, "GET");

            responseA.StatusCode.ShouldBeEquivalentTo(500);

            var responseB = Send(url, "GET", headers: headers);

            responseB.StatusCode.ShouldBeEquivalentTo(200);

            HttpMocks.Invoking(m => m.VerifyAll())
            .ShouldThrowExactly <AssertHttpMockException>()
            .WithMessage("Actual request GET /, but not expected.");
        }
        public void TestNotActualWhenRepeatCountMoreActualCount()
        {
            IHttpMock httpMock1;

            using (httpMock1 = HttpMocks.New("localhost", 3465))
            {
                httpMock1
                .WhenRequestGet("/bills/1")
                .ThenResponse(200)
                .Repeat(2);
            }

            Send(BuildUrl(httpMock1.MockUri, "/bills/1"), "GET").StatusCode.ShouldBeEquivalentTo(200);

            HttpMocks.Invoking(x => x.VerifyAll()).ShouldThrow <AssertHttpMockException>();
        }
Beispiel #4
0
        public void TestFailWhenActualIsNotExpectedRequest()
        {
            using (var httpMock = HttpMocks.New(DefaultMockUrl))
            {
                httpMock
                .WhenRequestGet("/bills/@guid")
                .ThenResponse(302);
            }

            var url      = BuildUrl(DefaultMockUrl, "/bills");
            var response = Send(url, "GET");

            response.StatusCode.ShouldBeEquivalentTo(500);
            response.ContentBytes.Length.ShouldBeEquivalentTo(0);

            HttpMocks
            .Invoking(m => m.VerifyAll())
            .ShouldThrowExactly <AssertHttpMockException>();
        }
Beispiel #5
0
        public void TestFailWhenDefaultActualRepeatMoreThatExpected()
        {
            using (var httpMock = HttpMocks.New(DefaultMockUrl))
            {
                httpMock
                .WhenRequestGet("/bills")
                .ThenResponse(200);
            }

            var url = BuildUrl(DefaultMockUrl, "/bills");

            Send(url, "GET").StatusCode.ShouldBeEquivalentTo(200);

            Send(url, "GET").StatusCode.ShouldBeEquivalentTo(500);

            HttpMocks.Invoking(m => m.VerifyAll())
            .ShouldThrowExactly <AssertHttpMockException>()
            .WithMessage("Actual request GET /bills repeat count 2, but max expected repeat count 1.");
        }