Example #1
0
        public void FileExistsReturnsFalseIfFileIsNotPresentOnDisk()
        {
            // Arrange
            PhysicalFileSystem fs = new PhysicalFileSystem(testRoot);

            // Act/Assert
            Assert.False(fs.FileExists("testExists.txt"));
        }
Example #2
0
        public void DeleteFileSilentlyFailsForNonExistantFile()
        {
            // Arrange
            PhysicalFileSystem fs = new PhysicalFileSystem(testRoot);

            // Act
            fs.DeleteFile("testDeleteNonExistant.txt");

            // Assert
            Assert.False(File.Exists(ResolveTestFile("testDeleteNonExistant.txt")));
        }
Example #3
0
        public void DeleteFileDeletesPhysicalFileIfExists()
        {
            // Arrange
            PhysicalFileSystem fs = new PhysicalFileSystem(testRoot);
            WriteTestFile("testDelete.txt");

            // Act
            fs.DeleteFile("testDelete.txt");

            // Assert
            Assert.False(File.Exists(ResolveTestFile("testDelete.txt")));
        }
Example #4
0
        public void GetFilePathReturnsCombinedPathEvenIfFileDoesNotExist()
        {
            // Arrange
            PhysicalFileSystem fs = new PhysicalFileSystem(testRoot);

            // Act
            string actual = fs.GetFullPath(@"tests\testGetFullPath.txt");

            // Assert
            Assert.Equal(Path.Combine(testRoot, @"tests\testGetFullPath.txt"), actual);
        }
Example #5
0
        public void FileExistsReturnsTrueIfFileIsPresentOnDisk()
        {
            // Arrange
            PhysicalFileSystem fs = new PhysicalFileSystem(testRoot);
            WriteTestFile("testExists.txt");

            // Act/Assert
            Assert.True(fs.FileExists("testExists.txt"));
        }
Example #6
0
        public void OpenFileReturnsWriteableStreamPositionedAtFileStart()
        {
            // Arrange
            PhysicalFileSystem fs = new PhysicalFileSystem(testRoot);
            WriteTestFile("testOpenWrite.txt", "Foo Bar Baz");

            // Act
            using (Stream strm = fs.OpenFile("testOpenWrite.txt"))
            {
                using (StreamWriter writer = new StreamWriter(strm))
                {
                    writer.Write("Quz");
                }
            }

            // Assert
            Assert.Equal("Quz Bar Baz", File.ReadAllText(ResolveTestFile("testOpenWrite.txt")));
        }
Example #7
0
        public void OpenFileReturnsStreamContainingAllFileData()
        {
            // Arrange
            PhysicalFileSystem fs = new PhysicalFileSystem(testRoot);
            WriteTestFile("testOpenRead.txt", "Foo Bar Baz");

            // Act
            Stream strm = fs.OpenFile("testOpenRead.txt");

            // Assert
            Assert.Equal("Foo Bar Baz", GetContent(strm));
        }
Example #8
0
        public void OpenFileLocksFileForAllAccess()
        {
            // Arrange
            PhysicalFileSystem fs = new PhysicalFileSystem(testRoot);
            WriteTestFile("testLock.txt", "Foo Bar Baz");

            // Act
            using (Stream strm = fs.OpenFile("testLock.txt"))
            {
                // Assert
                IOException ex = Assert.Throws<IOException>(() => fs.OpenFile("testLock.txt"));
                Assert.Equal(String.Format("The process cannot access the file '{0}' because it is being used by another process.", ResolveTestFile("testLock.txt")), ex.Message);
            }
        }
Example #9
0
        public void OpenFileCreatesParentDirectoryTreeIfNecessary()
        {
            // Arrange
            PhysicalFileSystem fs = new PhysicalFileSystem(testRoot);

            // Act
            using (Stream strm = fs.OpenFile(@"testParent\folder\testOpenWrite.txt")) { }

            // Assert
            Assert.True(Directory.Exists(ResolveTestFile(@"testParent\folder")));
        }