Example #1
0
        public void Readbuffer_in_multiple_attempts_with_more_whitespace_than_buffersize_trailing()
        {
            var text   = "this is some text                                                                                                                                                                                                                                                                                    ";
            var reader = new TrimmingTextReader(new StringReader(text));
            var result = new StringBuilder();
            var buffer = new char[1024];
            var read   = reader.Read(buffer, 0, 24);
            var total  = read;

            Assert.AreEqual('t', buffer[0]);
            read   = reader.Read(buffer, read, buffer.Length);
            total += read;
            result.Append(buffer, 0, total);
            Assert.AreEqual("this is some text", result.ToString());
        }
Example #2
0
        public void Readbuffer_in_multiple_attempts_with_whitespace_between_chunks()
        {
            var text   = "   this is some text                                          with lots of whitespace in the middle   ";
            var reader = new TrimmingTextReader(new StringReader(text));
            var result = new StringBuilder();
            var buffer = new char[1024];
            var read   = reader.Read(buffer, 0, 24);
            var total  = read;

            Assert.AreEqual(24, read);
            Assert.AreEqual('t', buffer[0]);
            read   = reader.Read(buffer, read, buffer.Length);
            total += read;
            result.Append(buffer, 0, total);
            Assert.AreEqual("this is some text                                          with lots of whitespace in the middle", result.ToString());
        }
Example #3
0
        public void Trim_both_the_beginning_and_end_via_readbuffer()
        {
            TextReader reader = new StringReader("   this is plain text   ");

            reader = new TrimmingTextReader(reader);
            var buffer = new char[1024];
            var read   = reader.Read(buffer, 0, buffer.Length);
            var result = new StringBuilder();

            result.Append(buffer, 0, read);
            Assert.AreEqual("this is plain text", result.ToString());
        }
Example #4
0
        public void Trimming_reader_retries_against_stream_when_request_bytes_are_not_met()
        {
            var stream = new MockStream();

            using (var reader = new TrimmingTextReader(new StreamReader(stream, Encoding.ASCII))) {
                var buffer = new char[4000];
                var total  = 0;
                while (total < buffer.Length)
                {
                    var read = reader.Read(buffer, total, buffer.Length - total);
                    _log.DebugFormat("requested {0}, got {1}", buffer.Length - total, read);
                    Assert.IsTrue(read > 0);
                    total += read;
                }
            }
        }