示例#1
0
    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 DoesNotCacheRouteTableForDifferentAssemblies()
        {
            // Arrange
            var routes1 = RouteTableFactory.Create(new[] { GetType().Assembly, });

            // Act
            var routes2 = RouteTableFactory.Create(new[] { GetType().Assembly, typeof(object).Assembly, });

            // Assert
            Assert.NotSame(routes1, routes2);
        }
        public void CanCacheRouteTableWithDifferentAssembliesAndOrder()
        {
            // Arrange
            var routes1 = RouteTableFactory.Create(new[] { typeof(object).Assembly, GetType().Assembly, });

            // Act
            var routes2 = RouteTableFactory.Create(new[] { GetType().Assembly, typeof(object).Assembly, });

            // Assert
            Assert.Same(routes1, routes2);
        }
示例#4
0
        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));
        }
示例#5
0
        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);
            }
        }
示例#6
0
 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;
    }
示例#8
0
        /// <inheritdoc />
        public Task SetParametersAsync(ParameterView parameters)
        {
            parameters.SetParameterProperties(this);

            // 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)}.");
            }

            Routes = RouteTableFactory.Create(AppAssembly);
            Refresh(isNavigationIntercepted: false);
            return(Task.CompletedTask);
        }