Beispiel #1
0
        public void NoTenant(bool preferExactMatches)
        {
            using var ctx = new TestContext();

            SetupContext(ctx);

            _navigationManager.NotifyLocationChanged("https://www.example.com/nocompany", false);

            RenderFragment <RouteData> found = __builder =>
            {
                RenderFragment foundContentrf = __builder =>
                {
                    __builder.AddContent(0, "Found");
                };
                return(foundContentrf);
            };

            RenderFragment notFound = __builder =>
            {
                __builder.AddContent(0, "Not Found");
            };

            RenderFragment <string> noTenant = __builder =>
            {
                RenderFragment noTenantrf = __builder =>
                {
                    __builder.AddContent(0, "No Tenant");
                };
                return(noTenantrf);
            };

            var cut = ctx.RenderComponent <MultiTenantRouter>(
                ("AppAssembly", Assembly.GetExecutingAssembly()),
                ("PreferExactMatches", preferExactMatches),
                ("Found", found),
                ("NotFound", notFound),
                ("NoTenant", noTenant)
                );

            cut.MarkupMatches("No Tenant");
        }
Beispiel #2
0
        public async Task UsesLegacyRouteMatchingByDefault()
        {
            // Arrange
            // Legacy routing prefers {*someWildcard} over any other pattern than has more segments,
            // even if the other pattern is an exact match
            _navigationManager.NotifyLocationChanged("https://www.example.com/subdir/a/b", false);
            var parameters = new Dictionary <string, object>
            {
                { nameof(Router.AppAssembly), typeof(RouterTest).Assembly },
                { nameof(Router.NotFound), (RenderFragment)(builder => { }) },
            };

            // Act
            await _renderer.Dispatcher.InvokeAsync(() =>
                                                   _router.SetParametersAsync(ParameterView.FromDictionary(parameters)));

            // Assert
            var renderedFrame = _renderer.Batches.First().ReferenceFrames.First();

            Assert.Equal(RenderTreeFrameType.Text, renderedFrame.FrameType);
            Assert.Equal($"Rendering route matching {typeof(MatchAnythingComponent)}", renderedFrame.TextContent);
        }
Beispiel #3
0
        public async Task UsesCurrentRouteMatchingIfSpecified()
        {
            // Arrange
            // Current routing prefers exactly-matched patterns over {*someWildcard}, no matter
            // how many segments are in the exact match
            _navigationManager.NotifyLocationChanged("https://www.example.com/subdir/a/b", false);
            var parameters = new Dictionary <string, object>
            {
                { nameof(Router.AppAssembly), typeof(RouterTest).Assembly },
                { nameof(Router.NotFound), (RenderFragment)(builder => { }) },
            };

            // Act
            await _renderer.Dispatcher.InvokeAsync(() =>
                                                   _router.SetParametersAsync(ParameterView.FromDictionary(parameters)));

            // Assert
            var renderedFrame = _renderer.Batches.First().ReferenceFrames.First();

            Assert.Equal(RenderTreeFrameType.Text, renderedFrame.FrameType);
            Assert.Equal($"Rendering route matching {typeof(MultiSegmentRouteComponent)}", renderedFrame.TextContent);
        }