public void ReadUntilSpace_ReadAll_TextMatch(string fName, int bufferSize) { TestPrecondition.EnsureFileExist(fName); var sb = new StringBuilder(); string expected; using (Stream stream = File.OpenRead(fName)) { using (var reader = new StreamReader(stream)) { expected = reader.ReadToEnd(); } } using (Stream stream = File.OpenRead(fName)) { using (var reader = new TextReader(stream)) { while (reader.CanRead) { string chunk; reader.ReadUntilSpace(bufferSize, out chunk); sb.Append(chunk); } } } string actual = sb.ToString(); Assert.AreEqual(expected, actual); }
internal ITextStatistic Crunch(Stream stream, CancellationToken cancellationToken) { int readCount = -1; int bufferSize = 1024; string chunk; var reader = new TextReader(stream); while (readCount > 0) { readCount = reader.ReadUntilSpace( bufferSize, out chunk); cancellationToken.ThrowIfCancellationRequested(); break; } return new TextStatistic() as ITextStatistic; }
public void ReadUntilSpace_ReadAll_CountMatch(string fName) { TestPrecondition.EnsureFileExist(fName); int actual = 0; const int bufSize = 1024; long expected; using (Stream stream = File.OpenRead(fName)) { expected = stream.Length; using (var reader = new TextReader(stream)) { while (reader.CanRead) { string chunk; int singleRead = reader.ReadUntilSpace( bufSize, out chunk); actual += singleRead; } } } Assert.AreEqual(expected, actual); }
public void ReadUntilSpace_ReadCount_Exception(string fName, int invalidReadCount) { TestPrecondition.EnsureFileExist(fName); string chunk; int actual; using (Stream stream = File.OpenRead(fName)) { using (var reader = new TextReader(stream)) { actual = reader.ReadUntilSpace(invalidReadCount, out chunk); } } Assert.Fail("Shouldn't reach this code"); }