public void WhenReplaceMultipleLines_ThenDeleteLines() { const string text = "Line1\n" + "\n" + "Line3\r\n" + "Line4\n" + "Line5\r\n" + "Line6"; const string expected = "Line1\n" + "New Line2\n" + "Line3\r\n" + "\n" + "\r\n" + "New Line6"; var sut = FileBuilder.InFileSystem.WithText(text).WithPath(GetAbsolutePath("ReplaceLines2.txt")).Build(); var result = sut.ReplaceLines(new Dictionary <int, string> { { 2, "New Line2" }, { 4, "" }, { 5, null }, { 6, "New Line6\n" } }, GetAbsolutePath("ReplaceLine2-Output.txt")); AssertFile.ContentEquals(result, expected); }
public void WhenNoFileExistsOnDisk_ThenSaveToDisk() { var sut = AssemblyEmbeddedResource.CreateFromAssemblyContaining <AssemblyEmbeddedResourceTests>(TestFileNames.ExistingEmbeddedFile); var fileInfo = sut.Save(GetWorkingPath(sut.FileName)); AssertFile.ContentEquals(fileInfo, "Embedded Resource 1"); }
public void WhenFileContentIsNotExpected_ThenAssertFalse() { const string content = "test1"; var file = BaseDir.CreateFile("ContentEquals-Test2.txt", content); Assert.Throws <AssertionException>(() => AssertFile.ContentEquals(file, content + "A")); }
public void WhenFileContentIsExpected_ThenAssertTrue() { const string content = "test1"; var file = BaseDir.CreateFile("ContentEquals-Test1.txt", content); Assert.DoesNotThrow(() => AssertFile.ContentEquals(file, content)); }
public void WhenFileHasThreeUnixLines_ThenReplaceLine() { const string text = "Line1\nLine2\nLine3"; var sut = FileBuilder.InFileSystem.WithText(text).WithPath(GetAbsolutePath("ReplaceLine2.txt")).Build(); var result = sut.ReplaceLine(2, "New Line2", GetAbsolutePath("ReplaceLine2-Output.txt")); AssertFile.ContentEquals(result, "Line1\nNew Line2\nLine3"); }
public void WhenLineToDeleteIsEmpty_ThenDeleteLine() { const string text = "Line1\n\nLine3"; var sut = FileBuilder.InFileSystem.WithText(text).WithPath(GetAbsolutePath("DeleteLine4.txt")).Build(); var result = sut.DeleteLine(2, GetAbsolutePath("DeleteLine4-Output.txt")); AssertFile.ContentEquals(result, "Line1\nLine3"); }
public void WhenNewLineAlreadyHasEndLineChars_ThenReplaceWithOriginalEndLineChars() { const string text = "Line1\r\nLine2\r\nLine3"; const string expected = "Line1\r\nNew Line2\r\nLine3"; var sut = FileBuilder.InFileSystem.WithText(text).WithPath(GetAbsolutePath("ReplaceLine4.txt")).Build(); var result = sut.ReplaceLine(2, "New Line2\n", GetAbsolutePath("ReplaceLine4-Output.txt")); AssertFile.ContentEquals(result, expected); }
public void WhenNoPagesToReplace_ThenOutputSameFile() { const string text = "Line1\n" + "\n" + "Line3\r\n" + "Line4\n" + "Line5"; var sut = FileBuilder.InFileSystem.WithText(text).WithPath(GetAbsolutePath("ReplaceLines1.txt")).Build(); var result = sut.ReplaceLines(new Dictionary <int, string>(), GetAbsolutePath("ReplaceLine1-Output.txt")); AssertFile.ContentEquals(result, text); }
public void WhenNoPagesToDelete_ThenOutputSameFile() { const string text = "Line1\n" + "\n" + "Line3\r\n" + "Line4\n" + "Line5"; var sut = FileBuilder.InFileSystem.WithText(text).WithPath(GetAbsolutePath("DeleteLines1.txt")).Build(); var result = sut.DeleteLines(new int[0], GetAbsolutePath("DeleteLine1-Output.txt")); AssertFile.ContentEquals(result, text); }
public void WhenFilesLastCharIsNotEndLineChar_ThenDeleteLastLine() { const string text = "Line1\n" + "Line2\n" + "Line3"; const string expected = "Line1\n" + "Line2\n"; var sut = FileBuilder.InFileSystem.WithText(text).WithPath(GetAbsolutePath("DeleteLastLine3.txt")).Build(); var result = sut.DeleteLastLine(GetAbsolutePath("DeleteLastLine3-Output.txt")); AssertFile.ContentEquals(result, expected); }
public void WhenDeleteMultipleLines_ThenDeleteLines() { const string text = "Line1\n" + "\n" + "Line3\r\n" + "Line4\n" + "Line5"; const string expected = "Line1\n" + "Line3\r\n"; var sut = FileBuilder.InFileSystem.WithText(text).WithPath(GetAbsolutePath("DeleteLines2.txt")).Build(); var result = sut.DeleteLines(new [] { 2, 4, 5 }, GetAbsolutePath("DeleteLine2-Output.txt")); AssertFile.ContentEquals(result, expected); }