public void ReadUntilBoundary_boundaryNotExist_throws() { string content = "before1\r\nbefore2"; Assert.Throws <InvalidDataException>( () => BatchSerializeHelper.ReadUntilBoundaryOrThrow(GetReaderFor(content), "someBoundary")); }
/// <exception cref="InvalidDataException"></exception> private HttpResponse <string> ParseNextSubresponseFrom(PeekableStreamReader reader, string boundary) { var currentLine = reader.ReadFirstNonEmptyLine(); if (currentLine != BatchSerializeHelper.GetOpenBoundaryString(boundary)) { throw new InvalidDataException("Response boundary missed"); } currentLine = reader.ReadFirstNonEmptyLineOrThrow("Content type header not found"); // if (currentLine?.Trim() != HttpHelper.HttpRequestContentTypeHeaderString) if (!currentLine.Trim().StartsWith(HttpHelper.ContentTypeHeader)) { throw new InvalidDataException("Content type has invalid format"); } currentLine = reader.ReadFirstNonEmptyLineOrThrow("Status code is missed"); var resultCode = BatchSerializeHelper.GetResultCodeOrThrow(currentLine); var content = BatchSerializeHelper.ReadUntilBoundaryOrThrow(reader, boundary); return(new HttpResponse <string>( new ResponseInfo((HttpStatusCode)resultCode), content)); }
public void ReadUntilBoundary_boundaryIsNotLast_ResultsAreCorrect(string beforeBoundary, string afterBoundary) { string boundary = "theBoundary"; var text = $"{beforeBoundary}\r\n--{boundary}\r\n{afterBoundary}"; var actual = BatchSerializeHelper.ReadUntilBoundaryOrThrow(GetReaderFor(text), boundary); Assert.AreEqual(beforeBoundary, actual); }
public void ReadUntilBoundary_boundaryIsLast_ResultsAreCorrect() { string boundary = "theBoundary"; string content = "before1\r\nbefore2"; var text = $"{content}\r\n--{boundary}--\r\nsome string after"; var actual = BatchSerializeHelper.ReadUntilBoundaryOrThrow(GetReaderFor(text), boundary); Assert.AreEqual(content, actual); }