Exemplo n.º 1
0
        public void TestSuccessWhenResponseFromAsyncDelegate()
        {
            var paths = new List <string>();

            Func <HttpRequest, Task <HttpResponse> > processRequestInfoAsync = request =>
            {
                paths.Add(request.Path);
                return(Task.FromResult(HttpResponse.Create(200)));
            };

            using (var httpMock = HttpMocks.New(DefaultMockUrl))
            {
                httpMock
                .WhenRequestGet("/bills/@guid")
                .ThenResponse(i => processRequestInfoAsync(i));
            }

            var guid     = Guid.NewGuid();
            var url      = BuildUrl(DefaultMockUrl, $"/bills/{guid}");
            var response = Send(url, "GET");

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

            paths.Count.ShouldBeEquivalentTo(1);
            paths[0].ShouldBeEquivalentTo($"/bills/{guid}");

            HttpMocks.VerifyAll();
        }
Exemplo n.º 2
0
        public void TestSuccess()
        {
            IHttpMock httpMock1;

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

            IHttpMock httpMock2;

            using (httpMock2 = HttpMocks.New("localhost", 3466))
            {
                httpMock2
                .WhenRequestGet("/bills/2")
                .ThenResponse(200);
            }

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

            HttpMocks.VerifyAll();
        }
Exemplo n.º 3
0
        public void TestSuccessWhenGetReturn302()
        {
            using (var httpMock = HttpMocks.New(DefaultMockUrl))
            {
                httpMock
                .WhenRequestGet("/bills")
                .ThenResponse(302);
            }

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

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

            HttpMocks.VerifyAll();
        }
Exemplo n.º 4
0
        public void TestFailWhenAnyActualRepeatMoreThatExpected()
        {
            using (var httpMock = HttpMocks.New(DefaultMockUrl))
            {
                httpMock
                .WhenRequestGet("/bills")
                .ThenResponse(200)
                .RepeatAny();
            }

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

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

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

            HttpMocks.VerifyAll();
        }
Exemplo n.º 5
0
        public void TestSuccessWhenGetReturn200AndResult()
        {
            const string testDataString = "Test data";
            var          content        = Encoding.UTF8.GetBytes(testDataString);

            using (var httpMock = HttpMocks.New(DefaultMockUrl))
            {
                httpMock
                .WhenRequestGet("/bills")
                .ThenResponse(200)
                .Content(content, "text/plain");
            }

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

            response.StatusCode.ShouldBeEquivalentTo(200);
            response.ContentBytes.Length.ShouldBeEquivalentTo(content.Length);
            Encoding.UTF8.GetString(response.ContentBytes).ShouldBeEquivalentTo(testDataString);

            HttpMocks.VerifyAll();
        }