public void CanWriteAFile()
 {
     using var executionContext = new TextFileWriterTestExecutionContext();
     executionContext.TextFileWriter.WriteAllLines(executionContext.TestFolder, executionContext.TestFileName, executionContext.Lines, Encoding.UTF8);
     Assert.IsTrue(File.Exists(executionContext.TestFolder.FullName + '\\' + executionContext.TestFileName));
     Assert.IsTrue(AreTheseFilesInTheTestFolder(executionContext, new List <string> {
         executionContext.TestFileName
     }));
     Assert.IsFalse(AreTheseFilesInTheTestFolder(executionContext, new List <string> {
         executionContext.TestFileName, executionContext.TestFileName
     }));
     Assert.IsFalse(AreTheseFilesInTheTestFolder(executionContext, new List <string> {
         "", executionContext.TestFileName
     }));
     Assert.IsTrue(executionContext.TextFileWriter.FileExistsAndIsIdentical(executionContext.TestFolder, executionContext.TestFileName, executionContext.Lines, Encoding.UTF8));
 }
 public void OverwriteFileWithNewContentsCreatesBackupFile()
 {
     using var executionContext = new TextFileWriterTestExecutionContext();
     executionContext.TextFileWriter.WriteAllLines(executionContext.TestFolder, executionContext.TestFileName, executionContext.Lines, Encoding.UTF8);
     Assert.IsTrue(AreTheseFilesInTheTestFolder(executionContext, new List <string> {
         executionContext.TestFileName
     }));
     Assert.IsTrue(executionContext.TextFileWriter.FileExistsAndIsIdentical(executionContext.TestFolder, executionContext.TestFileName, executionContext.Lines, Encoding.UTF8));
     Assert.IsFalse(executionContext.TextFileWriter.FileExistsAndIsIdentical(executionContext.TestFolder, executionContext.TestFileName, executionContext.ChangedLines, Encoding.UTF8));
     executionContext.TextFileWriter.WriteAllLines(executionContext.TestFolder, executionContext.TestFileName, executionContext.ChangedLines, Encoding.UTF8);
     Assert.IsTrue(AreTheseFilesInTheTestFolder(executionContext, new List <string> {
         executionContext.TestFileBackup1Name, executionContext.TestFileName
     }));
     Assert.IsTrue(executionContext.TextFileWriter.FileExistsAndIsIdentical(executionContext.TestFolder, executionContext.TestFileName, executionContext.ChangedLines, Encoding.UTF8));
     Assert.IsTrue(executionContext.TextFileWriter.FileExistsAndIsIdentical(executionContext.TestFolder, executionContext.TestFileBackup1Name, executionContext.Lines, Encoding.UTF8));
 }
        internal bool AreTheseFilesInTheTestFolder(TextFileWriterTestExecutionContext context, List <string> shortFileNames)
        {
            var existingFileNames = Directory.GetFiles(context.TestFolder.FullName, "*.*").OrderBy(x => x).ToList();

            return(existingFileNames.SequenceEqual(shortFileNames.Select(x => context.TestFolder.FullName + '\\' + x)));
        }