public void Can_deserialize_TestRequest_QueryStringSerializer_output() { // Setup var testAppHost = new TestAppHost(new Container(), typeof(TestService).Assembly); var restPath = new RestPath(typeof(TestRequest), "/service", "GET"); var restHandler = new RestHandler { RestPath = restPath }; var requestString = "ListOfA={ListOfB:[{Property:prop1},{Property:prop2}]}"; NameValueCollection queryString = HttpUtility.ParseQueryString(requestString); var httpReq = new HttpRequestMock("service", "GET", "application/json", "service", queryString, new MemoryStream(), new NameValueCollection()); var request2 = (TestRequest)restHandler.CreateRequest(httpReq, "service"); Assert.That(request2.ListOfA.Count, Is.EqualTo(1)); Assert.That(request2.ListOfA.First().ListOfB.Count, Is.EqualTo(2)); }
/// <summary>Gets handler for path information.</summary> /// /// <param name="httpMethod"> The HTTP method.</param> /// <param name="pathInfo"> Information describing the path.</param> /// <param name="requestPath">Full pathname of the request file.</param> /// <param name="filePath"> Full pathname of the file.</param> /// /// <returns>The handler for path information.</returns> public static IHttpHandler GetHandlerForPathInfo(string httpMethod, string pathInfo, string requestPath, string filePath) { var pathParts = pathInfo.TrimStart('/').Split('/'); if (pathParts.Length == 0) { return(NotFoundHttpHandler); } string contentType; var restPath = RestHandler.FindMatchingRestPath(httpMethod, pathInfo, out contentType); if (restPath != null) { return new RestHandler { RestPath = restPath, RequestName = restPath.RequestType.Name, ResponseContentType = contentType } } ; var existingFile = pathParts[0].ToLower(); if (WebHostRootFileNames.Contains(existingFile)) { var fileExt = Path.GetExtension(filePath); var isFileRequest = !string.IsNullOrEmpty(fileExt); if (!isFileRequest && !AutoRedirectsDirs) { //If pathInfo is for Directory try again with redirect including '/' suffix if (!pathInfo.EndsWith("/")) { var appFilePath = filePath.Substring(0, filePath.Length - requestPath.Length); var redirect = Support.StaticFileHandler.DirectoryExists(filePath, appFilePath); if (redirect) { return(new RedirectHttpHandler { RelativeUrl = pathInfo + "/", }); } } } //e.g. CatchAllHandler to Process Markdown files var catchAllHandler = GetCatchAllHandlerIfAny(httpMethod, pathInfo, filePath); if (catchAllHandler != null) { return(catchAllHandler); } if (!isFileRequest) { return(NotFoundHttpHandler); } return(ShouldAllow(requestPath) ? StaticFileHandler : ForbiddenHttpHandler); } var handler = GetCatchAllHandlerIfAny(httpMethod, pathInfo, filePath); if (handler != null) { return(handler); } if (EndpointHost.Config.FallbackRestPath != null) { restPath = EndpointHost.Config.FallbackRestPath(httpMethod, pathInfo, filePath); if (restPath != null) { return(new RestHandler { RestPath = restPath, RequestName = restPath.RequestType.Name, ResponseContentType = contentType }); } } return(null); }