public async Task LoadAsync_IsUniquePerPageDescriptor()
    {
        // Arrange
        var descriptor = new PageActionDescriptor()
        {
            AttributeRouteInfo = new AttributeRouteInfo()
            {
                Template = "/test",
            },
        };

        var descriptor2 = new PageActionDescriptor()
        {
            AttributeRouteInfo = new AttributeRouteInfo()
            {
                Template = "/test",
            },
        };

        var transformer = new Mock <RoutePatternTransformer>();

        transformer
        .Setup(t => t.SubstituteRequiredValues(It.IsAny <RoutePattern>(), It.IsAny <object>()))
        .Returns <RoutePattern, object>((p, v) => p);

        var compilerProvider = GetCompilerProvider();

        var mvcOptions      = Options.Create(new MvcOptions());
        var endpointFactory = new ActionEndpointFactory(transformer.Object, Enumerable.Empty <IRequestDelegateFactory>(), Mock.Of <IServiceProvider>());

        var provider = new Mock <IPageApplicationModelProvider>();

        provider.Setup(p => p.OnProvidersExecuting(It.IsAny <PageApplicationModelProviderContext>()))
        .Callback((PageApplicationModelProviderContext c) =>
        {
            Assert.Null(c.PageApplicationModel);
            c.PageApplicationModel = new PageApplicationModel(c.ActionDescriptor, typeof(object).GetTypeInfo(), Array.Empty <object>());
        })
        .Verifiable();

        var providers = new[]
        {
            provider.Object,
        };

        var loader = new DefaultPageLoader(
            providers,
            compilerProvider,
            endpointFactory,
            RazorPagesOptions,
            mvcOptions);

        // Act
        var result1 = await loader.LoadAsync(descriptor, EndpointMetadataCollection.Empty);

        var result2 = await loader.LoadAsync(descriptor2, EndpointMetadataCollection.Empty);

        // Assert
        Assert.NotSame(result1, result2);
    }
Exemple #2
0
        public void NestedPageShouldBeLoaded()
        {
            // Arrange
            var webFormsOptions    = Options.Create(new WebFormsOptions());
            var hostingEnvironment = new HostingEnvironment()
            {
                ApplicationName = "My.AspNetCore.WebForms.Tests"
            };
            var pageLoader = new DefaultPageLoader(webFormsOptions, hostingEnvironment);

            // Act
            var page = pageLoader.Load("Admin/LoginPage");

            // Assert
            Assert.NotNull(page);
        }
Exemple #3
0
        public void LoadPageShouldIgnoreRelativePathCasing(string path)
        {
            // Arrange
            var webFormsOptions    = Options.Create(new WebFormsOptions());
            var hostingEnvironment = new HostingEnvironment()
            {
                ApplicationName = "My.AspNetCore.WebForms.Tests"
            };
            var pageLoader = new DefaultPageLoader(webFormsOptions, hostingEnvironment);

            // Act
            var page = pageLoader.Load(path);

            // Assert
            Assert.NotNull(page);
        }
    public async Task LoadAsync_CompiledPageActionDescriptor_ReturnsSelf()
    {
        // Arrange
        var mvcOptions      = Options.Create(new MvcOptions());
        var endpointFactory = new ActionEndpointFactory(Mock.Of <RoutePatternTransformer>(), Enumerable.Empty <IRequestDelegateFactory>(), Mock.Of <IServiceProvider>());
        var loader          = new DefaultPageLoader(
            new[] { Mock.Of <IPageApplicationModelProvider>() },
            Mock.Of <IViewCompilerProvider>(),
            endpointFactory,
            RazorPagesOptions,
            mvcOptions);
        var pageDescriptor = new CompiledPageActionDescriptor();

        // Act
        var result1 = await loader.LoadAsync(pageDescriptor, new EndpointMetadataCollection());

        var result2 = await loader.LoadAsync(pageDescriptor, new EndpointMetadataCollection());

        // Assert
        Assert.Same(pageDescriptor, result1);
        Assert.Same(pageDescriptor, result2);
    }
    public async Task LoadAsync_InvokesApplicationModelProviders()
    {
        // Arrange
        var descriptor = new PageActionDescriptor();

        var compilerProvider = GetCompilerProvider();

        var mvcOptions      = Options.Create(new MvcOptions());
        var endpointFactory = new ActionEndpointFactory(Mock.Of <RoutePatternTransformer>(), Enumerable.Empty <IRequestDelegateFactory>(), Mock.Of <IServiceProvider>());

        var provider1 = new Mock <IPageApplicationModelProvider>();
        var provider2 = new Mock <IPageApplicationModelProvider>();

        var sequence = 0;
        var pageApplicationModel1 = new PageApplicationModel(descriptor, typeof(object).GetTypeInfo(), Array.Empty <object>());
        var pageApplicationModel2 = new PageApplicationModel(descriptor, typeof(object).GetTypeInfo(), Array.Empty <object>());

        provider1.Setup(p => p.OnProvidersExecuting(It.IsAny <PageApplicationModelProviderContext>()))
        .Callback((PageApplicationModelProviderContext c) =>
        {
            Assert.Equal(0, sequence++);
            Assert.Null(c.PageApplicationModel);
            c.PageApplicationModel = pageApplicationModel1;
        })
        .Verifiable();

        provider2.Setup(p => p.OnProvidersExecuting(It.IsAny <PageApplicationModelProviderContext>()))
        .Callback((PageApplicationModelProviderContext c) =>
        {
            Assert.Equal(1, sequence++);
            Assert.Same(pageApplicationModel1, c.PageApplicationModel);
            c.PageApplicationModel = pageApplicationModel2;
        })
        .Verifiable();

        provider1.Setup(p => p.OnProvidersExecuted(It.IsAny <PageApplicationModelProviderContext>()))
        .Callback((PageApplicationModelProviderContext c) =>
        {
            Assert.Equal(3, sequence++);
            Assert.Same(pageApplicationModel2, c.PageApplicationModel);
        })
        .Verifiable();

        provider2.Setup(p => p.OnProvidersExecuted(It.IsAny <PageApplicationModelProviderContext>()))
        .Callback((PageApplicationModelProviderContext c) =>
        {
            Assert.Equal(2, sequence++);
            Assert.Same(pageApplicationModel2, c.PageApplicationModel);
        })
        .Verifiable();

        var providers = new[]
        {
            provider1.Object, provider2.Object
        };

        var loader = new DefaultPageLoader(
            providers,
            compilerProvider,
            endpointFactory,
            RazorPagesOptions,
            mvcOptions);

        // Act
        var result = await loader.LoadAsync(new PageActionDescriptor(), EndpointMetadataCollection.Empty);

        // Assert
        provider1.Verify();
        provider2.Verify();
    }