public void GetActions_RouteOnController_CreatesOneActionInforPerRouteTemplateOnAction(Type controller) { // Arrange var builder = new DefaultActionModelBuilder(); var typeInfo = controller.GetTypeInfo(); // Act var actions = builder.BuildActionModels(typeInfo, typeInfo.GetMethod("Index")); // Assert Assert.Equal(2, actions.Count()); foreach (var action in actions) { Assert.Equal("Index", action.ActionName); var httpMethod = Assert.Single(action.HttpMethods); Assert.Equal("GET", httpMethod); Assert.NotNull(action.AttributeRouteModel.Template); Assert.IsType <HttpGetAttribute>(Assert.Single(action.Attributes)); } Assert.Single(actions, ai => ai.AttributeRouteModel.Template.Equals("List")); Assert.Single(actions, ai => ai.AttributeRouteModel.Template.Equals("All")); }
public void GetActions_AttributeRouteOnAction() { // Arrange var builder = new DefaultActionModelBuilder(); var typeInfo = typeof(NoRouteAttributeOnControllerController).GetTypeInfo(); var actionName = nameof(NoRouteAttributeOnControllerController.Edit); // Act var actions = builder.BuildActionModels(typeInfo, typeInfo.GetMethod(actionName)); // Assert var action = Assert.Single(actions); Assert.Equal("Edit", action.ActionName); Assert.True(action.IsActionNameMatchRequired); var httpMethod = Assert.Single(action.HttpMethods); Assert.Equal("POST", httpMethod); Assert.NotNull(action.AttributeRouteModel); Assert.Equal("Change", action.AttributeRouteModel.Template); Assert.IsType <HttpPostAttribute>(Assert.Single(action.Attributes)); }
public void GetActions_AttributeRouteOnAction_CreatesOneActionInforPerRouteTemplate() { // Arrange var builder = new DefaultActionModelBuilder(); var typeInfo = typeof(NoRouteAttributeOnControllerController).GetTypeInfo(); var actionName = nameof(NoRouteAttributeOnControllerController.Index); // Act var actions = builder.BuildActionModels(typeInfo, typeInfo.GetMethod(actionName)); // Assert Assert.Equal(2, actions.Count()); foreach (var action in actions) { Assert.Equal("Index", action.ActionName); Assert.NotNull(action.AttributeRouteModel); } var list = Assert.Single(actions, ai => ai.AttributeRouteModel.Template.Equals("List")); var listMethod = Assert.Single(list.HttpMethods); Assert.Equal("POST", listMethod); Assert.IsType <HttpPostAttribute>(Assert.Single(list.Attributes)); var all = Assert.Single(actions, ai => ai.AttributeRouteModel.Template.Equals("All")); var allMethod = Assert.Single(all.HttpMethods); Assert.Equal("GET", allMethod); Assert.IsType <HttpGetAttribute>(Assert.Single(all.Attributes)); }
public void BuildActionModel_DisableCorsAttributeAddsDisableCorsAuthorizationFilter() { // Arrange var builder = new DefaultActionModelBuilder(authorizationOptions: null); var typeInfo = typeof(DisableCorsController).GetTypeInfo(); var method = typeInfo.GetMethod("Action"); // Act var actions = builder.BuildActionModels(typeInfo, method); // Assert var action = Assert.Single(actions); Assert.True(action.Filters.Any(f => f is DisableCorsAuthorizationFilter)); }
public void GetActions_MixedHttpVerbsAndRoutes_EmptyVerbWithRoute() { // Arrange var builder = new DefaultActionModelBuilder(); var typeInfo = typeof(MixedHttpVerbsAndRouteAttributeController).GetTypeInfo(); var actionName = nameof(MixedHttpVerbsAndRouteAttributeController.VerbAndRoute); // Act var actions = builder.BuildActionModels(typeInfo, typeInfo.GetMethod(actionName)); // Assert var action = Assert.Single(actions); Assert.Equal <string>(new string[] { "GET" }, action.HttpMethods); Assert.Equal("Products", action.AttributeRouteModel.Template); }
public void GetActions_ConventionallyRoutedAction_WithMultipleHttpConstraints() { // Arrange var builder = new DefaultActionModelBuilder(); var typeInfo = typeof(ConventionallyRoutedController).GetTypeInfo(); var actionName = nameof(ConventionallyRoutedController.Details); // Act var actions = builder.BuildActionModels(typeInfo, typeInfo.GetMethod(actionName)); // Assert var action = Assert.Single(actions); Assert.Contains("GET", action.HttpMethods); Assert.Contains("POST", action.HttpMethods); Assert.Equal("Details", action.ActionName); Assert.Null(action.AttributeRouteModel); }
public void GetActions_ConventionallyRoutedAction_WithoutHttpConstraints() { // Arrange var builder = new DefaultActionModelBuilder(); var typeInfo = typeof(ConventionallyRoutedController).GetTypeInfo(); var actionName = nameof(ConventionallyRoutedController.Edit); // Act var actions = builder.BuildActionModels(typeInfo, typeInfo.GetMethod(actionName)); // Assert var action = Assert.Single(actions); Assert.Equal("Edit", action.ActionName); Assert.True(action.IsActionNameMatchRequired); Assert.Empty(action.HttpMethods); Assert.Null(action.AttributeRouteModel); Assert.Empty(action.Attributes); }
public void GetActions_MixedHttpVerbsAndRoutes_MultipleEmptyAndNonEmptyVerbs() { // Arrange var builder = new DefaultActionModelBuilder(); var typeInfo = typeof(MixedHttpVerbsAndRouteAttributeController).GetTypeInfo(); var actionName = nameof(MixedHttpVerbsAndRouteAttributeController.Invalid); // Act var actions = builder.BuildActionModels(typeInfo, typeInfo.GetMethod(actionName)); // Assert Assert.Equal(2, actions.Count()); var action = Assert.Single(actions, a => a.AttributeRouteModel?.Template == "Products"); Assert.Equal <string>(new string[] { "POST" }, action.HttpMethods); action = Assert.Single(actions, a => a.AttributeRouteModel?.Template == null); Assert.Equal <string>(new string[] { "GET" }, action.HttpMethods); }
public void GetActions_RouteAttributeOnController_CreatesAttributeRoute_ForNonAttributedActions(Type controller) { // Arrange var builder = new DefaultActionModelBuilder(); var typeInfo = controller.GetTypeInfo(); // Act var actions = builder.BuildActionModels(typeInfo, typeInfo.GetMethod("Delete")); // Assert var action = Assert.Single(actions); Assert.Equal("Delete", action.ActionName); Assert.Empty(action.HttpMethods); Assert.Null(action.AttributeRouteModel); Assert.Empty(action.Attributes); }
public void GetActions_ConventionallyRoutedAction_WithHttpConstraints() { // Arrange var builder = new DefaultActionModelBuilder(); var typeInfo = typeof(ConventionallyRoutedController).GetTypeInfo(); var actionName = nameof(ConventionallyRoutedController.Update); // Act var actions = builder.BuildActionModels(typeInfo, typeInfo.GetMethod(actionName)); // Assert var action = Assert.Single(actions); Assert.Contains("PUT", action.HttpMethods); Assert.Contains("PATCH", action.HttpMethods); Assert.Equal("Update", action.ActionName); Assert.Null(action.AttributeRouteModel); Assert.IsType <CustomHttpMethodsAttribute>(Assert.Single(action.Attributes)); }
public void GetActions_NoRouteOnController_AllowsConventionallyRoutedActions_OnTheSameController() { // Arrange var builder = new DefaultActionModelBuilder(); var typeInfo = typeof(NoRouteAttributeOnControllerController).GetTypeInfo(); var actionName = nameof(NoRouteAttributeOnControllerController.Remove); // Act var actions = builder.BuildActionModels(typeInfo, typeInfo.GetMethod(actionName)); // Assert var action = Assert.Single(actions); Assert.Equal("Remove", action.ActionName); Assert.Empty(action.HttpMethods); Assert.Null(action.AttributeRouteModel); Assert.Empty(action.Attributes); }
public void GetActions_AttributeRouteOnAction_AcceptVerbsAttributeWithTemplate() { // Arrange var builder = new DefaultActionModelBuilder(); var typeInfo = typeof(NoRouteAttributeOnControllerController).GetTypeInfo(); var actionName = nameof(NoRouteAttributeOnControllerController.List); // Act var actions = builder.BuildActionModels(typeInfo, typeInfo.GetMethod(actionName)); // Assert var action = Assert.Single(actions); Assert.Equal("List", action.ActionName); Assert.Equal(new[] { "GET", "HEAD" }, action.HttpMethods.OrderBy(m => m, StringComparer.Ordinal)); Assert.NotNull(action.AttributeRouteModel); Assert.Equal("ListAll", action.AttributeRouteModel.Template); Assert.IsType <AcceptVerbsAttribute>(Assert.Single(action.Attributes)); }
public void GetActions_AttributeRouteOnAction_RouteAttribute() { // Arrange var builder = new DefaultActionModelBuilder(); var typeInfo = typeof(NoRouteAttributeOnControllerController).GetTypeInfo(); var actionName = nameof(NoRouteAttributeOnControllerController.Update); // Act var actions = builder.BuildActionModels(typeInfo, typeInfo.GetMethod(actionName)); // Assert var action = Assert.Single(actions); Assert.Equal("Update", action.ActionName); Assert.Empty(action.HttpMethods); Assert.NotNull(action.AttributeRouteModel); Assert.Equal("Update", action.AttributeRouteModel.Template); Assert.IsType <RouteAttribute>(Assert.Single(action.Attributes)); }
public void GetActions_ConventionallyRoutedActionWithHttpConstraints_AndInvalidRouteTemplateProvider() { // Arrange var builder = new DefaultActionModelBuilder(); var typeInfo = typeof(ConventionallyRoutedController).GetTypeInfo(); var actionName = nameof(ConventionallyRoutedController.Delete); // Act var actions = builder.BuildActionModels(typeInfo, typeInfo.GetMethod(actionName)); // Assert var action = Assert.Single(actions); Assert.Equal("Delete", action.ActionName); var httpMethod = Assert.Single(action.HttpMethods); Assert.Equal("DELETE", httpMethod); Assert.Null(action.AttributeRouteModel); Assert.IsType <HttpDeleteAttribute>(Assert.Single(action.Attributes)); }