internal async Task <RouteTree> BuildRouting(IContainer container, JasperGenerationRules generation) { if (!Enabled) { return(null); } var actions = await FindActions(ApplicationAssembly); foreach (var methodCall in actions) { var chain = Routes.AddRoute(methodCall); Urls.Register(chain.Route); } foreach (var policy in _policies) { policy.Apply(Routes, generation); } Routes.AssertNoDuplicateRoutes(); Routes.Seal(); var tree = new RouteTree(this, generation); tree.CompileAll(container); return(tree); }
public void Two_routes_without_an_id_can_be_defined() { var table = new RouteTree(); table.Add(new Route("GET", "/foo")); var secondRouteWithoutId = new Route("GET", "/bar"); Assert.DoesNotThrow(() => table.Add(secondRouteWithoutId)); }
public void If_a_route_is_added_with_an_id_that_already_exists_the_router_throws_an_exception() { var table = new RouteTree(); table.Add(new Route("my-id", "GET", "/foo", App)); var otherRouteWithSameId = new Route("my-id", "GET", "/bar", App); Assert.Throws <RouteAlreadyExistsException>(() => table.Add(otherRouteWithSameId)); }
public void Route_can_be_removed_by_id() { var table = new RouteTree(); table.Add(new Route("my-id", "GET", "/foo", App)); table.RemoveRoute("my-id"); var candiates = table.GetCandidates("/foo", "GET"); Assert.Equal(0, candiates.Count); }
public void TheSelectionShouldBe(string Url, out string Selected, [Default("NONE")] out ArgumentExpectation Arguments) { var env = StubHttpContext.Empty(); var leaf = _tree.Select(Url); Selected = leaf.Pattern; leaf.SetValues(env, RouteTree.ToSegments(Url)); Arguments = new ArgumentExpectation(env); }
public void Route_with_two_static_segments_can_be_removed() { var table = new RouteTree(); var route = new Route("GET", "/foo/bar", App); table.Add(route); table.RemoveRoute(route); var candidates = table.GetCandidates("/foo/bar", "GET"); Assert.Equal(0, candidates.Count); }
public void Route_dynamic_segment_can_be_removed() { var table = new RouteTree(); var route = new Route("GET", "/{id}", App); table.Add(route); Assert.Equal(new[] { route }, table.GetCandidates("/12", "GET")); table.RemoveRoute(route); var candidates = table.GetCandidates("/13", "GET"); Assert.Equal(0, candidates.Count); }
public async void Start(Assembly assembly) { Host = Browser.Window.Location.Host; Port = Browser.Window.Location.Port; Scheme = Browser.Window.Location.Protocol; Browser.Window.AddEventListener("popstate", evt => OnPopState(evt.As <PopStateEvent>())); var path = Browser.Window.Location.PathName; Console.WriteLine(path); ControllerFactory = new DefaultControllerFactory(DependencyResolver); var routeGenerator = new RouteGenerator(); routeTree = routeGenerator.GenerateRoutes(assembly); await OnStarting(); await OnStarted(); }
// Call this from the activator internal Task <RouteTree> BuildRouting(IContainer container, JasperGenerationRules generation) { if (!Enabled) { return(null); } return(_findActions.ContinueWith(t => { if (t.IsFaulted) { container.GetInstance <IEnvironmentRecorder>().Failure("Failure while trying to discover HTTP route handlers", t.Exception); throw t.Exception; } try { foreach (var policy in _policies) { policy.Apply(Routes, generation); } Routes.AssertNoDuplicateRoutes(); var tree = new RouteTree(this, generation); tree.CompileAll(container); return tree; } catch (Exception e) { container.GetInstance <IEnvironmentRecorder>().Failure("Failure while trying to compile the routing tree", e); throw; } })); }
public void Start(Assembly assembly) { Host = Browser.Window.Location.Host; Port = Browser.Window.Location.Port; Scheme = Browser.Window.Location.Protocol; Browser.Window.AddEventListener("popstate", evt => OnPopState(evt.As <PopStateEvent>())); var path = Browser.Window.Location.PathName; Console.WriteLine(path); ControllerFactory = new DefaultControllerFactory(DependencyResolver); var routeGenerator = new RouteGenerator(); routeTree = routeGenerator.GenerateRoutes(assembly); OnStarting(() => { Open(path + (!string.IsNullOrEmpty(Browser.Window.Location.Search) ? "?" + Browser.Window.Location.Search : ""), false, OnStarted); }); }
public void Returns_all_routes() { var routeTree = new RouteTree(); var route1 = new Route("GET", "/test"); routeTree.Add(route1); var route2 = new Route("GET", "/products/{id}"); routeTree.Add(route2); var route3 = new Route("GET", "/products/new/{id}"); routeTree.Add(route3); var route4 = new Route("GET", "/{id}"); routeTree.Add(route4); var allRoutes = new[] { route1, route2, route3, route4 }.OrderBy(x => x.Path); var resolvedRoutes = routeTree.GetAllRoutes().OrderBy(x => x.Path); Assert.Equal(allRoutes, resolvedRoutes); }
public void Throws_argument_exception_if_RemoveRoute_is_called_with_empty_string() { var table = new RouteTree(); Assert.Throws <ArgumentException>(() => table.RemoveRoute(string.Empty)); }
public void Throws_argument_exception_if_RemoveRoute_is_call_with_null_parameter() { var table = new RouteTree(); Assert.Throws <ArgumentNullException>(() => table.RemoveRoute((string)null)); }
public override void SetUp() { _tree = new RouteTree("GET"); }
public void RemoveById_throws_ArgumentException_if_id_is_not_available() { var table = new RouteTree(); Assert.Throws <ArgumentException>(() => table.RemoveRoute("route-id")); }