public void TestIsFullPath() { string tmpname = Guid.NewGuid().ToString(); Assert.IsFalse(File.Exists(tmpname)); using (ReplaceFile f = new ReplaceFile(tmpname)) { Assert.IsTrue(Path.IsPathRooted(f.TargetFile)); Assert.AreEqual(Environment.CurrentDirectory, Path.GetDirectoryName(f.TargetFile)); } Assert.IsFalse(File.Exists(tmpname)); using (TransactFile f = new TransactFile(tmpname)) { Assert.IsTrue(Path.IsPathRooted(f.TargetFile)); Assert.AreEqual(Environment.CurrentDirectory, Path.GetDirectoryName(f.TargetFile)); } Assert.IsFalse(File.Exists(tmpname)); }
public void TestTransactRollback() { string testdata = Guid.NewGuid().ToString(); using (TempFile replace = new TempFile()) using (TransactFile temp = new TransactFile(replace.TempPath)) { temp.WriteAllText(testdata); Assert.IsTrue(temp.Exists); temp.Rollback(); Assert.IsFalse(temp.Exists); } }
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()); } }