Ejemplo n.º 1
0
        public void ReadFileContent()
        {
            string fileContent = "12345";
            string path        = $"{nameof(ReadFileContent)}.txt";

            File.WriteAllText(path, fileContent);

            using (var fr = new TextFileScanner(path)) {
                for (int i = 0; i < fileContent.Length; i++)
                {
                    char c = fr.Read();
                    Assert.AreEqual(c, fileContent[i]);
                }
                // Two extra reads for the ending /r/n
                fr.Read();
                fr.Read();
                Assert.IsFalse(fr.CanRead);
            }
            File.Delete(path);
        }
Ejemplo n.º 2
0
        public void GoToStart()
        {
            string fileContent = "12345";
            string path        = $"{nameof(GoToStart)}.txt";

            File.WriteAllText(path, fileContent);

            using (var fr = new TextFileScanner(path)) {
                while (fr.CanRead)
                {
                    fr.Read();
                }

                fr.GoToStart();
                Assert.IsTrue(fr.CanRead);
            }
            File.Delete(path);
        }
Ejemplo n.º 3
0
        public void ReadMultiLine()
        {
            string fileContent = @"1
2
3
4";
            string path        = $"{nameof(ReadMultiLine)}.txt";

            File.WriteAllText(path, fileContent);

            int count = 0;

            using (var fr = new TextFileScanner(path)) {
                while (fr.CanRead)
                {
                    fr.Read();
                    count++;
                }
            }
            File.Delete(path);
            // + 2 to account for the last \r\n
            Assert.AreEqual(fileContent.Length + 2, count);
        }