Esempio n. 1
0
        public void MoveToDirectoryTest()
        {
            File   file = new File(Path.GetTempFileName());
            string filepathBeforeMove = file.Path;
            string filename           = Path.GetFileName(filepathBeforeMove);

            string    destinationDirName = "testdir";
            Directory destinationDir     = new Directory(Path.Combine(_testDirectory, destinationDirName));

            if (destinationDir.Exists)
            {
                System.IO.Directory.Delete(destinationDir.Path, true);
            }
            System.IO.Directory.CreateDirectory(destinationDir.Path);
            string destinationDirPath = destinationDir.Path;

            if (destinationDirPath.EndsWith(Path.DirectorySeparatorChar.ToString()))
            {
                destinationDirPath = destinationDirPath.Remove(destinationDirPath.Length - 1, 1);
            }

            file.MoveToDirectory(destinationDir);

            Assert.AreEqual(1,
                            System.IO.Directory.GetFiles(destinationDir.Path)
                            .Count(x => Path.GetFileName(x) == filename),
                            "File should have been relocated.");
            Assert.AreEqual(destinationDirPath,
                            Path.GetDirectoryName(file.Path),
                            "File should have updated its location.");
            Assert.IsFalse(System.IO.File.Exists(filepathBeforeMove), "File should not exist at original location.");
        }
Esempio n. 2
0
        public void FileConstructorTest()
        {
            string    fname           = "test123.txt";
            string    filePath        = Path.Combine(_testDirectory, fname);
            Directory parentDirectory = new Directory(Path.GetDirectoryName(filePath));

            File target = new File(parentDirectory, fname);

            Assert.AreEqual(filePath, target.Path, "Expected same filepath");
        }