Esempio n. 1
0
        public void ShouldRestoreOverwrittenFileOnBeginRollback()
        {
            String destinationFilePath = null;
            String overwrittenFilePath = null;
            FileCopyPlugin plugin = null;

            try
            {
                var fileContent = Guid.NewGuid().ToString();

                overwrittenFilePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
                File.WriteAllText(overwrittenFilePath, fileContent);

                destinationFilePath = Path.GetTempFileName();
                plugin = new FileCopyPlugin();
                plugin.RollbackLevel = RollbackLevels.FINAL_LEVEL;
                plugin.RollbackFailed +=
                    delegate(object sender, ObjectErrorEventArgs<IPlugin> e) { throw e.Exception; };

                plugin.DestinationFilePath = destinationFilePath;
                plugin.ShouldOwerwriteExistingFile = true;
                plugin.TemporaryFilePath = overwrittenFilePath;

                plugin.BeginRollback();

                Assert.That(File.Exists(destinationFilePath));
                Assert.AreEqual(fileContent, File.ReadAllText(destinationFilePath));
            }
            finally
            {
                if (File.Exists(destinationFilePath))
                    File.Delete(destinationFilePath);
                if (File.Exists(overwrittenFilePath))
                    File.Delete(overwrittenFilePath);
            }
        }
Esempio n. 2
0
        public void ShouldFailWithFileNotFoundExceptionWhenOverwritedTemporaryFilePathDoesNotExistOnBeginRollback()
        {
            String destinationFilePath = null;
            String overwrittenFilePath = null;
            FileCopyPlugin plugin = null;

            try
            {
                overwrittenFilePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

                destinationFilePath = Path.GetTempFileName();
                plugin = new FileCopyPlugin();
                plugin.RollbackLevel = RollbackLevels.FINAL_LEVEL;
                plugin.RollbackFailed +=
                    delegate(object sender, ObjectErrorEventArgs<IPlugin> e) { throw e.Exception; };

                plugin.DestinationFilePath = destinationFilePath;
                plugin.ShouldOwerwriteExistingFile = true;
                plugin.TemporaryFilePath = overwrittenFilePath;

                plugin.BeginRollback();
            }
            finally
            {
                if (File.Exists(destinationFilePath))
                    File.Delete(destinationFilePath);
            }
        }