/// <summary> /// Initializes a new instance of the <see cref="AcceptVerbsAttribute" /> class. /// </summary> /// <param name="methods">The HTTP methods the action supports.</param> /// <remarks> /// This constructor is not CLS-compliant. /// </remarks> public AcceptVerbsAttribute(params string[] methods) { _httpMethods = methods != null ? new Collection <HttpMethod>( methods.Select(method => HttpMethodHelper.GetHttpMethod(method)).ToArray() ) : new Collection <HttpMethod>(new HttpMethod[0]); }
public static HttpControllerContext CreateControllerContext( string httpMethod, string requestUrl, string routeUrl, object routeDefault = null ) { string baseAddress = "http://localhost/"; HttpConfiguration config = new HttpConfiguration(); HttpRoute route = routeDefault != null ? new HttpRoute(routeUrl, new HttpRouteValueDictionary(routeDefault)) : new HttpRoute(routeUrl); config.Routes.Add("test", route); HttpRequestMessage request = new HttpRequestMessage( HttpMethodHelper.GetHttpMethod(httpMethod), baseAddress + requestUrl ); IHttpRouteData routeData = config.Routes.GetRouteData(request); if (routeData == null) { throw new InvalidOperationException( "Could not dispatch to controller based on the route." ); } RemoveOptionalRoutingParameters(routeData.Values); HttpControllerContext controllerContext = ContextUtil.CreateControllerContext( config, routeData, request ); return(controllerContext); }
public void GetHttpMethod_RetunsNonStaticResult(string method) { Assert.Equal(method, HttpMethodHelper.GetHttpMethod(method).ToString()); }
public void GetHttpMethod_RetunsStaticResult(string method, HttpMethod expectedMethod) { Assert.Same(expectedMethod, HttpMethodHelper.GetHttpMethod(method)); Assert.Same(expectedMethod, HttpMethodHelper.GetHttpMethod(method.ToLowerInvariant())); Assert.Same(expectedMethod, HttpMethodHelper.GetHttpMethod(method.ToUpperInvariant())); }
public void GetHttpMethod_ReturnsNullOnNullorEmpty() { Assert.Null(HttpMethodHelper.GetHttpMethod(null)); Assert.Null(HttpMethodHelper.GetHttpMethod(String.Empty)); }