Exemplo n.º 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);
            }
        }
Exemplo n.º 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();
        }
Exemplo n.º 3
0
        public void ShouldFailWithPropertyNotSetBeforeOperationExceptionWhenNoPropertiesSetBeforeBeginExecute()
        {
            var plugin = new FileCopyPlugin();
            plugin.ExecuteFailed +=
                delegate(object sender, ObjectErrorEventArgs<IPlugin> e) { throw e.Exception; };

            plugin.BeginExecute();
        }
Exemplo n.º 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();
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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);
            }
        }