public void Build_WithPropertiesSet_FromApplicationModel()
        {
            // Arrange
            var applicationModel = new ApplicationModel();

            applicationModel.Properties["test"] = "application";

            var controller = new ControllerModel(typeof(TestController).GetTypeInfo(),
                                                 new List <object>()
            {
            });

            controller.Application = applicationModel;
            applicationModel.Controllers.Add(controller);

            var methodInfo  = typeof(TestController).GetMethod("SomeAction");
            var actionModel = new ActionModel(methodInfo, new List <object>()
            {
            });

            actionModel.Controller = controller;
            controller.Actions.Add(actionModel);

            // Act
            var descriptors = ControllerActionDescriptorBuilder.Build(applicationModel);

            // Assert
            Assert.Equal("application", descriptors.Single().Properties["test"]);
        }
Exemple #2
0
        public IEnumerable <ControllerActionDescriptor> GetDescriptors()
        {
            var applicationModel = BuildModel();

            ApplicationModelConventions.ApplyConventions(applicationModel, _modelConventions);
            return(ControllerActionDescriptorBuilder.Build(applicationModel));
        }
        public void Build_WithControllerPropertiesSet_AddsPropertiesWithBinderMetadataSet()
        {
            // Arrange
            var applicationModel = new ApplicationModel();
            var controller       = new ControllerModel(
                typeof(TestController).GetTypeInfo(),
                new List <object>()
            {
            });

            var propertyInfo = controller.ControllerType.GetProperty("BoundProperty");

            controller.ControllerProperties.Add(
                new PropertyModel(
                    propertyInfo,
                    new List <object>()
            {
            })
            {
                BindingInfo  = BindingInfo.GetBindingInfo(new object[] { new FromQueryAttribute() }),
                PropertyName = "BoundProperty"
            });

            controller.ControllerProperties.Add(
                new PropertyModel(controller.ControllerType.GetProperty("UnboundProperty"), new List <object>()
            {
            }));

            controller.Application = applicationModel;
            applicationModel.Controllers.Add(controller);

            var methodInfo  = typeof(TestController).GetMethod("SomeAction");
            var actionModel = new ActionModel(methodInfo, new List <object>()
            {
            });

            actionModel.Controller = controller;
            controller.Actions.Add(actionModel);

            // Act
            var descriptors = ControllerActionDescriptorBuilder.Build(applicationModel);

            // Assert
            var controllerDescriptor = Assert.Single(descriptors);

            var parameter = Assert.Single(controllerDescriptor.BoundProperties);
            var property  = Assert.IsType <ControllerBoundPropertyDescriptor>(parameter);

            Assert.Equal("BoundProperty", property.Name);
            Assert.Equal(propertyInfo, property.PropertyInfo);
            Assert.Equal(typeof(string), property.ParameterType);
            Assert.Equal(BindingSource.Query, property.BindingInfo.BindingSource);
        }
Exemple #4
0
        public IEnumerable <ControllerActionDescriptor> GetDescriptors()
        {
            var applicationModel = BuildModel();

            ApplicationModelConventions.ApplyConventions(applicationModel, _modelConventions);
            if (_logger.IsEnabled(LogLevel.Verbose))
            {
                foreach (var controller in applicationModel.Controllers)
                {
                    _logger.WriteVerbose(new ControllerModelValues(controller));
                }
            }
            return(ControllerActionDescriptorBuilder.Build(applicationModel));
        }