public void CreateDescriptor_CopiesPropertiesFromPageActionDescriptor() { // Arrange var actionDescriptor = new PageActionDescriptor { ActionConstraints = new List <IActionConstraintMetadata>(), AttributeRouteInfo = new AttributeRouteInfo(), EndpointMetadata = new List <object>(), FilterDescriptors = new List <FilterDescriptor>(), RelativePath = "/Foo", RouteValues = new Dictionary <string, string>(), ViewEnginePath = "/Pages/Foo", }; var handlerTypeInfo = typeof(object).GetTypeInfo(); var pageApplicationModel = new PageApplicationModel(actionDescriptor, handlerTypeInfo, new object[0]); var globalFilters = new FilterCollection(); // Act var actual = CompiledPageActionDescriptorBuilder.Build(pageApplicationModel, globalFilters); // Assert Assert.Same(actionDescriptor.ActionConstraints, actual.ActionConstraints); Assert.Same(actionDescriptor.AttributeRouteInfo, actual.AttributeRouteInfo); Assert.Same(actionDescriptor.EndpointMetadata, actual.EndpointMetadata); Assert.Same(actionDescriptor.RelativePath, actual.RelativePath); Assert.Same(actionDescriptor.RouteValues, actual.RouteValues); Assert.Same(actionDescriptor.ViewEnginePath, actual.ViewEnginePath); }
public void CreateDescriptor_CombinesEndpointMetadataFromHandlerTypeAttributesAndAttributesOnModel() { // Arrange var metadata1 = "metadata1"; var metadata2 = "metadata2"; var metadata3 = "metadata3"; var metadata4 = "metadata4"; var metadata5 = "metadata5"; var metadata6 = "metadata6"; var actionDescriptor = new PageActionDescriptor { ActionConstraints = new List <IActionConstraintMetadata>(), AttributeRouteInfo = new AttributeRouteInfo(), EndpointMetadata = new List <object> { metadata3, metadata4, }, FilterDescriptors = new List <FilterDescriptor>(), RelativePath = "/Foo", RouteValues = new Dictionary <string, string>(), ViewEnginePath = "/Pages/Foo", }; var handlerTypeInfo = typeof(object).GetTypeInfo(); var pageApplicationModel = new PageApplicationModel(actionDescriptor, handlerTypeInfo, new[] { metadata1, metadata2, }); pageApplicationModel.EndpointMetadata.Add(metadata5); pageApplicationModel.EndpointMetadata.Add(metadata6); var globalFilters = new FilterCollection(); // Act var actual = CompiledPageActionDescriptorBuilder.Build(pageApplicationModel, globalFilters); // Assert Assert.Equal(new[] { metadata1, metadata2, metadata3, metadata4, metadata5, metadata6 }, actual.EndpointMetadata); }
public void CreateDescriptor_CopiesPropertiesFromPageApplicationModel() { // Arrange var actionDescriptor = new PageActionDescriptor { ActionConstraints = new List <IActionConstraintMetadata>(), AttributeRouteInfo = new AttributeRouteInfo(), FilterDescriptors = new List <FilterDescriptor>(), RelativePath = "/Foo", RouteValues = new Dictionary <string, string>(), ViewEnginePath = "/Pages/Foo", }; var handlerTypeInfo = typeof(TestModel).GetTypeInfo(); var pageApplicationModel = new PageApplicationModel(actionDescriptor, typeof(TestModel).GetTypeInfo(), handlerTypeInfo, new object[0]) { PageType = typeof(TestPage).GetTypeInfo(), ModelType = typeof(TestModel).GetTypeInfo(), Filters = { Mock.Of <IFilterMetadata>(), Mock.Of <IFilterMetadata>(), }, HandlerMethods = { new PageHandlerModel(handlerTypeInfo.GetMethod(nameof(TestModel.OnGet)), new object[0]), }, HandlerProperties = { new PagePropertyModel(handlerTypeInfo.GetProperty(nameof(TestModel.Property)), new object[0]) { BindingInfo = new BindingInfo(), }, } }; var globalFilters = new FilterCollection(); // Act var actual = CompiledPageActionDescriptorBuilder.Build(pageApplicationModel, globalFilters); // Assert Assert.Same(pageApplicationModel.PageType, actual.PageTypeInfo); Assert.Same(pageApplicationModel.DeclaredModelType, actual.DeclaredModelTypeInfo); Assert.Same(pageApplicationModel.ModelType, actual.ModelTypeInfo); Assert.Same(pageApplicationModel.HandlerType, actual.HandlerTypeInfo); Assert.Same(pageApplicationModel.Properties, actual.Properties); Assert.Equal(pageApplicationModel.Filters, actual.FilterDescriptors.Select(f => f.Filter)); Assert.Equal(pageApplicationModel.HandlerMethods.Select(p => p.MethodInfo), actual.HandlerMethods.Select(p => p.MethodInfo)); Assert.Equal(pageApplicationModel.HandlerProperties.Select(p => p.PropertyName), actual.BoundProperties.Select(p => p.Name)); }
public void CreateDescriptor_AddsGlobalFiltersWithTheRightScope() { // Arrange var actionDescriptor = new PageActionDescriptor { ActionConstraints = new List <IActionConstraintMetadata>(), AttributeRouteInfo = new AttributeRouteInfo(), FilterDescriptors = new List <FilterDescriptor>(), RelativePath = "/Foo", RouteValues = new Dictionary <string, string>(), ViewEnginePath = "/Pages/Foo", }; var handlerTypeInfo = typeof(TestModel).GetTypeInfo(); var pageApplicationModel = new PageApplicationModel(actionDescriptor, handlerTypeInfo, new object[0]) { PageType = typeof(TestPage).GetTypeInfo(), ModelType = typeof(TestModel).GetTypeInfo(), Filters = { Mock.Of <IFilterMetadata>(), }, }; var globalFilters = new FilterCollection { Mock.Of <IFilterMetadata>(), }; // Act var compiledPageActionDescriptor = CompiledPageActionDescriptorBuilder.Build(pageApplicationModel, globalFilters); // Assert Assert.Collection( compiledPageActionDescriptor.FilterDescriptors, filterDescriptor => { Assert.Same(globalFilters[0], filterDescriptor.Filter); Assert.Equal(FilterScope.Global, filterDescriptor.Scope); }, filterDescriptor => { Assert.Same(pageApplicationModel.Filters[0], filterDescriptor.Filter); Assert.Equal(FilterScope.Action, filterDescriptor.Scope); }); }
public void CreateDescriptor_ThrowsIfModelIsNotCompatibleWithDeclaredModel() { // Arrange var actionDescriptor = new PageActionDescriptor { ActionConstraints = new List <IActionConstraintMetadata>(), AttributeRouteInfo = new AttributeRouteInfo(), FilterDescriptors = new List <FilterDescriptor>(), RelativePath = "/Foo", RouteValues = new Dictionary <string, string>(), ViewEnginePath = "/Pages/Foo", }; var handlerTypeInfo = typeof(TestModel).GetTypeInfo(); var pageApplicationModel = new PageApplicationModel(actionDescriptor, typeof(TestModel).GetTypeInfo(), handlerTypeInfo, new object[0]) { PageType = typeof(TestPage).GetTypeInfo(), ModelType = typeof(string).GetTypeInfo(), Filters = { Mock.Of <IFilterMetadata>(), Mock.Of <IFilterMetadata>(), }, HandlerMethods = { new PageHandlerModel(handlerTypeInfo.GetMethod(nameof(TestModel.OnGet)), new object[0]), }, HandlerProperties = { new PagePropertyModel(handlerTypeInfo.GetProperty(nameof(TestModel.Property)), new object[0]) { BindingInfo = new BindingInfo(), }, } }; var globalFilters = new FilterCollection(); // Act & Assert var actual = Assert.Throws <InvalidOperationException>(() => CompiledPageActionDescriptorBuilder.Build(pageApplicationModel, globalFilters)); }