public void CanReadAllLines() { string test_file_name = ".\\FileContainerTests_11.txt"; if (File.Exists(test_file_name)) { File.Delete(test_file_name); } File.WriteAllLines(test_file_name, new List <string>() { "Hello", "World" }); var file_container = new FileContainer(test_file_name); var result = file_container.ReadAllLines(); Assert.That(result.Count, Is.EqualTo(2)); Assert.That(result[0], Is.EqualTo("Hello")); Assert.That(result[1], Is.EqualTo("World")); if (File.Exists(test_file_name)) { File.Delete(test_file_name); } }
public void WillCreateIfMissing() { string test_file_name = ".\\FileContainerTests_15.txt"; if (File.Exists(test_file_name)) { File.Delete(test_file_name); } var file_container = new FileContainer(test_file_name, true); var result = file_container.ReadAllLines(); Assert.That(result.Count, Is.EqualTo(0)); file_container.WriteAllLines(new List <string>() { "Hello", "World" }); Assert.That(File.Exists(test_file_name)); if (File.Exists(test_file_name)) { File.Delete(test_file_name); } }
public void WillFailIfFileIsMissingWhenReading() { string test_file_name = ".\\FileContainerTests_13.txt"; if (File.Exists(test_file_name)) { File.Delete(test_file_name); } var file_container = new FileContainer(test_file_name); Assert.Throws <Exception>(() => file_container.ReadAllLines()); }