Exemplo n.º 1
0
        apply_pipeline_for_a_matched_route()
        {
            WebActionFeature <string> addContent = (some) =>
                                                   (ctx) => ctx.With(content: some);

            WebAction ok = (ctx) => Context(
                request: ctx.Request,
                response: Response(ctx.Response.Content, 200)
                );

            var requestPipeline = Pipeline(
                (context) =>
                context
                | addContent("hello")
                | ok
                );

            Route route = new Route(
                template: "/hello",
                pipeline: requestPipeline
                );

            string content       = string.Empty;
            int    status        = 0;
            var    beforeContext = Defaults.Context.With(path: "/hello");

            if (route.Matches(path: "/hello"))
            {
                (content, status) = route.ApplyPipeline(beforeContext);
            }


            Assert.Equal("hello", content);
            Assert.Equal(200, status);
        }
Exemplo n.º 2
0
        multiple_webactions_define_the_request_pipeline()
        {
            var newRequestWithContext = Defaults.Context.With(path: "/hello");

            WebActionFeature <string> addContent = (content) =>
                                                   (ctx) => ctx.With(content: content);

            WebAction ok = (ctx) => Context(
                request: ctx.Request,
                response: Response(ctx.Response.Content, 200)
                );

            var requestPipeline = Pipeline(
                (context) =>
                context
                | addContent("hello")
                | ok
                );

            var afterContext = requestPipeline(newRequestWithContext);


            Assert.Equal("hello", afterContext.Response.Content);
            Assert.Equal(200, afterContext.Response.StatusCode);
        }
Exemplo n.º 3
0
        featured_webaction_is_a_composition_returning_webaction()
        {
            var req           = Request(RequestType.UNKNOWN, "/hello");
            var response      = Response("xxx", 0);
            var beforeContext = Context(req, response);

            WebActionFeature <string> addContent = (content) =>
                                                   (ctx) => ctx.With(content: content);

            WebAction ok = (ctx) => Context(
                request: ctx.Request,
                response: Response(ctx.Response.Content, 200)
                );

            var afterContext1 = addContent("oh oh oh")(beforeContext);
            var afterContext  = ok(afterContext1);

            Assert.Equal(200, afterContext.Response.StatusCode);
            Assert.Equal("oh oh oh", afterContext.Response.Content);
        }
Exemplo n.º 4
0
        define_route_with_template_and_pipeline()
        {
            WebActionFeature <string> addContent = (content) =>
                                                   (ctx) => ctx.With(content: content);

            WebAction ok = (ctx) => Context(
                request: ctx.Request,
                response: Response(ctx.Response.Content, 200)
                );

            var requestPipeline = Pipeline(
                (context) =>
                context
                | addContent("hello")
                | ok
                );

            Route route = new Route(
                template: "/hello",
                pipeline: requestPipeline
                );
        }