Ejemplo n.º 1
0
        private void DoTypicalScenario(bool isPreview)
        {
            // arrange
            var copyActionText = isPreview ? "Copy Preview" : "Copying";
            var regex = new Regex(string.Format(@"{0} (.+) to", copyActionText), RegexOptions.IgnoreCase);
            var copier = new CopyManager(_sourceRootFolder, _destinationRootFolder, new FileHelper(), isPreview);

            // act
            var isCopySuccess = copier.CopyFiles();

            // assert
            Assert.That(isCopySuccess, Is.True, "Not Successful");
            Assert.That(copier.FileCopyLog, Is.Not.Null, "NULL File List");
            Assert.That(copier.FileCopyLog.Length, Is.GreaterThan(0), "EMPTY File List");
            Console.WriteLine("File List:\r\n");
            Console.WriteLine(copier.FileCopyLog);
            foreach (var file in copier.FileCopyLog.Split("\r\n".ToCharArray()))
            {
                if (!string.IsNullOrEmpty(file))
                {
                    var sourceFileName = regex.Match(file).Groups[1].Value;
                    Assert.That(File.Exists(sourceFileName), Is.True, string.Format("File: {0} does not exists", sourceFileName));
                    var destinationFileName = sourceFileName.Replace(_sourceRootFolder, _destinationRootFolder);
                    var destinationFileInfo = new FileInfo(destinationFileName);
                    if (!isPreview)
                    {
                        Assert.That(destinationFileInfo.Directory.Exists, Is.True, string.Format("Destination folder {0} does not exist", destinationFileInfo.DirectoryName));
                        Assert.That(File.Exists(destinationFileName), Is.True, string.Format("File: {0} does not exists", destinationFileName));
                    }
                    var sourceFileInfo = new FileInfo(sourceFileName);
                    var isReadonly = sourceFileInfo.Attributes.HasFlag(FileAttributes.ReadOnly);
                    Assert.That(isReadonly, Is.False, string.Format("File: {0} is read-only", sourceFileName)); // NOTE: this only works if there are in fact files checked out
                }
            }
        }
Ejemplo n.º 2
0
        public void CopyManager_UseIgnoreList_ShouldOnlyCopyUnignoredFiles()
        {
            // arrange
            var helper = new CopyManagerTestHelper();
            helper.ArrangeTypicalScenario("Copying", _sourceRootFolder, _destinationRootFolder, "File2.txt");

            var copier = new CopyManager(_sourceRootFolder, _destinationRootFolder, helper.MockHelper.Object, false);

            // act
            var isCopySuccess = copier.CopyFiles();

            // assert
            Assert.That(isCopySuccess, Is.True, "Not Successful");
            Assert.That(copier.FileCopyLog, Is.EqualTo(helper.ExpectedFileLog.ToString()), "Wrong File List");
        }
Ejemplo n.º 3
0
        private static void CopyFiles(string sourceFolder, string destinationFolder, bool isPreview)
        {
            if (!Directory.Exists(sourceFolder))
            {
                Console.WriteLine("Source folder: {0} does not exist.", sourceFolder);
                return;
            }

            Console.WriteLine("Copying files from {0} to {1}", sourceFolder, destinationFolder);

            var copier = new CopyManager(sourceFolder, destinationFolder, new FileHelper(), isPreview);
            var success = copier.CopyFiles();
            Console.WriteLine("File Copy was {0}", success ? "Successful!" : "unsuccessful");
            Console.WriteLine("Copy log is as follows:");
            Console.WriteLine(copier.FileCopyLog);
        }
Ejemplo n.º 4
0
        public void CopyManager_ExceptionThrown_ShouldSucceed()
        {
            // arrange
            var fileInUseText = "File in use";
            var sourceFile = Path.Combine(_sourceRootFolder, "File1.txt");
            var destinationFile = Path.Combine(_destinationRootFolder, "File1.txt");
            var expectedErrorInfo = string.Format("ERROR: Unable to copy {0}\r\nMessage: {1}\r\nDetails: System.IO.IOException: {1}\r\n", sourceFile, fileInUseText);
            var helper = new CopyManagerTestHelper();
            helper.ArrangeTypicalScenario("Copying", _sourceRootFolder, _destinationRootFolder, string.Empty);
            helper.MockHelper.Setup(x => x.FileCopy(sourceFile, destinationFile, true)).Throws(new IOException(fileInUseText));

            var copier = new CopyManager(_sourceRootFolder, _destinationRootFolder, helper.MockHelper.Object, false);

            // act
            var isCopySuccess = copier.CopyFiles();

            // assert
            Assert.That(isCopySuccess, Is.True, "Not Successful");
            Assert.That(copier.FileCopyLog.Contains(expectedErrorInfo), Is.True, "File Copy Log missing error info\r\nCopy Log:" + copier.FileCopyLog);
        }
Ejemplo n.º 5
0
        private void DoTypicalScenario(string copyActionText, bool isPreview)
        {
            // arrange
            var helper = new CopyManagerTestHelper();
            helper.ArrangeTypicalScenario(copyActionText, _sourceRootFolder, _destinationRootFolder, "debug");

            var copier = new CopyManager(_sourceRootFolder, _destinationRootFolder, helper.MockHelper.Object, isPreview);

            // act
            var isCopySuccess = copier.CopyFiles();

            // assert
            Assert.That(isCopySuccess, Is.True, "Not Successful");
            Assert.That(copier.FileCopyLog, Is.EqualTo(helper.ExpectedFileLog.ToString()), "Wrong File List");
        }