Example #1
0
        public void CanRouteToARoute()
        {
            ITestWebApplication webApplication = Server
                                                 .Configure()
                                                 .OnRequest(
                c =>
            {
                c.Get("/").To(request => Ok().WithJsonBody(new { a = 123 }));
                c.Post("/post").To(request => Ok().WithJsonBody(request));
            }).StartTesting();

            {
                var response = webApplication.Execute(Get());
                response.AssertIsOk();
                response.AssertJsonBodyMatches(new { a = 123 });
            }

            {
                var response = webApplication.Execute(Post().WithPath("/post"));
                response.AssertIsOk();
                response.AssertJsonBodyMatches(new
                {
                    Path            = "/post",
                    Body            = "",
                    QueryParameters = new {},
                    Headers         = new {},
                    Method          = "POST"
                });
            }

            webApplication.Stop();
        }
Example #2
0
        public void CanMakeTestRequestAndRespondWith404()
        {
            ITestWebApplication webApplication = Server.Configure().StartTesting();

            var response = webApplication.Execute(Get());

            response.AssertIsNotFound();
        }
Example #3
0
        public void ItCallsOnRequestOncePerRequest()
        {
            var numberOfTimesOnRequestCalled   = 0;
            ITestWebApplication webApplication = Server
                                                 .Configure()
                                                 .OnRequest(
                _ => numberOfTimesOnRequestCalled++
                ).StartTesting();

            webApplication.Execute(Get());
            webApplication.Execute(Get());

            webApplication.Stop();
            numberOfTimesOnRequestCalled.Should().Be(2);
        }