public void TestReadWrite() { string test = "Hello World!\u1255"; TempFile file = new TempFile(); File.WriteAllBytes(file.TempPath, Encoding.UTF8.GetBytes(test)); Assert.AreEqual(Encoding.UTF8.GetBytes(test), file.ReadAllBytes()); Assert.AreEqual(test, file.ReadAllText()); file.Delete(); Assert.IsFalse(File.Exists(file.TempPath)); Assert.IsFalse(file.Exists); file.WriteAllBytes(Encoding.UTF8.GetBytes(test)); Assert.AreEqual(test, file.ReadAllText()); file.Delete(); Assert.IsFalse(File.Exists(file.TempPath)); Assert.IsFalse(file.Exists); file.WriteAllText(test); Assert.AreEqual(test, file.ReadAllText()); }
public void TestReplaceFiles() { string testdata = Guid.NewGuid().ToString(); string tmpPath; TempFile replace = new TempFile(); using (ReplaceFile temp = new ReplaceFile(replace.TempPath)) { Assert.AreEqual(temp.TargetFile, replace.TempPath); tmpPath = temp.TempPath; Assert.IsTrue(temp.Exists); temp.WriteAllText(testdata); //missing commit: //temp.Commit(); } Assert.AreEqual(0, replace.Length); Assert.IsFalse(File.Exists(tmpPath)); string backupfile = Path.ChangeExtension(replace.TempPath, ".bak"); File.Delete(Path.ChangeExtension(replace.TempPath, ".bak")); Assert.IsFalse(File.Exists(backupfile)); replace.WriteAllText("backup"); //now for real using (ReplaceFile temp = new ReplaceFile(replace.TempPath, ".bak")) { tmpPath = temp.TempPath; Assert.IsTrue(temp.Exists); temp.WriteAllText(testdata); temp.Commit(); } Assert.IsFalse(File.Exists(tmpPath)); Assert.AreEqual(testdata, replace.ReadAllText()); Assert.IsTrue(File.Exists(backupfile)); using (TempFile fbackup = TempFile.Attach(backupfile)) Assert.AreEqual("backup", fbackup.ReadAllText()); }
public void TestParseDocument() { XmlLightDocument doc = new HtmlLightDocument(document); XmlLightDocument doc2; using (TempFile t = new TempFile()) { using (TextWriter tw = new StreamWriter(t.Open())) doc.WriteXml(tw); new XhtmlValidation(XhtmlDTDSpecification.XhtmlTransitional_10).Validate(t.TempPath); doc2 = new XmlLightDocument(t.ReadAllText()); Assert.AreEqual(doc.InnerXml, doc2.InnerXml); } }
public void TestTransactFiles() { string testdata = Guid.NewGuid().ToString(); string tmpPath; using (TempFile replace = new TempFile()) { using (TransactFile temp = new TransactFile(replace.TempPath)) { Assert.AreEqual(temp.TargetFile, replace.TempPath); tmpPath = temp.TempPath; Assert.IsTrue(temp.Exists); temp.WriteAllText(testdata); //missing commit: //temp.Commit(); } Assert.AreEqual(0, replace.Length); Assert.IsFalse(File.Exists(tmpPath)); //now for real using (TransactFile temp = new TransactFile(replace.TempPath)) { tmpPath = temp.TempPath; Assert.IsTrue(temp.Exists); temp.WriteAllText(testdata); temp.Commit(); } Assert.IsFalse(File.Exists(tmpPath)); Assert.AreEqual(testdata, replace.ReadAllText()); } }