Пример #1
0
        public async Task ExtractsUriFromHttpContext_NonemptyPathBase()
        {
            // Arrange
            var circuitFactory     = new TestCircuitFactory();
            var circuitRegistry    = new CircuitRegistry(Options.Create(new CircuitOptions()), Mock.Of <ILogger <CircuitRegistry> >());
            var circuitPrerenderer = new CircuitPrerenderer(circuitFactory, circuitRegistry);
            var httpContext        = new DefaultHttpContext();
            var httpRequest        = httpContext.Request;

            httpRequest.Scheme   = "https";
            httpRequest.Host     = new HostString("example.com", 1234);
            httpRequest.PathBase = "/my/dir";
            httpRequest.Path     = "/some/path";

            var prerenderingContext = new ComponentPrerenderingContext
            {
                ComponentType = typeof(UriDisplayComponent),
                Parameters    = ParameterCollection.Empty,
                Context       = httpContext
            };

            // Act
            var result = await circuitPrerenderer.PrerenderComponentAsync(prerenderingContext);

            // Assert
            Assert.Equal(string.Join("", new[]
            {
                "The current URI is ",
                "https://example.com:1234/my/dir/some/path",
                " within base URI ",
                "https://example.com:1234/my/dir/"
            }), GetUnwrappedContent(result));
        }
        public async Task ReplacesDashesWithDots_WhenTheyAppearInPairs()
        {
            // Arrange
            var circuitFactory  = new TestCircuitFactory(() => "--1234--");
            var circuitRegistry = new CircuitRegistry(
                Options.Create(new CircuitOptions()),
                Mock.Of <ILogger <CircuitRegistry> >(),
                TestCircuitIdFactory.CreateTestFactory());
            var circuitPrerenderer = new CircuitPrerenderer(circuitFactory, circuitRegistry);
            var httpContext        = new DefaultHttpContext();
            var httpRequest        = httpContext.Request;

            httpRequest.Scheme = "https";
            httpRequest.Host   = new HostString("example.com", 1234);
            httpRequest.Path   = "/some/path";

            var prerenderingContext = new ComponentPrerenderingContext
            {
                ComponentType = typeof(UriDisplayComponent),
                Parameters    = ParameterView.Empty,
                Context       = httpContext
            };

            // Act
            var result = await circuitPrerenderer.PrerenderComponentAsync(prerenderingContext);

            // Assert
            Assert.Equal("..1234..", GetUnwrappedCircuitInfo(result).RootElement.GetProperty("circuitId").GetString());
        }
Пример #3
0
        public async Task ExtractsUriFromHttpContext_NonemptyPathBase()
        {
            // Arrange
            var circuitFactory     = new TestCircuitFactory();
            var circuitPrerenderer = new CircuitPrerenderer(circuitFactory);
            var httpContext        = new Mock <HttpContext>();
            var httpRequest        = new Mock <HttpRequest>().SetupAllProperties();

            httpContext.Setup(h => h.Request).Returns(httpRequest.Object);
            httpRequest.Object.Scheme   = "https";
            httpRequest.Object.Host     = new HostString("example.com", 1234);
            httpRequest.Object.PathBase = "/my/dir";
            httpRequest.Object.Path     = "/some/path";

            var prerenderingContext = new ComponentPrerenderingContext
            {
                ComponentType = typeof(UriDisplayComponent),
                Parameters    = ParameterCollection.Empty,
                Context       = httpContext.Object
            };

            // Act
            var result = await circuitPrerenderer.PrerenderComponentAsync(prerenderingContext);

            // Assert
            Assert.Equal(new[]
            {
                "The current URI is ",
                "https://example.com:1234/my/dir/some/path",
                " within base URI ",
                "https://example.com:1234/my/dir/"
            }, result);
        }
        public async Task DisposesCircuitScopeEvenIfPrerenderingThrows()
        {
            // Arrange
            var circuitFactory  = new MockServiceScopeCircuitFactory();
            var circuitRegistry = new CircuitRegistry(
                Options.Create(new CircuitOptions()),
                Mock.Of <ILogger <CircuitRegistry> >(),
                TestCircuitIdFactory.CreateTestFactory());
            var httpContext         = new DefaultHttpContext();
            var prerenderer         = new CircuitPrerenderer(circuitFactory, circuitRegistry);
            var prerenderingContext = new ComponentPrerenderingContext
            {
                ComponentType = typeof(ThrowExceptionComponent),
                Parameters    = ParameterCollection.Empty,
                Context       = httpContext
            };

            // Act
            await Assert.ThrowsAsync <InvalidTimeZoneException>(async() =>
                                                                await prerenderer.PrerenderComponentAsync(prerenderingContext));

            // Assert
            circuitFactory.MockServiceScope.Verify(scope => scope.Dispose(), Times.Once());
        }