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"))); }
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); } }
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)); }
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"))); }