Exemplo n.º 1
0
 public void CopyingFiles_ExcludeFileFilterCase()
 {
     // test copying files with another exclude file filter case
     inputParams.ExcludeFiles = SyncTools.FileSpecsToRegex(new string[] { "*foo*" });
     expectedResults.Set(1, 0, 0, 3, 2, 0, 0);
     TestOneCase(new string[] { @"foo" }, new string[] { @"foo.jpg", @"bar.txt", @"foo\foo1.png", @"foo\txt.foo" },
                 null, null,
                 inputParams, expectedResults);
 }
Exemplo n.º 2
0
 public void CopyingFiles_ExcludeFileFilterNotMatchAnyFiles()
 {
     // test copying files with an exclude file filter that will not match any files
     inputParams.ExcludeFiles = SyncTools.FileSpecsToRegex(new string[] { "*.abc", "foo" });
     expectedResults.Set(4, 0, 0, 0, 2, 0, 0);
     TestOneCase(new string[] { @"foo" }, new string[] { @"foo.jpg", @"bar.txt", @"foo\foo1.png", @"foo\txt.foo" },
                 null, null,
                 inputParams, expectedResults);
 }
Exemplo n.º 3
0
        public void CopyingFiles_DirectoryIncludeFilterNotMatchAnySubdirectories()
        {
            inputParams.IncludeDirs = SyncTools.FileSpecsToRegex(new string[] { "marvin" });

            // test copying files with a directory include filter that doesn't match any subdirectories
            expectedResults.Set(2, 0, 0, 0, 1, 0, 3);
            TestOneCase(new string[] { @"foo", @"bar", @"bar2" }, new string[] { @"foo.jpg", @"bar.txt", @"foo\foo1.png", @"bar\txt.foo", @"bar2\thing.jig" },
                        null, null,
                        inputParams, expectedResults);
        }
Exemplo n.º 4
0
        public void CopyingFiles_FileIncludeFilter()
        {
            inputParams.ExcludeDirs = null;

            // test copying files with a file include filter
            inputParams.IncludeFiles = SyncTools.FileSpecsToRegex(new string[] { "*.jpg", "txt*" });
            expectedResults.Set(2, 0, 0, 2, 2, 0, 0);
            TestOneCase(new string[] { @"foo" }, new string[] { @"foo.jpg", @"bar.txt", @"foo\foo1.png", @"foo\txt.foo" },
                        null, null,
                        inputParams, expectedResults);
        }
Exemplo n.º 5
0
        public void CopyingFile_DirectoryExcludeFilter()
        {
            inputParams.ExcludeFiles = null;

            // test copying files with a directory exclude filter
            inputParams.ExcludeDirs = SyncTools.FileSpecsToRegex(new string[] { "foo*" });
            expectedResults.Set(3, 0, 0, 0, 2, 0, 1);
            TestOneCase(new string[] { @"foo", @"bar" }, new string[] { @"foo.jpg", @"bar.txt", @"foo\foo1.png", @"bar\txt.foo" },
                        null, null,
                        inputParams, expectedResults);
        }
Exemplo n.º 6
0
        public void CopyingFiles_ExcludeFileFilter()
        {
            inputParams.ExcludeHidden = false;

            // test copying files with an exclude file filter -- foo.jpg should not get copied
            inputParams.ExcludeFiles = SyncTools.FileSpecsToRegex(new string[] { "*.jpg", "*.wmv" });
            expectedResults.Set(3, 0, 0, 1, 2, 0, 0);
            TestOneCase(new string[] { @"foo" }, new string[] { @"foo.jpg", @"bar.txt", @"foo\foo1.png", @"foo\txt.foo" },
                        null, null,
                        inputParams, expectedResults);
        }
Exemplo n.º 7
0
        public void CopyingFiles_ExcludeFromDeletionDirectoryFilter()
        {
            inputParams.DeleteExcludeFiles = null;
            inputParams.DeleteFromDest     = true;
            inputParams.DeleteExcludeDirs  = SyncTools.FileSpecsToRegex(new string[] { "f*" });

            // test copying files with an exclude-from-deletion directory filter
            expectedResults.Set(4, 0, 2, 0, 0, 0, 0);
            TestOneCase(new string[] { @"foo" }, new string[] { @"foo.txt", @"bar.txt", @"foo\foo1.txt", @"foo\foo2.txt" },
                        new string[] { @"foo", "foo1" }, new string[] { @"foo\foo3.jpg", @"foo\foo4.txt" },
                        inputParams, expectedResults);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Runs a test case
        /// </summary>
        private static void TestOneCase(string[] srcDirectories, string[] srcFiles, string[] destDirectories, string[] destFiles, InputParams inputParams, SyncResults expectedResults)
        {
            // delete base directories in case they were hanging around from a previous failed test
            DeleteTestDirectory(baseDirSrc);
            DeleteTestDirectory(baseDirDest);

            // create source directories and files specified by test
            CreateTestDirectories(baseDirSrc, srcDirectories);
            CreateTestFiles(baseDirSrc, null, srcFiles);
            // create destination directories and files specified by test
            if (destDirectories != null)
            {
                CreateTestDirectories(baseDirDest, destDirectories);
            }
            if (destFiles != null)
            {
                CreateTestFiles(baseDirDest, baseDirSrc, destFiles);
            }

            // perform the directory sync
            SyncResults results = new SyncResults();

            results = new Sync(baseDirSrc, baseDirDest).Start(inputParams);

            // Assert we have expected results
            Assert.IsTrue(SyncTools.CompareTo(expectedResults, results));

            // If we are deleting extra files from destination, verify we have exactly the same files as filtered source files
            if (inputParams.DeleteFromDest &&
                (!(inputParams.DeleteExcludeFiles != null) && !(inputParams.DeleteExcludeDirs != null)))
            {
                // calc hash of filtered files & directories in source tree
                byte[] hashSrc = CalcHash(baseDirSrc, inputParams);
                // calc hash of all files & directories in destination tree
                byte[] hashDest = CalcHash(baseDirDest, null);
                // hashes must match
                bool hashesMatch = SyncTools.CompareByteArrays(hashSrc, hashDest);
                Assert.IsTrue(hashesMatch);
            }

            DeleteTestDirectory(baseDirSrc);
            DeleteTestDirectory(baseDirDest);
        }