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); }
private protected ActionEndpointDataSourceBase CreateDataSource(IActionDescriptorCollectionProvider actions = null) { if (actions == null) { actions = new DefaultActionDescriptorCollectionProvider( Array.Empty <IActionDescriptorProvider>(), Array.Empty <IActionDescriptorChangeProvider>()); } var services = new ServiceCollection(); services.AddSingleton(actions); var routeOptionsSetup = new MvcCoreRouteOptionsSetup(); services.Configure <RouteOptions>(routeOptionsSetup.Configure); services.AddRouting(options => { options.ConstraintMap["upper-case"] = typeof(UpperCaseParameterTransform); }); var serviceProvider = services.BuildServiceProvider(); var endpointFactory = new ActionEndpointFactory(serviceProvider.GetRequiredService <RoutePatternTransformer>(), Enumerable.Empty <IRequestDelegateFactory>()); return(CreateDataSource(actions, endpointFactory)); }
public PageActionEndpointDataSourceFactory( PageActionEndpointDataSourceIdProvider dataSourceIdProvider, IActionDescriptorCollectionProvider actions, ActionEndpointFactory endpointFactory) { _dataSourceIdProvider = dataSourceIdProvider; _actions = actions; _endpointFactory = endpointFactory; }
public PageActionEndpointDataSource(IActionDescriptorCollectionProvider actions, ActionEndpointFactory endpointFactory) : base(actions) { _endpointFactory = endpointFactory; // IMPORTANT: this needs to be the last thing we do in the constructor. // Change notifications can happen immediately! Subscribe(); }
public ControllerActionEndpointDataSourceFactory( ControllerActionEndpointDataSourceIdProvider dataSourceIdProvider, IActionDescriptorCollectionProvider actions, ActionEndpointFactory factory) { _dataSourceIdProvider = dataSourceIdProvider; _actions = actions; _factory = factory; }
public DefaultPageLoader( IEnumerable <IPageApplicationModelProvider> applicationModelProviders, IViewCompilerProvider viewCompilerProvider, ActionEndpointFactory endpointFactory, IOptions <RazorPagesOptions> pageOptions, IOptions <MvcOptions> mvcOptions) { _viewCompilerProvider = viewCompilerProvider; _endpointFactory = endpointFactory; _compiledPageActionDescriptorFactory = new CompiledPageActionDescriptorFactory(applicationModelProviders, mvcOptions.Value, pageOptions.Value); }
public async Task LoadAsync_CreatesEndpoint_WithRoute() { // Arrange var descriptor = 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 razorPagesOptions = Options.Create(new RazorPagesOptions()); var mvcOptions = Options.Create(new MvcOptions()); var endpointFactory = new ActionEndpointFactory(transformer.Object); var provider = new Mock <IPageApplicationModelProvider>(); var pageApplicationModel = new PageApplicationModel(descriptor, typeof(object).GetTypeInfo(), Array.Empty <object>()); provider.Setup(p => p.OnProvidersExecuting(It.IsAny <PageApplicationModelProviderContext>())) .Callback((PageApplicationModelProviderContext c) => { Assert.Null(c.PageApplicationModel); c.PageApplicationModel = pageApplicationModel; }) .Verifiable(); var providers = new[] { provider.Object, }; var loader = new DefaultPageLoader( ActionDescriptorCollectionProvider, providers, compilerProvider, endpointFactory, razorPagesOptions, mvcOptions); // Act var result = await loader.LoadAsync(descriptor); // Assert Assert.NotNull(result.Endpoint); }
public PageActionEndpointDataSource( IActionDescriptorCollectionProvider actions, ActionEndpointFactory endpointFactory, OrderedEndpointsSequenceProvider orderedEndpoints) : base(actions) { _endpointFactory = endpointFactory; _orderSequence = orderedEndpoints; DefaultBuilder = new PageActionEndpointConventionBuilder(Lock, Conventions); // IMPORTANT: this needs to be the last thing we do in the constructor. // Change notifications can happen immediately! Subscribe(); }
public ActionEndpointFactoryTest() { var serviceCollection = new ServiceCollection(); var routeOptionsSetup = new MvcCoreRouteOptionsSetup(); serviceCollection.Configure <RouteOptions>(routeOptionsSetup.Configure); serviceCollection.AddRouting(options => { options.ConstraintMap["upper-case"] = typeof(UpperCaseParameterTransform); }); Services = serviceCollection.BuildServiceProvider(); Factory = new ActionEndpointFactory(Services.GetRequiredService <RoutePatternTransformer>(), Enumerable.Empty <IRequestDelegateFactory>()); }
public DefaultPageLoader( IEnumerable <IPageApplicationModelProvider> applicationModelProviders, IViewCompilerProvider viewCompilerProvider, ActionEndpointFactory endpointFactory, IOptions <RazorPagesOptions> pageOptions, IOptions <MvcOptions> mvcOptions) { _applicationModelProviders = applicationModelProviders .OrderBy(p => p.Order) .ToArray(); _viewCompilerProvider = viewCompilerProvider; _endpointFactory = endpointFactory; _conventions = pageOptions.Value.Conventions; _globalFilters = mvcOptions.Value.Filters; }
public DefaultPageLoader( IActionDescriptorCollectionProvider actionDescriptorCollectionProvider, IEnumerable <IPageApplicationModelProvider> applicationModelProviders, IViewCompilerProvider viewCompilerProvider, ActionEndpointFactory endpointFactory, IOptions <RazorPagesOptions> pageOptions, IOptions <MvcOptions> mvcOptions) { _collectionProvider = actionDescriptorCollectionProvider; _applicationModelProviders = applicationModelProviders .OrderBy(p => p.Order) .ToArray(); _viewCompilerProvider = viewCompilerProvider; _endpointFactory = endpointFactory; _conventions = pageOptions.Value.Conventions ?? throw new ArgumentNullException(nameof(RazorPagesOptions.Conventions)); _globalFilters = mvcOptions.Value.Filters; }
public ControllerActionEndpointDataSource( ControllerActionEndpointDataSourceIdProvider dataSourceIdProvider, IActionDescriptorCollectionProvider actions, ActionEndpointFactory endpointFactory, OrderedEndpointsSequenceProvider orderSequence) : base(actions) { _endpointFactory = endpointFactory; DataSourceId = dataSourceIdProvider.CreateId(); _orderSequence = orderSequence; _routes = new List <ConventionalRouteEntry>(); DefaultBuilder = new ControllerActionEndpointConventionBuilder(Lock, Conventions); // IMPORTANT: this needs to be the last thing we do in the constructor. // Change notifications can happen immediately! Subscribe(); }
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 void RequestDelegateFactoryWorks() { // Arrange var values = new { controller = "TestController", action = "TestAction", page = (string)null }; var action = CreateActionDescriptor(values, "{controller}/{action}/{page}"); action.AttributeRouteInfo.Name = "Test"; RequestDelegate del = context => Task.CompletedTask; var requestDelegateFactory = new Mock <IRequestDelegateFactory>(); requestDelegateFactory.Setup(m => m.CreateRequestDelegate(action, It.IsAny <RouteValueDictionary>())).Returns(del); // Act var factory = new ActionEndpointFactory(Services.GetRequiredService <RoutePatternTransformer>(), new[] { requestDelegateFactory.Object }); var endpoints = new List <Endpoint>(); factory.AddEndpoints(endpoints, new HashSet <string>(), action, Array.Empty <ConventionalRouteEntry>(), Array.Empty <Action <EndpointBuilder> >(), createInertEndpoints: false); var endpoint = Assert.IsType <RouteEndpoint>(Assert.Single(endpoints)); // Assert Assert.Same(del, endpoint.RequestDelegate); }
public async Task LoadAsync_InvokesApplicationModelProviders_WithTheRightOrder() { // 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>(); provider1.SetupGet(p => p.Order).Returns(10); var provider2 = new Mock <IPageApplicationModelProvider>(); provider2.SetupGet(p => p.Order).Returns(-5); var sequence = 0; provider1.Setup(p => p.OnProvidersExecuting(It.IsAny <PageApplicationModelProviderContext>())) .Callback((PageApplicationModelProviderContext c) => { Assert.Equal(1, sequence++); c.PageApplicationModel = new PageApplicationModel(descriptor, typeof(object).GetTypeInfo(), Array.Empty <object>()); }) .Verifiable(); provider2.Setup(p => p.OnProvidersExecuting(It.IsAny <PageApplicationModelProviderContext>())) .Callback((PageApplicationModelProviderContext c) => { Assert.Equal(0, sequence++); }) .Verifiable(); provider1.Setup(p => p.OnProvidersExecuted(It.IsAny <PageApplicationModelProviderContext>())) .Callback((PageApplicationModelProviderContext c) => { Assert.Equal(2, sequence++); }) .Verifiable(); provider2.Setup(p => p.OnProvidersExecuted(It.IsAny <PageApplicationModelProviderContext>())) .Callback((PageApplicationModelProviderContext c) => { Assert.Equal(3, sequence++); }) .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(); }
private protected abstract ActionEndpointDataSourceBase CreateDataSource(IActionDescriptorCollectionProvider actions, ActionEndpointFactory endpointFactory);
private protected override ActionEndpointDataSourceBase CreateDataSource(IActionDescriptorCollectionProvider actions, ActionEndpointFactory endpointFactory) { return(new PageActionEndpointDataSource(actions, endpointFactory, new OrderedEndpointsSequenceProvider())); }
public async Task LoadAsync_InvokesApplicationModelProviders() { // Arrange var descriptor = new PageActionDescriptor(); var compilerProvider = GetCompilerProvider(); var razorPagesOptions = Options.Create(new RazorPagesOptions()); var mvcOptions = Options.Create(new MvcOptions()); var endpointFactory = new ActionEndpointFactory(Mock.Of <RoutePatternTransformer>()); 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( ActionDescriptorCollectionProvider, providers, compilerProvider, endpointFactory, razorPagesOptions, mvcOptions); // Act var result = await loader.LoadAsync(new PageActionDescriptor()); // Assert provider1.Verify(); provider2.Verify(); }