예제 #1
0
        public void ShouldBeAbleToReadAllRecordsOfAStream()
        {
            Stream s = new MemoryStream();

            int recordsToCreateInStream = 1000;

            for (int x = 0; x < recordsToCreateInStream; x++)
            {
                AddRecordToStream(s, string.Format("{0}, {0}\n", x));
            }

            s.Position = 0;
            FileRecordReader reader  = new FileRecordReader(s, '\n', Encoding.Unicode);
            List <string>    records = new List <string>(recordsToCreateInStream);
            string           record  = reader.ReadNextRecord();

            while (record != null)
            {
                records.Add(record);
                record = reader.ReadNextRecord();
            }

            Assert.That(records.Count, Is.EqualTo(recordsToCreateInStream));
            for (int x = 0; x < recordsToCreateInStream; x++)
            {
                Assert.That(records[x], Is.EqualTo(string.Format("{0}, {0}", x)));
            }
        }
예제 #2
0
        public void ShouldBeAbleToReadFirstRecordOfAStream()
        {
            Stream s = new MemoryStream();

            string contents = "10, 12\r\n11, 14";

            byte[] streamContents = Encoding.Unicode.GetBytes(contents);
            s.Write(streamContents, 0, streamContents.Length);
            s.Position = 0;
            FileRecordReader reader = new FileRecordReader(s, '\n', Encoding.Unicode);

            string firstRecord = reader.ReadNextRecord();

            Assert.That(firstRecord, Is.Not.Null);
            Assert.That(firstRecord, Is.EqualTo("10, 12\r"));
        }
예제 #3
0
        public void ShouldBeAbleToReadLastRecordOfAStream()
        {
            Stream s = new MemoryStream();

            string contents = "10, 12\r\n11, 14";

            byte[] streamContents = Encoding.Unicode.GetBytes(contents);
            s.Write(streamContents, 0, streamContents.Length);
            s.Position = 0;
            FileRecordReader reader = new FileRecordReader(s, '\n', Encoding.Unicode);

            string firstRecord = reader.ReadNextRecord();

            Console.WriteLine(firstRecord);
            string secondRecord = reader.ReadNextRecord();

            Assert.IsNotNull(secondRecord);
            Assert.AreEqual(secondRecord, "11, 14");
            Console.WriteLine(secondRecord);
        }