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"]);
        }
        internal protected IEnumerable <ControllerActionDescriptor> GetDescriptors()
        {
            var applicationModel = BuildModel();

            ApplicationModelConventions.ApplyConventions(applicationModel, _conventions);
            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.AsType().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.AsType().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);
        }