Ejemplo n.º 1
0
        public void MapPathTest()
        {
            RouteGraph routeGraph = new RouteGraph(midProcessGraph, midProcessIdentifiers);
            RouteGraph testGraph  = new RouteGraph(finishedMidProcessGraph, null);

            routeGraph.MapPath("/about-us.html -> /about");
            routeGraph.Equals(testGraph);
        }
Ejemplo n.º 2
0
 public void Apply(RouteGraph graph, GenerationRules rules)
 {
     // Put this middleware on any route that
     // has the HTTP method POST, PUT, or DELETE
     foreach (var chain in graph.Commands)
     {
         chain.Middleware.Add(new StopwatchFrame(chain));
     }
 }
Ejemplo n.º 3
0
        public UrlGraph(RouteGraph routes, HttpSettings settings)
        {
            settings.IsReady.GetAwaiter().GetResult();

            foreach (var chain in routes)
            {
                Register(chain.Route);
            }
        }
Ejemplo n.º 4
0
 public void Apply(RouteGraph graph, GenerationRules rules)
 {
     graph
     .Where(x => x.Action.HandlerType.CanBeCastTo <ControllerBase>())
     .Each(x =>
     {
         x.Middleware.Add(new BuildOutControllerContextFrame());
         x.Middleware.Add(new SetControllerContextFrame(x.Action.HandlerType));
     });
 }
Ejemplo n.º 5
0
        public void TraverseGraphTest()
        {
            RouteGraph    routeGraph      = new RouteGraph(finishedSampleInputGraph, finishedSampleInputIdentifiers);
            List <string> traversalResult = routeGraph.TraverseGraph();

            for (int i = 0; i < traversalResult.Count; i++)
            {
                Assert.IsTrue(traversalResult[i].Equals(sampleOutput[i]));
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Used for running tests when the process is supposed to throw and exception
        /// </summary>
        /// <param name="input">input to be processed</param>
        private void TestProcessThrowsExceptionWith(List <string> input)
        {
            RouteGraph routeGraph = new RouteGraph();

            try {
                routeGraph.Process(input);
            }
            catch (ArgumentException exc) {
                Assert.IsTrue(exc.GetType() == typeof(ArgumentException));
                return;
            }
            Assert.Fail("Test should have thrown an ArgumentException, it did not");
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Used for running tests on the process function
        /// </summary>
        /// <param name="input">input to be processed</param>
        /// <param name="output">graph to be validated</param>
        private void TestProcessWith(List <string> input, List <List <int> > output)
        {
            RouteGraph routeGraph = new RouteGraph();
            RouteGraph testGraph  = new RouteGraph(output, null);

            try {
                routeGraph.Process(input);
            }
            catch (Exception exc) {
                Assert.Fail(exc.Message);
            }
            Assert.IsTrue(routeGraph.Equals(testGraph));
        }
Ejemplo n.º 8
0
        public void CompareGraphs()
        {
            RouteGraph one   = new RouteGraph(finishedSampleInputGraph, null);
            RouteGraph two   = new RouteGraph(finishedLargerInputGraph, null);
            RouteGraph three = new RouteGraph(finishedShuffledGraph, null);

            Assert.IsTrue(one.Equals(one));
            Assert.IsTrue(two.Equals(two));
            Assert.IsTrue(three.Equals(three));
            Assert.IsFalse(one.Equals(two));
            Assert.IsFalse(one.Equals(three));
            Assert.IsFalse(two.Equals(three));
        }
Ejemplo n.º 9
0
        public FindRouteFrame(MethodRoutes routes, RouteGraph graph)
        {
            _routes = routes;


            graph
            .Where(x => x.RespondsToMethod(routes.HttpMethod))
            .Select(x => new Setter(typeof(RouteHandler), x.Route.VariableName)
            {
                InitialValue = x.Route.Handler
            })
            .Each(x => uses.Add(x));
        }
Ejemplo n.º 10
0
        public void AssemblySelector(GeneratedAssembly assembly, RouteGraph routes)
        {
            _generatedType = assembly.AddType(HttpMethod + "Router", typeof(RouteSelector));

            foreach (var route in routes.Where(x => x.RespondsToMethod(HttpMethod)))
            {
                route.WriteRouteMatchMethod(_generatedType);
            }

            var method = _generatedType.MethodFor(nameof(RouteSelector.Select));

            method.Frames.Add(new FindRouteFrame(this, routes));
        }
Ejemplo n.º 11
0
        public RouteSelector BuildSelector(IContainer container, RouteGraph routes)
        {
            var code = _generatedType.SourceCode;

            var selectorType = _generatedType.CompiledType;
            var selector     = (RouteSelector)Activator.CreateInstance(selectorType);

            foreach (var route in routes.Where(x => x.RespondsToMethod(HttpMethod)))
            {
                var handler = route.CreateHandler(container);
                var setter  = selectorType.GetProperty(route.Route.VariableName);
                setter?.SetValue(selector, handler);
            }

            return(selector);
        }
Ejemplo n.º 12
0
        public CompilationContext()
        {
            _container = new Lazy <IContainer>(() => new Container(services));


            _graph = new Lazy <RouteGraph>(() =>
            {
                config        = new GenerationConfig("Jasper.Testing.Codegen.Generated");
                var container = _container.Value;
                config.Sources.Add(new StructureMapServices(container));

                config.Assemblies.Add(typeof(IContainer).GetTypeInfo().Assembly);
                config.Assemblies.Add(GetType().GetTypeInfo().Assembly);


                var graph = new RouteGraph();

                var methods = typeof(T).GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static)
                              .Where(x => x.DeclaringType != typeof(object) && x != null && !x.IsSpecialName);

                foreach (var method in methods)
                {
                    graph.AddRoute(typeof(T), method);
                }

                return(graph);
            });



            _code = new Lazy <string>(() => Graph.GenerateCode(config));

            _routes = new Lazy <Dictionary <string, RouteHandler> >(() =>
            {
                var routers = Graph.CompileAndBuildAll(config, _container.Value);
                var dict    = new Dictionary <string, RouteHandler>();
                foreach (var router in routers)
                {
                    dict.Add(router.Chain.Action.Method.Name, router);
                }

                return(dict);
            });
        }
Ejemplo n.º 13
0
        static void Main(string[] args)
        {
            var routeGraph = RouteGraph.Parse("AB5, BC4, CD8, DC8, DE6, AD5, CE2, EB3, AE7");

            var answer1 = routeGraph.GetDistance('A', 'B', 'C');
            var answer2 = routeGraph.GetDistance('A', 'D');
            var answer3 = routeGraph.GetDistance('A', 'D', 'C');
            var answer4 = routeGraph.GetDistance('A', 'E', 'B', 'C', 'D');
            //var answer5 = routeGraph.GetDistance('A', 'E', 'D'); // Crashes (on purpose)

            var answer6 = routeGraph
                          .Walk('C', (route) => route.GetEdgeCount() <= 3)
                          .Where(route => route.End == 'C' && route.GetEdgeCount() > 1)
                          .Count();

            var answer7 = routeGraph
                          .Walk('A', (route) => route.GetEdgeCount() <= 4)
                          .Where(route => route.End == 'C' && route.GetEdgeCount() == 4)
                          .Count();

            var answer8 = routeGraph
                          .Walk('A', (route) => !route.GetIsCyclic())
                          .Where(route => route.End == 'C' && route.GetEdgeCount() > 1)
                          .OrderBy(route => route.Distance)
                          .First()
                          .Distance;

            var answer9 = routeGraph
                          .Walk('B', (route) => !route.GetIsCyclic() || route.End == 'B')
                          .Where(route => route.End == 'B' && route.GetEdgeCount() > 1)
                          .OrderBy(route => route.Distance)
                          .First()
                          .Distance;

            var answer10 = routeGraph
                           .Walk('C', (route) => route.Distance < 30)
                           .Where(route => route.End == 'C' && route.GetEdgeCount() > 1)
                           .Count();
        }
Ejemplo n.º 14
0
 public HttpServices(RouteGraph routes)
 {
     For <RouteGraph>().Use(routes);
     For <IUrlRegistry>().Use(routes.Router.Urls);
 }
Ejemplo n.º 15
0
 public RouteScopingPolicy(RouteGraph routes)
 {
     _routes = routes;
 }
Ejemplo n.º 16
0
 public HandlerAndRoutePolicy(RouteGraph routes, HandlerGraph handlers)
 {
     _routes   = routes;
     _handlers = handlers;
 }