public FileCommand Create(FileOperationBehaviourType type, string sourceFile, string destinationFile)
        {
            switch (type)
            {
            case FileOperationBehaviourType.DestExistsThrowException:
                return(new FileCopyExistsThrowExceptionCommand(sourceFile, destinationFile));

            case FileOperationBehaviourType.DestExistsDoNothing:
                return(new FileCopyExistsDoNothingCommand(sourceFile, destinationFile));

            case FileOperationBehaviourType.DestExistsOverwrite:
                return(new FileCopyExistsOverwriteCommand(sourceFile, destinationFile));

            case FileOperationBehaviourType.DestExistsRenameWithNumber:
                return(new FileCopyExistsRenameWithNumberCommand(sourceFile, destinationFile));

            case FileOperationBehaviourType.SourceSizeGreaterOverwrite:
                return(new FileCopySourceSizeGreaterOverwriteCommand(sourceFile, destinationFile));

            case FileOperationBehaviourType.SourceIsNewerOverwrite:
                return(new FileCopySourceIsNewerOverwriteCommand(sourceFile, destinationFile));

            default:
                throw new InvalidOperationException($"Unhandled {nameof(FileOperationBehaviourType)}: {type}.");
            }
        }
Example #2
0
        /// <summary>
        /// Copy <paramref name="sourceFile" /> to <paramref name="destinationFile" />.
        /// </summary>
        /// <param name="sourceFile">Source file to copy.</param>
        /// <param name="destinationFile">Destination to copy the file to.</param>
        /// <param name="type">File operation behaviour to use when copying the file.</param>
        /// <returns>File info of the copied file.</returns>
        /// <exception cref="T:System.ArgumentNullException"><paramref name="sourceFile" /> is null.</exception>
        /// <exception cref="T:System.ArgumentNullException"><paramref name="destinationFile" /> is null.</exception>
        public FileInfo CopyFile(FileInfo sourceFile, FileInfo destinationFile, FileOperationBehaviourType type = FileOperationBehaviourType.DestExistsThrowException)
        {
            if (sourceFile == null)
            {
                throw new ArgumentNullException(nameof(sourceFile));
            }

            if (destinationFile == null)
            {
                throw new ArgumentNullException(nameof(destinationFile));
            }

            return(CopyFile(sourceFile.FullName, destinationFile.FullName));
        }
Example #3
0
        /// <summary>
        /// Copy <paramref name="sourceFile" /> to <paramref name="destinationFile" />.
        /// </summary>
        /// <param name="sourceFile">Source file to copy.</param>
        /// <param name="destinationFile">Destination to copy the file to.</param>
        /// <param name="type">File operation behaviour to use when copying the file.</param>
        /// <returns>File info of the copied file.</returns>
        /// <exception cref="T:System.ArgumentNullException"><paramref name="sourceFile" /> is null.</exception>
        /// <exception cref="T:System.ArgumentNullException"><paramref name="destinationFile" /> is null.</exception>
        public FileInfo CopyFile(string sourceFile, string destinationFile, FileOperationBehaviourType type = FileOperationBehaviourType.DestExistsThrowException)
        {
            if (sourceFile == null)
            {
                throw new ArgumentNullException(nameof(sourceFile));
            }

            if (destinationFile == null)
            {
                throw new ArgumentNullException(nameof(destinationFile));
            }

            var command = FileCopyCommandFactory.Create(type, sourceFile, destinationFile);

            command.Execute();

            return(command.DestinationFileResult);
        }
Example #4
0
            public void WhenTypeHandled_ThenReturnCorrectCommandType(FileOperationBehaviourType type, Type expectedCommandType)
            {
                var result = _sut.Create(type, "sourceFile", "destinationFile");

                Assert.That(result.GetType(), Is.EqualTo(expectedCommandType));
            }