public void ShouldCopyFileOnBeginExecute() { String sourceFilePath = null; String destinationFilePath = null; FileCopyPlugin plugin = null; try { var fileContent = Guid.NewGuid().ToString(); sourceFilePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); File.WriteAllText(sourceFilePath, fileContent); destinationFilePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); plugin = new FileCopyPlugin(); plugin.ExecuteFailed += delegate(object sender, ObjectErrorEventArgs<IPlugin> e) { throw e.Exception; }; plugin.SourceFilePath = sourceFilePath; plugin.DestinationFilePath = destinationFilePath; plugin.BeginExecute(); Assert.That(File.Exists(destinationFilePath)); Assert.AreEqual(fileContent, File.ReadAllText(destinationFilePath)); } finally { if (File.Exists(sourceFilePath)) File.Delete(sourceFilePath); if (File.Exists(destinationFilePath)) File.Delete(destinationFilePath); } }
public void ShouldFailWithPropertyNotSetBeforeOperationExceptionWhenSourceFilePathNotSetBeforeBeginExecute() { var plugin = new FileCopyPlugin(); plugin.ExecuteFailed += delegate(object sender, ObjectErrorEventArgs<IPlugin> e) { throw e.Exception; }; plugin.DestinationFilePath = Path.GetRandomFileName(); plugin.BeginExecute(); }
public void ShouldFailWithPropertyNotSetBeforeOperationExceptionWhenNoPropertiesSetBeforeBeginExecute() { var plugin = new FileCopyPlugin(); plugin.ExecuteFailed += delegate(object sender, ObjectErrorEventArgs<IPlugin> e) { throw e.Exception; }; plugin.BeginExecute(); }
public void ShouldFailWithFileNotFoundExceptionWhenSourceFileDoesNotExistsBeforeBeginExecute() { String sourceFilePath = null; String destinationFilePath = null; var plugin = new FileCopyPlugin(); plugin.ExecuteFailed += delegate(object sender, ObjectErrorEventArgs<IPlugin> e) { throw e.Exception; }; while (sourceFilePath == null || File.Exists(sourceFilePath)) sourceFilePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); while (destinationFilePath == null || File.Exists(destinationFilePath)) destinationFilePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); plugin.SourceFilePath = sourceFilePath; plugin.DestinationFilePath = destinationFilePath; plugin.BeginExecute(); }
public void ShouldFailWithFileAlreadyExistExceptionWhenDestinationFileAlreadyExistsBeforeBeginExecute() { String sourceFilePath = null; String destinationFilePath = null; FileCopyPlugin plugin = null; try { sourceFilePath = Path.GetTempFileName(); destinationFilePath = Path.GetTempFileName(); plugin = new FileCopyPlugin(); plugin.ExecuteFailed += delegate(object sender, ObjectErrorEventArgs<IPlugin> e) { throw e.Exception; }; plugin.SourceFilePath = sourceFilePath; plugin.DestinationFilePath = destinationFilePath; plugin.BeginExecute(); } finally { if (File.Exists(sourceFilePath)) File.Delete(sourceFilePath); if (File.Exists(destinationFilePath)) File.Delete(destinationFilePath); } }
public void ShouldFailWithDirectoryNotFoundExceptionWhenDestinationDirectoryDoesNotExistsBeforeBeginExecute() { String sourceFilePath = null; String destinationFilePath = null; FileCopyPlugin plugin = null; try { sourceFilePath = Path.GetTempFileName(); destinationFilePath = Path.Combine(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()), Path.GetRandomFileName()); plugin = new FileCopyPlugin(); plugin.ExecuteFailed += delegate(object sender, ObjectErrorEventArgs<IPlugin> e) { throw e.Exception; }; plugin.SourceFilePath = sourceFilePath; plugin.DestinationFilePath = destinationFilePath; plugin.BeginExecute(); } finally { if (File.Exists(sourceFilePath)) File.Delete(sourceFilePath); if (File.Exists(destinationFilePath)) File.Delete(destinationFilePath); } }