public void WriteTextTest2() { string fname = "test123.txt"; string filePath = Path.Combine(_testDirectory, fname); File target = new File(filePath); string line1 = "This is Line 1"; System.IO.File.Delete(filePath); target.WriteText(line1, false, Encoding.UTF8); string[] fileLines = System.IO.File.ReadAllLines(filePath); if (fileLines == null) { Assert.Fail("Could not retrieve text file lines"); } else if (fileLines.Length != 1) { Assert.Fail("Expecting one line"); } else if (fileLines[0] != line1) { Assert.Fail("Read 1st line not equal to expected line"); } else { // ok now append line string[] lines = new string[2]; string line2 = "This is second line"; target.WriteText(line2, true, Encoding.UTF8); // should put this on 1st line/ fileLines = System.IO.File.ReadAllLines(filePath); lines[0] = line1; lines[1] = line2; //int i = 0; Assert.IsNotNull(fileLines, "Could not retrieve file lines"); Assert.AreEqual(1, fileLines.Length, "Should only be 1 line"); string linecomb = line1 + line2; Assert.AreEqual(linecomb, fileLines[0], "Should be one 1 line"); /* * foreach(string s in fileLines) * { * * Assert.AreEqual(lines[i],s,string.Format("Line {0} not equal",i)); * i++; * } * */ } }
public void LastChangedDateTest() { File file = new File(Path.Combine(_testDirectory, "TestLastChangedDate.Txt")); file.WriteText("testing"); DateTime time1 = new FileInfo(file.Path).LastWriteTime; Thread.Sleep(100); file.WriteText("more text"); DateTime time2 = new FileInfo(file.Path).LastWriteTime; Assert.AreNotEqual(time1, time2, "File modified datetimes should be different."); }
public void WriteTextTest() { string fname = "test123.txt"; string filePath = Path.Combine(_testDirectory, fname); File target = new File(filePath); string line1 = "This is Line 1"; System.IO.File.Delete(filePath); bool appendText = false; target.WriteText(line1, appendText); target.WriteText(line1, true); string combLine = line1 + line1; string linein = System.IO.File.ReadAllText(filePath); Assert.AreEqual(combLine, linein, "Lines should be equal"); }
public void WriteTextTest1() { string fname = "test123.txt"; string filePath = Path.Combine(_testDirectory, fname); File target = new File(filePath); string line1 = "This is Line 1"; System.IO.File.Delete(filePath); target.WriteText(line1); string linein = System.IO.File.ReadAllText(filePath); Assert.AreEqual(line1, linein, "Lines should be equal"); string line2 = "This is line 2"; target.WriteText(line2); // should not append linein = System.IO.File.ReadAllText(filePath); Assert.AreEqual(line2, linein, "Lines should be equal"); }