Exemplo n.º 1
0
        public void ReadContentFilesTest()
        {
            DirectoryInfo di = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "NReco_LocalFileManagerTest"));
            DirectoryInfo subDi = Directory.CreateDirectory(Path.Combine(di.FullName, "subfolder_NReco_LocalFileManagerTest"));
            string testFilePath = Path.Combine(di.FullName, "file2.txt");
            string testSubFolderFilePath = Path.Combine(subDi.FullName, "file3.txt");
            string testContentText = "This is a text write by using class LocalFileManager!";
            string testSubFolderFileContent = "This is a content secondery file!";
            int contentLength = testContentText.Length + testSubFolderFileContent.Length;

            using (FileStream fs = File.Create(testFilePath))
            {
                AddText(fs, testContentText);
                fs.Flush();
                fs.Close();
            }
            using (FileStream fs = File.Create(testSubFolderFilePath))
            {
                AddText(fs, testSubFolderFileContent);
                fs.Flush();
                fs.Close();
            }

            try {
                LocalFileManager localFileManager = new LocalFileManager();

                localFileManager.RootPath = di.FullName;
                Assert.AreEqual(contentLength, localFileManager.Read("**.txt").Length);
            } finally {
                File.Delete(testSubFolderFilePath);
                Directory.Delete(subDi.FullName);
                File.Delete(testFilePath);
                Directory.Delete(di.FullName);
            }
        }
Exemplo n.º 2
0
        public void ReadContentFileTest()
        {
            DirectoryInfo di = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "NReco_LocalFileManagerTest"));
            string testDir = di.FullName;
            string testFilePath = Path.Combine(testDir, "file1.txt");
            string test_text = "This is a NUnit test for LocalFileManager class!";
            using (FileStream fs = File.Create(testFilePath))
            {
                AddText(fs, test_text);
                fs.Flush();
                fs.Close();
            }
            try {
                LocalFileManager localFileManager = new LocalFileManager();

                localFileManager.RootPath = di.FullName;

                Assert.AreEqual(test_text, localFileManager.Read(testFilePath));
                Assert.AreNotEqual("This is a wrong text! ", localFileManager.Read(testFilePath));
            } finally {
                File.Delete(testFilePath);
                Directory.Delete(testDir);
            }
        }
Exemplo n.º 3
0
        public void WriteContentToFileTest()
        {
            DirectoryInfo di = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "NReco_LocalFileManagerTest"));
            string testDir = di.FullName;
            string testFilePath = Path.Combine(testDir, "file2.txt");
            string testContentText = "This is a text write by using class LocalFileManager!";

            LocalFileManager localFileManager = new LocalFileManager();
            localFileManager.Write(testFilePath, testContentText);

            try {
                string readText = File.ReadAllText(testFilePath);

                Assert.AreEqual(testContentText, readText);
                Assert.AreEqual(testContentText, localFileManager.Read(testFilePath));
            } finally {
                File.Delete(testFilePath);
                Directory.Delete(testDir);
            }
        }