public void CreateHandlerMethods_CopiesPropertiesFromHandlerModel()
        {
            // Arrange
            var actionDescriptor = new PageActionDescriptor();
            var handlerTypeInfo  = typeof(ModelWithHandler).GetTypeInfo();
            var handlerModel     = new PageHandlerModel(handlerTypeInfo.GetMethod(nameof(ModelWithHandler.OnGetCustomerAsync)), new object[0])
            {
                HttpMethod  = "GET",
                HandlerName = "Customer",
            };
            var pageApplicationModel = new PageApplicationModel(actionDescriptor, handlerTypeInfo, new object[0])
            {
                HandlerMethods =
                {
                    handlerModel,
                }
            };

            // Act
            var handlerDescriptors = CompiledPageActionDescriptorBuilder.CreateHandlerMethods(pageApplicationModel);

            // Assert
            Assert.Collection(
                handlerDescriptors,
                d =>
            {
                Assert.Equal(handlerModel.MethodInfo, d.MethodInfo);
                Assert.Equal(handlerModel.HttpMethod, d.HttpMethod);
                Assert.Equal(handlerModel.HandlerName, d.Name);
            });
        }
        public void CreateHandlerMethods_CopiesParameterDescriptorsFromParameterModel()
        {
            // Arrange
            var actionDescriptor = new PageActionDescriptor();
            var handlerTypeInfo  = typeof(HandlerWithParameters).GetTypeInfo();
            var handlerMethod    = handlerTypeInfo.GetMethod(nameof(HandlerWithParameters.OnPost));
            var parameters       = handlerMethod.GetParameters();
            var parameterModel1  = new PageParameterModel(parameters[0], new object[0])
            {
                ParameterName = "test-name"
            };
            var parameterModel2 = new PageParameterModel(parameters[1], new object[0])
            {
                BindingInfo = new BindingInfo(),
            };
            var handlerModel = new PageHandlerModel(handlerMethod, new object[0])
            {
                Parameters =
                {
                    parameterModel1,
                    parameterModel2,
                }
            };
            var pageApplicationModel = new PageApplicationModel(actionDescriptor, handlerTypeInfo, new object[0])
            {
                HandlerMethods =
                {
                    handlerModel,
                }
            };

            // Act
            var handlerDescriptors = CompiledPageActionDescriptorBuilder.CreateHandlerMethods(pageApplicationModel);

            // Assert
            Assert.Collection(
                Assert.Single(handlerDescriptors).Parameters,
                p =>
            {
                Assert.Equal(parameters[0], p.ParameterInfo);
                Assert.Equal(typeof(string), p.ParameterType);
                Assert.Equal(parameterModel1.ParameterName, p.Name);
            },
                p =>
            {
                Assert.Equal(parameters[1], p.ParameterInfo);
                Assert.Equal(typeof(int), p.ParameterType);
                Assert.Same(parameterModel2.BindingInfo, p.BindingInfo);
            });
        }