예제 #1
0
        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);
            }
        }
예제 #2
0
        public void ShouldFailWithPropertyNotSetBeforeOperationExceptionWhenSourceFilePathNotSetBeforeBeginExecute()
        {
            var plugin = new FileCopyPlugin();
            plugin.ExecuteFailed +=
                delegate(object sender, ObjectErrorEventArgs<IPlugin> e) { throw e.Exception; };

            plugin.DestinationFilePath = Path.GetRandomFileName();

            plugin.BeginExecute();
        }
예제 #3
0
        public void ShouldFailWithPropertyNotSetBeforeOperationExceptionWhenNoPropertiesSetBeforeBeginExecute()
        {
            var plugin = new FileCopyPlugin();
            plugin.ExecuteFailed +=
                delegate(object sender, ObjectErrorEventArgs<IPlugin> e) { throw e.Exception; };

            plugin.BeginExecute();
        }
예제 #4
0
        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();
        }
예제 #5
0
        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);
            }
        }
예제 #6
0
        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);
            }
        }