示例#1
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();
        }
示例#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));
        }
示例#3
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);
        }
示例#4
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));
        }
示例#5
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();
        }
示例#6
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"));
        }
示例#7
0
        public void CreateFileFromAbsolute()
        {
            // Arrange
            var fs = new MockFileSystem();

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

            // Assert
            Assert.IsTrue(fs.FileExists("c:\\testFile.txt"));
        }
示例#8
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();
        }