示例#1
0
        public RouteContext GetContext(RouteId id, HttpContext ctx)
        {
            var spec    = Specs[id];
            var options = RouteOptionsBuilder.Build(id, Config);
            var callCtx = RequestContextBuilder.Build(ctx);
            var handler = HandlerProvider.GetHandler(options.Handler, options.Config, responseContext: null);

            return(new RouteContext(options, spec, callCtx, handler, Logger));
        }
示例#2
0
        public void ReturnDefaultsIfNoRoutesConfigured()
        {
            var config = GetConfig(new Dictionary <string, string>());
            var route  = new RouteId("/", HttpMethod.Get);

            var expected = new MockServerRouteOptions
            {
                Path    = "/",
                Method  = MockServerOptionsHttpMethod.Get,
                Handler = "default"
            };

            var actual = RouteOptionsBuilder.Build(route, config);

            AssertEqual(expected, actual);
        }
示例#3
0
        public void ReturnDefaultOptionsIfRouteIsNotConfigured()
        {
            var config = GetConfig("/", "get", "test");
            var route  = new RouteId("/test", HttpMethod.Get);

            var expected = new MockServerRouteOptions
            {
                Path    = "/test",
                Method  = MockServerOptionsHttpMethod.Get,
                Handler = "default"
            };

            var actual = RouteOptionsBuilder.Build(route, config);

            AssertEqual(expected, actual);
        }
示例#4
0
        public void CanBuildRouteOptions(string glob, string configMethod)
        {
            var config = GetConfig(glob, configMethod, "test");
            var route  = new RouteId("/foo/bar", HttpMethod.Get);

            var expected = new MockServerRouteOptions
            {
                Path    = "/foo/bar",
                Method  = MockServerOptionsHttpMethod.Get,
                Handler = "test"
            };

            var actual = RouteOptionsBuilder.Build(route, config);

            AssertEqual(expected, actual);
        }