public static async Task AppendText(this IFileInfo fileInfo, string text) { using (var writer = fileInfo.AppendText()) { await writer.WriteAsync(text); } }
public static IFileInfo CreateSteamAppIdFile(IFileSystem fileSystem) { IFileInfo steamAppIdFile = fileSystem.FileInfo.FromFileName("steam_appid.txt"); StreamWriter streamWriter = steamAppIdFile.AppendText(); streamWriter.WriteLine("32470"); streamWriter.Close(); return(steamAppIdFile); }
private void When_appending_to_file_as_text_it_must_succeed() { // Arrange const string path = @"C:\some\file.txt"; IFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingTextFile(path, DefaultContents) .Build(); IFileInfo info = fileSystem.ConstructFileInfo(path); // Act using (StreamWriter writer = info.AppendText()) { // Assert writer.BaseStream.CanRead.Should().BeFalse(); writer.BaseStream.CanWrite.Should().BeTrue(); } }