public IEnumerable <IMultipartHttpEntity> GetParts() { if (AtEndBoundary) { throw new InvalidOperationException("Can only read through the enumerator once."); } _reader.SeekToNextPart(); // seeks to the first part if (AtEndBoundary) { yield break; } while (ReadEntity()) { yield return(CurrentEntity); } yield break; }
read_line_followed_by_full_read_followed_by_read_line_reads_a_line_the_rest_of_the_part_and_the_line_of_the_next_part () { GivenAMemoryStreamContaining( TextInASCII("--boundary\r\nline1\r\nline2\r\n--boundary\r\nline3\r\nline4\r\n--boundary--")); GivenABoundaryStreamReader("boundary"); Reader.SeekToNextPart(); //ensures we get to our first part Reader.ReadLine().ShouldBe("line1"); Reader.GetNextPart().ReadToEnd().ShouldBe(TextInASCII("line2")); Reader.ReadLine().ShouldBe("line3"); Reader.GetNextPart().ReadToEnd().ShouldBe(TextInASCII("line4")); }