/// <summary> /// 确定是否应考虑将此操作用于生成 System.Web.Http.Description.ApiExplorer.ApiDescriptions。初始化 System.Web.Http.Description.ApiExplorer.ApiDescriptions时调用。 /// </summary> /// <param name="actionVariableValue">来自路由的操作变量值</param> /// <param name="actionDescriptor">操作描述符.</param> /// <param name="route">路由</param> /// <returns>如果应考虑将此操作用于生成 System.Web.Http.Description.ApiExplorer.ApiDescriptions,则为 true,否则为 false。</returns> public override bool ShouldExploreAction(string actionVariableValue, HttpActionDescriptor actionDescriptor, IHttpRoute route) { if (actionDescriptor == null) { throw new ArgumentNullException("actionDescriptor"); } if (route == null) { throw new ArgumentNullException("route"); } ApiExplorerSettingsAttribute setting = actionDescriptor.GetCustomAttributes <ApiExplorerSettingsAttribute>().FirstOrDefault(); NonActionAttribute nonAction = actionDescriptor.GetCustomAttributes <NonActionAttribute>().FirstOrDefault(); string hcNamespace = string.Empty; string routetemplate = string.Empty; routetemplate = route.RouteTemplate.Split('/')[1]; hcNamespace = actionDescriptor.ControllerDescriptor.ControllerType.Namespace; if (hcNamespace.Contains(routetemplate)) { return((setting == null || !setting.IgnoreApi) && (nonAction == null) && MatchRegexConstraint(route, "action", actionVariableValue)); } else { return(false); } }
public void InValidActionForRequestReturnsFalse() { // Arrange NonActionAttribute attr = new NonActionAttribute(); // Act & Assert Assert.False(attr.IsValidForRequest(null, null)); }
public void InValidActionForRequestReturnsFalse() { // Arrange NonActionAttribute attr = new NonActionAttribute(); // Act & Assert Assert.IsFalse(attr.IsValidForRequest(null, null), "[NonAction] should not be valid for any request."); }
/// <summary> /// Determines whether the action should be considered for /// <see cref="P:System.Web.Http.Description.IApiExplorer.ApiDescriptions"/> generation. /// Called when initializing the <see cref="P:System.Web.Http.Description.IApiExplorer.ApiDescriptions"/>. /// </summary> /// <param name="actionVariableValue">The action variable value from the route.</param> /// <param name="actionDescriptor">The action descriptor.</param> /// <param name="route">The route.</param> /// <returns><b>true</b> if the action should be considered for /// <see cref="P:System.Web.Http.Description.IApiExplorer.ApiDescriptions"/> generation, <c>false</c> otherwise.</returns> /// <exception cref="T:System.ArgumentNullException">actionDescriptor</exception> /// <exception cref="T:System.ArgumentNullException">route</exception> public virtual bool ShouldExploreAction(string actionVariableValue, HttpActionDescriptor actionDescriptor, IHttpRoute route) { Throw.IfArgumentNull(actionDescriptor, "actionDescriptor"); Throw.IfArgumentNull(route, "route"); ApiExplorerSettingsAttribute setting = actionDescriptor.GetCustomAttributes <ApiExplorerSettingsAttribute>().FirstOrDefault(); NonActionAttribute nonAction = actionDescriptor.GetCustomAttributes <NonActionAttribute>().FirstOrDefault(); return((setting == null || !setting.IgnoreApi) && (nonAction == null) && MatchRegexConstraint(route, ActionVariableName, actionVariableValue)); }
/// <summary> /// Determines whether the action should be considered for <see cref="ApiExplorer.ApiDescriptions"/> generation. Called when initializing the <see cref="ApiExplorer.ApiDescriptions"/>. /// </summary> /// <param name="actionVariableValue">The action variable value from the route.</param> /// <param name="actionDescriptor">The action descriptor.</param> /// <param name="route">The route.</param> /// <returns><c>true</c> if the action should be considered for <see cref="ApiExplorer.ApiDescriptions"/> generation, <c>false</c> otherwise.</returns> public virtual bool ShouldExploreAction(string actionVariableValue, HttpActionDescriptor actionDescriptor, IHttpRoute route) { if (actionDescriptor == null) { throw Error.ArgumentNull("actionDescriptor"); } if (route == null) { throw Error.ArgumentNull("route"); } ApiExplorerSettingsAttribute setting = actionDescriptor.GetCustomAttributes <ApiExplorerSettingsAttribute>().FirstOrDefault(); NonActionAttribute nonAction = actionDescriptor.GetCustomAttributes <NonActionAttribute>().FirstOrDefault(); return((setting == null || !setting.IgnoreApi) && (nonAction == null) && MatchRegexConstraint(route, RouteKeys.ActionKey, actionVariableValue)); }