Exemplo n.º 1
0
        public void CopyFile_FromFileIsDirectoryThrowsArgumentException()
        {
            // Arrange
            var fs = new MockFileSystem();
            fs.CreateDirectory("c:\\old");
            const string oldFilePath = "c:\\old";
            //long oldSize = 100;
            const string newFilePath = "c:\\new\\file2.txt";
            //long newSize = 300;

            // Act
            fs.CopyFile(oldFilePath, newFilePath);

            // Assert
            Assert.Fail();
        }
Exemplo n.º 2
0
        public void CopyFileLeavesOldFile()
        {
            // Arrange
            var fs = new MockFileSystem();
            const string oldFilePath = "c:\\old\\file1.txt";
            const long oldSize = 100;
            const string newFilePath = "c:\\new\\file2.txt";
            fs.AddFile(oldFilePath, oldSize);
            fs.CreateDirectory("c:\\new");

            // Act
            fs.CopyFile(oldFilePath, newFilePath);

            // Assert
            Assert.IsTrue(fs.FileExists(oldFilePath));
            Assert.AreEqual(oldSize, fs.GetFileLength(oldFilePath));
        }
Exemplo n.º 3
0
        public void CopyFileToExistingFileThrowsIoException()
        {
            // Arrange
            var fs = new MockFileSystem();
            const string oldFilePath = "c:\\old\\file1.txt";
            const long oldSize = 100;
            const string newFilePath = "c:\\new\\file2.txt";
            const long newSize = 300;
            fs.AddFile(oldFilePath, oldSize);
            fs.AddFile(newFilePath, newSize);

            // Act
            fs.CopyFile(oldFilePath, newFilePath);

            // Assert
            Assert.Fail();
        }
Exemplo n.º 4
0
        public void FileDelete_OnDirectoryThrowsUnauthorizedAccessException()
        {
            // Arrange
            var fs = new MockFileSystem();
            const string fileName = "c:\\test\\";
            fs.CreateDirectory(fileName);

            // Act
            fs.DeleteFile(fileName);

            // Assert
            Assert.Fail();
        }
Exemplo n.º 5
0
        public void FileDelete_DeletingNonExistantFileDoesNotFail()
        {
            // Arrange
            var fs = new MockFileSystem();
            const string fileName = "c:\\test\\Horker.txt";

            // Act
            fs.DeleteFile(fileName);

            // Assert
        }
Exemplo n.º 6
0
        public void DirectoryExistsReturnsTrueForExistingDirectoryWithTrailingSlash()
        {
            // Arrange
            var fs = new MockFileSystem();
            const string newdir = "newdir";
            fs.CreateDirectory(newdir);

            // Act
            bool result = fs.DirectoryExists(newdir + "\\");

            // Assert
            Assert.IsTrue(result);
        }
Exemplo n.º 7
0
        public void DirectoryExistsReturnsTrueForExistingDirectory()
        {
            // Arrange
            var fs = new MockFileSystem();
            const string newdir = "newdir";
            fs.CreateDirectory(newdir);

            // Act

            // Assert
            Assert.IsTrue(fs.DirectoryExists(newdir));
        }
Exemplo n.º 8
0
        public void DirectoryExistsReturnsFalseForNonexistingDirectory()
        {
            // Arrange
            var fs = new MockFileSystem();

            // Act
            bool result = fs.DirectoryExists("doesnotexist");

            // Assert
            Assert.IsFalse(result);
        }
Exemplo n.º 9
0
        public void CreateDirectoryFromCurrent()
        {
            // Arrange
            var fs = new MockFileSystem();

            // Act
            fs.CreateDirectory("test");

            // Assert
            Assert.IsTrue(fs.DirectoryExists("c:\\test"));
        }
Exemplo n.º 10
0
        public void InstantiateMockFileSystem()
        {
            // Arrange

            // Act
            var fs = new MockFileSystem();

            // Assert
            Assert.IsNotNull(fs);
        }
Exemplo n.º 11
0
        public void DeleteDirectory_RemovesEmptyDirectory()
        {
            // Arrange
            var fs = new MockFileSystem();
            const string dirName = "c:\\test";
            fs.CreateDirectory(dirName);

            // Act
            fs.DeleteDirectory(dirName);

            // Assert
            Assert.IsFalse(fs.DirectoryExists(dirName));
        }
Exemplo n.º 12
0
        public void DeleteDirectory_RemoveNonEmptyDirectoryThrowsIoException()
        {
            // Arrange
            var fs = new MockFileSystem();
            string dirName = "c:\\test";
            fs.CreateDirectory(dirName);
            fs.AddFile(dirName + "\\file1.txt", 100);

            // Act
            fs.DeleteDirectory(dirName);

            // Assert
            Assert.Fail();
        }
Exemplo n.º 13
0
        public void CreateSimpleDirectoryAfterInstantiate()
        {
            // Arrange
            var fs = new MockFileSystem();
            const string newdir = "newdir";

            // Act
            fs.CreateDirectory(newdir);

            // Assert
            Assert.IsTrue(fs.DirectoryExists(newdir));
        }
Exemplo n.º 14
0
        public void CreateNestedFileFromCurrentDirectory()
        {
            // Arrange
            var fs = new MockFileSystem();

            // Act
            fs.AddFile("test\\test2\\testFile.txt", 352);

            // Assert
            Assert.IsTrue(fs.FileExists("c:\\test\\test2\\testFile.txt"));
        }
Exemplo n.º 15
0
        public void CreateNestedDirectoryFromCurrentWithTrailingSlash()
        {
            // Arrange
            var fs = new MockFileSystem();

            // Act
            fs.CreateDirectory("test\\test2\\");

            // Assert
            Assert.IsTrue(fs.DirectoryExists("c:\\test\\test2"));
        }
Exemplo n.º 16
0
        public void CreateFileFromAbsolute()
        {
            // Arrange
            var fs = new MockFileSystem();

            // Act
            fs.AddFile("c:\\testFile.txt", 352);

            // Assert
            Assert.IsTrue(fs.FileExists("c:\\testFile.txt"));
        }
Exemplo n.º 17
0
        public void CreateExistingDirectoryThrowsIoException()
        {
            // Arrange
            var fs = new MockFileSystem();
            fs.CreateDirectory("test");

            // Act
            fs.CreateDirectory("test");

            // Assert
            Assert.Fail();
        }
Exemplo n.º 18
0
        public void FileDelete_RemovesFile()
        {
            // Arrange
            var fs = new MockFileSystem();
            const string fileName = "c:\\test\\file1.txt";
            fs.AddFile(fileName, 255);

            // Act
            fs.DeleteFile(fileName);

            // Assert
            Assert.IsFalse(fs.FileExists(fileName));
        }
Exemplo n.º 19
0
        public void GetFileSizeReturnsCorrectValue()
        {
            // Arrange
            var fs = new MockFileSystem();
            const int size = 352;
            const string file = "c:\\testFile.txt";
            fs.AddFile(file, size);

            // Act
            long value = fs.GetFileLength(file);

            // Assert
            Assert.AreEqual(size, value);
        }
Exemplo n.º 20
0
        public void CopyFile_ToFileIsNullThrowsArgumentNullException()
        {
            // Arrange
            var fs = new MockFileSystem();
            fs.CreateDirectory("c:\\new");
            const string oldFilePath = "c:\\old\\file1.txt";
            const long oldSize = 100;
            fs.AddFile(oldFilePath, oldSize);

            // Act
            fs.CopyFile(oldFilePath, null);

            // Assert
            Assert.Fail();
        }
Exemplo n.º 21
0
        public void InstantiateMockFileSystemHasValidCurrentDirectorySet()
        {
            // Arrange

            // Act
            var fs = new MockFileSystem();

            // Assert
            Assert.IsNotNull(fs.GetCurrentDirectory());
            Assert.IsTrue(fs.GetCurrentDirectory().Length >= 3);
            Assert.IsTrue(Regex.IsMatch(fs.GetCurrentDirectory(), "[A-Za-z]:\\.*", RegexOptions.IgnoreCase));
        }
Exemplo n.º 22
0
        public void CreateAbsoluteDirectoryFromExistingDriveWithTrailingSlash()
        {
            // Arrange
            var fs = new MockFileSystem();

            // Act
            fs.CreateDirectory("c:\\test\\");

            // Assert
            Assert.IsTrue(fs.DirectoryExists("c:\\test"));
        }
Exemplo n.º 23
0
        public void DirectoryExistsIsCaseInsensitive()
        {
            // Arrange
            var fs = new MockFileSystem();
            fs.CreateDirectory("test\\test2");

            // Act

            // Assert
            Assert.IsTrue(fs.DirectoryExists("C:\\TEST\\test2"));
        }
Exemplo n.º 24
0
        public void CopyFile_NonExistantFromFileThrowsFileNotFoundException()
        {
            // Arrange
            var fs = new MockFileSystem();
            const string oldFilePath = "c:\\old\\file1.txt";
            //long oldSize = 100;
            const string newFilePath = "c:\\new\\file2.txt";
            //long newSize = 300;

            // Act
            fs.CopyFile(oldFilePath, newFilePath);

            // Assert
            Assert.Fail();
        }