Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,26 @@ public void MockFileInfo_AppendText_ShouldAddTextToFileInMemoryFileSystem()
Assert.AreEqual($"Demo text contentThis should be at the end{Environment.NewLine}", newcontents);
}

[Test]
public void MockFileInfo_AppendText_ShouldCreateFileIfMissing()
{
var fileSystem = new MockFileSystem();
var targetFile = XFS.Path(@"c:\a.txt");
var fileInfo = new MockFileInfo(fileSystem, targetFile);

using (var file = fileInfo.AppendText())
file.WriteLine("This should be the contents");

string newcontents;
using (var newfile = fileInfo.OpenText())
{
newcontents = newfile.ReadToEnd();
}

Assert.That(fileSystem.File.Exists(targetFile), Is.True);
Assert.AreEqual($"This should be the contents{Environment.NewLine}", newcontents);
}

[Test]
public void MockFileInfo_OpenWrite_ShouldAddDataToFileInMemoryFileSystem()
{
Expand Down
1 change: 0 additions & 1 deletion System.IO.Abstractions.TestingHelpers/MockFileInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ public override string Name

public override StreamWriter AppendText()
{
if (MockFileData == null) throw CommonExceptions.FileNotFound(path);
return new StreamWriter(new MockFileStream(mockFileSystem, FullName, MockFileStream.StreamType.APPEND));
}

Expand Down