/// <summary> /// Read from a string containing the body of the response /// </summary> /// <param name="content">body of the response</param> /// <param name="statusCode"></param> /// <returns></returns> public static StubHttpResponseMessage From(string content, HttpStatusCode statusCode) { var response = new StubHttpResponseMessage(statusCode); response.Content = new StringContent(content); response.File = "Raw content"; return(response); }
/// <summary> /// Returns a stubbed response (obtained via one of the ResponseFactory methods) /// </summary> /// <param name="stub"></param> /// <param name="reason"></param> /// <returns></returns> public InterceptedHttpCall ReturnStub(StubHttpResponseMessage stub, Reason reason) { if (stub == null) { throw new ArgumentNullException(nameof(stub)); } NewResponse = stub; Global.AddResponseHeader($"Stub [{stub.File}] reason {reason}"); return(this); }
/// <summary> /// Read from a file containing the body of the response /// </summary> /// <param name="fileFullPath"></param> /// <param name="statusCode"></param> /// <returns></returns> public static StubHttpResponseMessage FromBodyOnlyFile(FileFullPath fileFullPath, HttpStatusCode statusCode) { string content = fileFullPath.ReadContent(); var response = new StubHttpResponseMessage(statusCode); response.Content = new StringContent(content, System.Text.Encoding.Default, fileFullPath.GetExtension().GetContentType()); response.SetFile(fileFullPath); return(response); }
internal static StubHttpResponseMessage ReadFiddlerResponseFormat(string content) { var fileParts = FiddlerFilePartsRegex.Match(content); if (!fileParts.Success) { throw new ArgumentException($"File is not in the right format, please consult {Constants.Website}"); } var httpStatusCode = Convert.ToInt32(fileParts.Groups[1].Value); if (!Enum.IsDefined(typeof(HttpStatusCode), httpStatusCode)) { throw new ArgumentException($"Not a valid Http Status code: {httpStatusCode}"); } var httpStatus = (HttpStatusCode)httpStatusCode; var response = new StubHttpResponseMessage(httpStatus); response.Content = Helper.ParseHeadersAndBody(fileParts.Groups[2].Value.Trim(), fileParts.Groups[4].Value.Trim(), response.Headers); return(response); }