public void RouteAttrbute_should_ConvertTo_Mvc_Attrute_Others_justCopy()
        {
            var convention      = new ControllerModelConvention(_mvcControllerManager);
            var controllerModel = new ControllerModel(typeof(TestWebApiService).GetTypeInfo(), new object[] {});

            convention.Apply(controllerModel);
        }
Beispiel #2
0
        public void ControllerConvention()
        {
            var provider = services.BuildServiceProvider();

            var controllerTypeInfo = typeof(TestController).GetTypeInfo();

            var convention = new ControllerModelConvention(provider, new RoutingOptions
            {
                Controllers =
                {
                    [controllerTypeInfo] = new RouteDeclaration("test")
                    {
                    ActionName        = "name",
                    Filters           = { sp => new RequireHttpsAttribute() },
                    ActionConstraints = { sp => new HttpMethodActionConstraint(new [] { "method" }) }
                    }
                }
            });

            var model = new ControllerModel(controllerTypeInfo, Array.Empty <object>());

            convention.Apply(model);

            Assert.Empty(model.Actions);
            Assert.Empty(model.Attributes);
            Assert.Empty(model.ControllerProperties);
            Assert.Equal(model.ControllerType, controllerTypeInfo);
            Assert.Empty(model.Properties);
            Assert.Empty(model.RouteValues);
            Assert.IsType <RequireHttpsAttribute>(Assert.Single(model.Filters));
            var selector = Assert.Single(model.Selectors);

            var methodConstraint = Assert.IsType <HttpMethodActionConstraint>(Assert.Single(selector.ActionConstraints));

            Assert.Equal("method", Assert.Single(methodConstraint.HttpMethods));

            Assert.Equal("name", selector.AttributeRouteModel.Name);
            Assert.Equal("test", selector.AttributeRouteModel.Template);
            Assert.IsType <RouteAttribute>(selector.AttributeRouteModel.Attribute);
        }