public void ApplyConventions_InvokesHandlerModelConventions() { // Arrange var descriptor = new PageActionDescriptor(); var methodInfo = GetType().GetMethod(nameof(OnGet), BindingFlags.Instance | BindingFlags.NonPublic); var handlerModelConvention = new Mock <IPageHandlerModelConvention>(); var applicationModel = new PageApplicationModel(descriptor, typeof(object).GetTypeInfo(), Array.Empty <object>()); var handlerModel = new PageHandlerModel(methodInfo, new[] { handlerModelConvention.Object }); applicationModel.HandlerMethods.Add(handlerModel); handlerModelConvention.Setup(p => p.Apply(It.IsAny <PageHandlerModel>())) .Callback((PageHandlerModel m) => { Assert.Same(handlerModel, m); }) .Verifiable(); var conventionCollection = new PageConventionCollection(Mock.Of <IServiceProvider>()); // Act CompiledPageActionDescriptorFactory.ApplyConventions(conventionCollection, applicationModel); // Assert handlerModelConvention.Verify(); }
public void ApplyConventions_RemovingPropertyModelAsPartOfConvention_Works() { // Arrange var descriptor = new PageActionDescriptor(); var propertyInfo = GetType().GetProperty(nameof(TestProperty), BindingFlags.Instance | BindingFlags.NonPublic); var applicationModel = new PageApplicationModel(descriptor, typeof(object).GetTypeInfo(), Array.Empty <object>()); var propertyModelConvention = new Mock <IParameterModelBaseConvention>(); var propertyModel = new PagePropertyModel(propertyInfo, new[] { propertyModelConvention.Object }) { Page = applicationModel, }; applicationModel.HandlerProperties.Add(propertyModel); propertyModelConvention.Setup(p => p.Apply(It.IsAny <ParameterModelBase>())) .Callback((ParameterModelBase m) => { var model = Assert.IsType <PagePropertyModel>(m); model.Page.HandlerProperties.Remove(model); }) .Verifiable(); var conventionCollection = new PageConventionCollection(Mock.Of <IServiceProvider>()); // Act CompiledPageActionDescriptorFactory.ApplyConventions(conventionCollection, applicationModel); // Assert propertyModelConvention.Verify(); }
public void ApplyConventions_InvokesApplicationModelConventions_SpecifiedOnHandlerType() { // Arrange var descriptor = new PageActionDescriptor(); var handlerConvention = new Mock <IPageApplicationModelConvention>(); var model = new PageApplicationModel(descriptor, typeof(object).GetTypeInfo(), new[] { handlerConvention.Object }); var globalConvention = new Mock <IPageApplicationModelConvention>(); globalConvention.Setup(c => c.Apply(It.IsAny <PageApplicationModel>())) .Callback((PageApplicationModel m) => { Assert.Same(model, m); }) .Verifiable(); handlerConvention.Setup(c => c.Apply(It.IsAny <PageApplicationModel>())) .Callback((PageApplicationModel m) => { Assert.Same(model, m); }) .Verifiable(); var conventionCollection = new PageConventionCollection(Mock.Of <IServiceProvider>()) { globalConvention.Object, }; // Act CompiledPageActionDescriptorFactory.ApplyConventions(conventionCollection, model); // Assert globalConvention.Verify(); handlerConvention.Verify(); }
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 CompiledPageActionDescriptorProvider( IEnumerable <IPageRouteModelProvider> pageRouteModelProviders, IEnumerable <IPageApplicationModelProvider> applicationModelProviders, ApplicationPartManager applicationPartManager, IOptions <MvcOptions> mvcOptions, IOptions <RazorPagesOptions> pageOptions) { _pageActionDescriptorProvider = new PageActionDescriptorProvider(pageRouteModelProviders, mvcOptions, pageOptions); _applicationPartManager = applicationPartManager; _compiledPageActionDescriptorFactory = new CompiledPageActionDescriptorFactory(applicationModelProviders, mvcOptions.Value, pageOptions.Value); }