Exemplo n.º 1
0
 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));
 }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        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());
            }
        }