/// <inheritdoc /> public Task SetParametersAsync(ParameterCollection parameters) { parameters.SetParameterProperties(this); Routes = RouteTableFactory.Create(AppAssembly); Refresh(isNavigationIntercepted: false); return(Task.CompletedTask); }
/// <inheritdoc /> public Task SetParametersAsync(ParameterView parameters) { parameters.SetParameterProperties(this); if (AppAssembly == null) { throw new InvalidOperationException($"The {nameof(Router)} component requires a value for the parameter {nameof(AppAssembly)}."); } // Found content is mandatory, because even though we could use something like <RouteView ...> as a // reasonable default, if it's not declared explicitly in the template then people will have no way // to discover how to customize this (e.g., to add authorization). if (Found == null) { throw new InvalidOperationException($"The {nameof(Router)} component requires a value for the parameter {nameof(Found)}."); } // NotFound content is mandatory, because even though we could display a default message like "Not found", // it has to be specified explicitly so that it can also be wrapped in a specific layout if (NotFound == null) { throw new InvalidOperationException($"The {nameof(Router)} component requires a value for the parameter {nameof(NotFound)}."); } var assemblies = AdditionalAssemblies == null ? new[] { AppAssembly } : new[] { AppAssembly }.Concat(AdditionalAssemblies); Routes = RouteTableFactory.Create(assemblies); Refresh(isNavigationIntercepted: false); return(Task.CompletedTask); }
public void CanDiscoverRoute() { // Arrange & Act var routes = RouteTableFactory.Create(new[] { typeof(MyComponent), }); // Assert Assert.Equal("Test1", Assert.Single(routes.Routes).Template.TemplateText); }
public void IgnoresIdenticalTypes() { // Arrange & Act var routes = RouteTableFactory.Create(new RouteKey(GetType().Assembly, new[] { GetType().Assembly })); // Assert Assert.Equal(routes.Routes.GroupBy(x => x.Handler).Count(), routes.Routes.Length); }
private void RefreshRouteTable() { var routeKey = new RouteKey(AppAssembly, AdditionalAssemblies); if (!routeKey.Equals(_routeTableLastBuiltForRouteKey)) { _routeTableLastBuiltForRouteKey = routeKey; Routes = RouteTableFactory.Create(routeKey); } }
public void DoesNotCacheRouteTableForDifferentAssemblies() { // Arrange var routes1 = RouteTableFactory.Create(new RouteKey(GetType().Assembly, null)); // Act var routes2 = RouteTableFactory.Create(new RouteKey(GetType().Assembly, new[] { typeof(object).Assembly })); // Assert Assert.NotSame(routes1, routes2); }
public void CanCacheRouteTableWithDifferentAssembliesAndOrder() { // Arrange var routes1 = RouteTableFactory.Create(new RouteKey(typeof(object).Assembly, new[] { typeof(ComponentBase).Assembly, GetType().Assembly, })); // Act var routes2 = RouteTableFactory.Create(new RouteKey(typeof(object).Assembly, new[] { GetType().Assembly, typeof(ComponentBase).Assembly, })); // Assert Assert.Same(routes1, routes2); }
public void CanCacheRouteTable() { // Arrange var routes1 = RouteTableFactory.Create(new RouteKey(GetType().Assembly, null)); // Act var routes2 = RouteTableFactory.Create(new RouteKey(GetType().Assembly, null)); // Assert Assert.Same(routes1, routes2); }
public void CanDiscoverRoutes_WithInheritance() { // Arrange & Act var routes = RouteTableFactory.Create(new[] { typeof(MyComponent), typeof(MyInheritedComponent), }); // Assert Assert.Collection( routes.Routes.OrderBy(r => r.Template.TemplateText), r => Assert.Equal("Test1", r.Template.TemplateText), r => Assert.Equal("Test2", r.Template.TemplateText)); }
private void RefreshRouteTable() { var assemblies = AdditionalAssemblies == null ? new[] { AppAssembly } : new[] { AppAssembly }.Concat(AdditionalAssemblies); var assembliesSet = new HashSet <Assembly>(assemblies); if (!_assemblies.SetEquals(assembliesSet)) { Routes = RouteTableFactory.Create(assemblies); _assemblies.Clear(); _assemblies.UnionWith(assembliesSet); } }
public RouteTable Build() { try { var templatesByHandler = _routeTemplates .GroupBy(rt => rt.Handler) .ToDictionary(group => group.Key, group => group.Select(g => g.Template).ToArray()); return(RouteTableFactory.Create(templatesByHandler)); } catch (InvalidOperationException ex) when(ex.InnerException is InvalidOperationException) { // ToArray() will wrap our exception in its own. throw ex.InnerException; } }
/// <summary> /// /// </summary> /// <returns></returns> protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); // 需要认证并且未认证 if (AuthenticationStateTask != null) { var url = Navigation.ToBaseRelativePath(Navigation.Uri); var context = RouteTableFactory.Create(AdditionalAssemblies, url); if (context.Handler != null) { IsAuthenticated = await context.Handler.IsAuthorizedAsync(AuthenticationStateTask, AuthorizationPolicyProvider, AuthorizationService); } } else { IsAuthenticated = true; } IsInit = true; }
private void ClearRouteCaches() { RouteTableFactory.ClearCaches(); _routeTableLastBuiltForRouteKey = default; }