Exemplo n.º 1
0
        public void TryParseHandler_ParsesHandlerNames_InvalidData(string methodName)
        {
            // Act
            var result = DefaultPageApplicationModelProvider.TryParseHandlerMethod(methodName, out var httpMethod, out var handler);

            // Assert
            Assert.False(result);
            Assert.Null(httpMethod);
            Assert.Null(handler);
        }
Exemplo n.º 2
0
        private static PageApplicationModelProviderContext GetApplicationProviderContext(TypeInfo typeInfo)
        {
            var defaultProvider = new DefaultPageApplicationModelProvider(
                TestModelMetadataProvider.CreateDefaultProvider(),
                Options.Create(new RazorPagesOptions()));

            var context = new PageApplicationModelProviderContext(new PageActionDescriptor(), typeInfo);

            defaultProvider.OnProvidersExecuting(context);

            return(context);
        }
Exemplo n.º 3
0
        public void TryParseHandler_ParsesHandlerNames_ValidData(string methodName, string expectedHttpMethod, string expectedHandler)
        {
            // Arrange

            // Act
            var result = DefaultPageApplicationModelProvider.TryParseHandlerMethod(methodName, out var httpMethod, out var handler);

            // Assert
            Assert.True(result);
            Assert.Equal(expectedHttpMethod, httpMethod);
            Assert.Equal(expectedHandler, handler);
        }
        private static PageApplicationModelProviderContext GetApplicationProviderContext(TypeInfo typeInfo)
        {
            var defaultProvider = new DefaultPageApplicationModelProvider(
                TestModelMetadataProvider.CreateDefaultProvider(),
                Options.Create(new MvcOptions {
                AllowValidatingTopLevelNodes = true
            }),
                Options.Create(new RazorPagesOptions {
                AllowDefaultHandlingForOptionsRequests = true
            }));
            var context = new PageApplicationModelProviderContext(new PageActionDescriptor(), typeInfo);

            defaultProvider.OnProvidersExecuting(context);
            return(context);
        }
Exemplo n.º 5
0
        public void PopulateFilters_With21CompatBehavior_DoesNotAddDisallowOptionsRequestsPageFilter()
        {
            // Arrange
            var provider = new DefaultPageApplicationModelProvider(
                TestModelMetadataProvider.CreateDefaultProvider(),
                Options.Create(new MvcOptions()),
                Options.Create(new RazorPagesOptions()));
            var typeInfo  = typeof(object).GetTypeInfo();
            var pageModel = new PageApplicationModel(new PageActionDescriptor(), typeInfo, typeInfo.GetCustomAttributes(inherit: true));

            // Act
            provider.PopulateFilters(pageModel);

            // Assert
            Assert.Empty(pageModel.Filters);
        }
Exemplo n.º 6
0
        public void CreateHandlerMethods_WithLegacyValidationBehavior_AddsParameterDescriptors()
        {
            // Arrange
            var provider = new DefaultPageApplicationModelProvider(
                TestModelMetadataProvider.CreateDefaultProvider(),
                Options.Create(new MvcOptions {
                AllowValidatingTopLevelNodes = false
            }),
                Options.Create(new RazorPagesOptions()));
            var typeInfo  = typeof(PageWithHandlerParameters).GetTypeInfo();
            var expected  = typeInfo.GetMethod(nameof(PageWithHandlerParameters.OnPost));
            var pageModel = new PageApplicationModel(new PageActionDescriptor(), typeInfo, new object[0]);

            // Act
            provider.PopulateHandlerMethods(pageModel);

            // Assert
            var handlerMethods = pageModel.HandlerMethods;
            var handler        = Assert.Single(handlerMethods);

            Assert.Collection(
                handler.Parameters,
                p =>
            {
                Assert.NotNull(p.ParameterInfo);
                Assert.Equal(typeof(string), p.ParameterInfo.ParameterType);
                Assert.Equal("name", p.ParameterName);
            },
                p =>
            {
                Assert.NotNull(p.ParameterInfo);
                Assert.Equal(typeof(int), p.ParameterInfo.ParameterType);
                Assert.Equal("id", p.ParameterName);
                Assert.Equal("personId", p.BindingInfo.BinderModelName);
            });
        }