Ejemplo n.º 1
0
        public void DoSynchronization_FileRemovedAndGroupHasDefaultDeletePolicy_FileIsDeletedFromDest()
        {
            using (var from = new TemporaryFolder("synctest_source"))
                using (var to = new TemporaryFolder("synctest_dest"))
                {
                    File.WriteAllText(from.Combine("test1.txt"), "Blah blah");
                    var source = new RawDirectoryGroup("1", from.Path, null, null);

                    //ensure this is the defualt
                    Assert.IsFalse(source.NormallyPropogateDeletions);

                    var groups = new List <FileGroup>(new[] { source });
                    var sync   = new Synchronizer(to.Path, groups, 100, new NullProgress());
                    sync.DoSynchronization();
                    string destFile = to.Combine(sync.DestinationRootForThisUser, source.Name, "test1.txt");
                    Assert.IsTrue(File.Exists(destFile));
                    File.Delete(from.Combine("test1.txt"));

                    sync = new Synchronizer(to.Path, groups, 100, new NullProgress());
                    Assert.IsTrue(File.Exists(destFile));
                    sync.DoSynchronization();

                    Assert.IsFalse(File.Exists(to.Combine("test1.txt")));
                }
        }
Ejemplo n.º 2
0
        public void Run_PathHasDangerousCharacters_DoesCopy()
        {
            //couldn't make it break on what came to me over email: var problemPart = "07Support&F 7f3";
            var problemPart = "{9}";

            using (var from = new TemporaryFolder("synctest_source"))
                using (var to = new TemporaryFolder("synctest_dest"))
                {
                    using (var sub = new TemporaryFolder(from, problemPart))
                    {
                        var fileName = "1.txt";
                        System.IO.File.WriteAllText(sub.Combine(fileName), "Blah blah");
                        var source   = new RawDirectoryGroup("1", from.Path, null, null);
                        var groups   = new List <FileGroup>(new[] { source });
                        var progress = new ConsoleProgress()
                        {
                            ShowVerbose = true
                        };

                        var sync = new MirrorController(to.Path, groups, 100, progress);

                        sync.Run();
                        string path = to.Combine("1", problemPart, fileName);
                        Assert.That(File.Exists(path), path);
                    }
                }
        }
Ejemplo n.º 3
0
        public void GetInfo_FileIncludedInPreviousGroup_WontBeCountedTwice()
        {
            using (var from = new TemporaryFolder("synctest_source"))
                using (var to = new TemporaryFolder("synctest_dest"))
                {
                    File.WriteAllText(from.Combine("test1.txt"), "Blah blah");
                    var source1  = new RawDirectoryGroup("1", from.Path, null, null);
                    var source2  = new RawDirectoryGroup("2", from.Path, null, null);
                    var groups   = new List <FileGroup>(new[] { source1, source2 });
                    var progress = new StringBuilderProgress()
                    {
                        ShowVerbose = true
                    };
                    var sync = new Synchronizer(to.Path, groups, 100, progress);
                    sync.GatherPreview();

                    Assert.AreEqual(1, source1.NewFileCount);
                    Assert.AreEqual(0, source1.UpdateFileCount);
                    Assert.AreEqual(0, source1.DeleteFileCount);
                    Assert.AreEqual(9, source1.NetChangeInBytes);

                    Assert.AreEqual(0, source2.NewFileCount);
                    Assert.AreEqual(0, source2.UpdateFileCount);
                    Assert.AreEqual(0, source2.DeleteFileCount);
                    Assert.AreEqual(0, source2.NetChangeInBytes);
                }
        }
Ejemplo n.º 4
0
        public void Syncronhize_FileLocked_OtherFileCopied()
        {
            using (var from = new TemporaryFolder("synctest_source"))
                using (var to = new TemporaryFolder("synctest_dest"))
                {
                    System.IO.File.WriteAllText(from.Combine("test1.txt"), "Blah blah");
                    System.IO.File.WriteAllText(from.Combine("test2.txt"), "Blah blah blah");
                    var source   = new RawDirectoryGroup("1", from.Path, null, null);
                    var groups   = new List <FileGroup>(new[] { source });
                    var progress = new StringBuilderProgress()
                    {
                        ShowVerbose = true
                    };
                    var sync = new Synchronizer(to.Path, groups, 100, progress);

                    using (File.OpenWrite(from.Combine("test2.txt")))           //lock it up
                    {
                        sync.GatherPreview();
                        sync.DoSynchronization();
                    }
                    AssertFileExists(sync, source, to, "test1.txt");
                    AssertFileDoesNotExist(sync, source, to, "test2.txt");
                    Assert.That(progress.ErrorEncountered);
                }
        }
Ejemplo n.º 5
0
        public void Run_GroupHasDoDeletePolicy_DeletionIsPropagated()
        {
            using (var from = new TemporaryFolder("synctest_source"))
                using (var to = new TemporaryFolder("synctest_dest"))
                {
                    File.WriteAllText(from.Combine("test1.txt"), "Blah blah");
                    var source = new RawDirectoryGroup("1", from.Path, null, null)
                    {
                        NormallyPropogateDeletions = true
                    };
                    var groups     = new List <FileGroup>(new[] { source });
                    var controller = new MirrorController(to.Path, groups, 100, new NullProgress());
                    controller.Run();

                    //should be there at the destination
                    AssertFileExists(controller, source, to, "test1.txt");
                    File.Delete(from.Combine("test1.txt"));

                    File.WriteAllText(from.Combine("test2.txt"), "Blah blah");
                    controller = new MirrorController(to.Path, groups, 100, new NullProgress());
                    controller.Run();

                    AssertFileDoesNotExist(controller, source, to, "test1.txt");
                }
        }
Ejemplo n.º 6
0
 public void Run_FileExcludedByPreviousGroup_ButIsCopiedByLaterGroup()
 {
     using (var from = new TemporaryFolder("synctest_source"))
         using (var to = new TemporaryFolder("synctest_dest"))
         {
             File.WriteAllText(from.Combine("one.txt"), "Blah blah");
             var source1 = new RawDirectoryGroup("1", from.Path, null, null);
             source1.Filter.FileNameExcludes.Add("*.txt");
             var source2 = new RawDirectoryGroup("2", from.Path, null, null);
             var groups  = new List <FileGroup>(new[] { source1, source2 });
             var sync    = new MirrorController(to.Path, groups, 100, new ConsoleProgress());
             sync.Run();
             AssertFileExists(sync, source2, to, "one.txt");
             AssertFileDoesNotExist(sync, source1, to, "one.txt");
         }
 }
Ejemplo n.º 7
0
        public void GetInfo_EmptyDest_SingleFileWillBeCopied()
        {
            using (var from = new TemporaryFolder("synctest_source"))
                using (var to = new TemporaryFolder("synctest_dest"))
                {
                    System.IO.File.WriteAllText(from.Combine("test1.txt"), "Blah blah");
                    System.IO.File.WriteAllText(from.Combine("test2.txt"), "Blah blah blah");
                    var source = new RawDirectoryGroup("1", from.Path, null, null);
                    var groups = new List <FileGroup>(new[] { source });
                    var sync   = new Synchronizer(to.Path, groups, 100, new NullProgress());

                    sync.GatherPreview();
                    Assert.AreEqual(0, source.UpdateFileCount);
                    Assert.AreEqual(0, source.DeleteFileCount);
                    Assert.AreEqual(2, source.NewFileCount);
                    Assert.AreEqual(23, source.NetChangeInBytes);
                }
        }
Ejemplo n.º 8
0
        public void GetInfo_FilteredFile_WontBeCounted()
        {
            using (var from = new TemporaryFolder("synctest_source"))
                using (var to = new TemporaryFolder("synctest_dest"))
                {
                    File.WriteAllText(from.Combine("text.txt"), "Blah blah");
                    File.WriteAllText(from.Combine("info.info"), "deedeedee");
                    var source1 = new RawDirectoryGroup("1", from.Path, new [] { "*.info" }, null);
                    var groups  = new List <FileGroup>(new[] { source1 });
                    var sync    = new Synchronizer(to.Path, groups, 100, new NullProgress());
                    sync.GatherPreview();

                    Assert.AreEqual(1, source1.NewFileCount);
                    Assert.AreEqual(0, source1.UpdateFileCount);
                    Assert.AreEqual(0, source1.DeleteFileCount);
                    Assert.AreEqual(9, source1.NetChangeInBytes);
                }
        }
Ejemplo n.º 9
0
        public void Synchronize_EmptyDest_SingleFileIsBeCopied()
        {
            using (var from = new TemporaryFolder("synctest_source"))
                using (var to = new TemporaryFolder("synctest_dest"))
                {
                    System.IO.File.WriteAllText(from.Combine("1.txt"), "Blah blah");
                    var source   = new RawDirectoryGroup("1", from.Path, null, null);
                    var groups   = new List <FileGroup>(new[] { source });
                    var progress = new StringBuilderProgress()
                    {
                        ShowVerbose = true
                    };

                    var sync = new Synchronizer(to.Path, groups, 100, progress);

                    sync.DoSynchronization();
                    AssertFileExists(sync, source, to, "1.txt");
                }
        }
Ejemplo n.º 10
0
        public void Preview_FileExistsButHasChanged_WillBeReplaced()
        {
            using (var from = new TemporaryFolder("synctest_source"))
                using (var to = new TemporaryFolder("synctest_dest"))
                {
                    System.IO.File.WriteAllText(from.Combine("test1.txt"), "Blah blah");
                    System.IO.File.WriteAllText(from.Combine("test2.txt"), "dee dee dee");
                    var source = new RawDirectoryGroup("1", from.Path, null, null);
                    var groups = new List <FileGroup>(new[] { source });
                    var sync   = new MirrorController(to.Path, groups, 100, new NullProgress());
                    sync.GatherPreview();
                    sync.Run();
                    System.IO.File.WriteAllText(from.Combine("test1.txt"), "Blah blah Blah Blah Blah");
                    sync = new MirrorController(to.Path, groups, 100, new NullProgress());
                    sync.GatherPreview();

                    Assert.AreEqual(1, source.UpdateFileCount);
                    Assert.AreEqual(0, source.DeleteFileCount);
                    Assert.AreEqual(0, source.NewFileCount);
                    Assert.AreEqual(15, source.NetChangeInBytes);
                }
        }
Ejemplo n.º 11
0
        public void DoSynchronization_GroupHasDoDeletePolicy_DeletionIsPropagated()
        {
            using (var from = new TemporaryFolder("synctest_source"))
                using (var to = new TemporaryFolder("synctest_dest"))
                {
                    File.WriteAllText(from.Combine("test1.txt"), "Blah blah");
                    var source = new RawDirectoryGroup("1", from.Path, null, null);
                    var groups = new List <FileGroup>(new[] { source });
                    var sync   = new Synchronizer(to.Path, groups, 100, new NullProgress());
                    sync.DoSynchronization();

                    //should be there at the destination
                    AssertFileExists(sync, source, to, "test1.txt");
                    File.Delete(from.Combine("test1.txt"));

                    File.WriteAllText(from.Combine("test2.txt"), "Blah blah");
                    sync = new Synchronizer(to.Path, groups, 100, new NullProgress());
                    sync.DoSynchronization();

                    AssertFileDoesNotExist(sync, source, to, "test1.txt");
                }
        }
Ejemplo n.º 12
0
        public void Run_ToldToSkipExtensionButSourceHasUpperCaseOfExt_DoesNotCopy()
        {
            using (var from = new TemporaryFolder("synctest_source"))
                using (var to = new TemporaryFolder("synctest_dest"))
                {
                    File.WriteAllText(from.Combine("one.TXT"), "Blah blah");
                    var source = new RawDirectoryGroup("1", from.Path, null, null);
                    source.Filter.FileNameExcludes.Add("*.txt");

                    var groups   = new List <FileGroup>(new[] { source });
                    var progress = new StringBuilderProgress()
                    {
                        ShowVerbose = true
                    };
                    var sync = new MirrorController(to.Path, groups, 100, progress);
                    sync.Run();

                    AssertFileDoesNotExist(sync, source, to, "one.txt");
                    // we don't get this progress yet Assert.That(progress.Text.ToLower().Contains("skip"));
                    Assert.AreEqual(0, source.NewFileCount);
                    Assert.AreEqual(0, source.UpdateFileCount);
                    Assert.AreEqual(0, source.DeleteFileCount);
                }
        }
Ejemplo n.º 13
0
        public void Synchronize_FolderExcluded_IsSkipped()
        {
            using (var from = new TemporaryFolder("synctest_source"))
                using (var to = new TemporaryFolder("synctest_dest"))
                {
                    Directory.CreateDirectory(from.Combine("sub"));
                    File.WriteAllText(from.Combine("sub", "one.txt"), "Blah blah");
                    var source = new RawDirectoryGroup("1", from.Path, null, null);
                    source.Filter.SubdirectoryExcludes.Add("sub");

                    var groups   = new List <FileGroup>(new[] { source });
                    var progress = new StringBuilderProgress()
                    {
                        ShowVerbose = true
                    };
                    var sync = new Synchronizer(to.Path, groups, 100, progress);
                    sync.DoSynchronization();

                    // we don't get this progress yet Assert.That(progress.Text.ToLower().Contains("skip"));
                    Assert.AreEqual(0, source.NewFileCount);
                    Assert.AreEqual(0, source.UpdateFileCount);
                    Assert.AreEqual(0, source.DeleteFileCount);
                }
        }
Ejemplo n.º 14
0
        public void DoSynchronization_FileInMercurialFolderRemoved_FileGetsDeletedFromDest()
        {
            using (var from = new TemporaryFolder("synctest_source"))
                using (var to = new TemporaryFolder("synctest_dest"))
                {
                    Directory.CreateDirectory(from.Combine(".hg"));
                    File.WriteAllText(from.Combine(".hg", "test1.txt"), "Blah blah");
                    var source = new RawDirectoryGroup("1", from.Path, null, null);
                    //the key here is that even though the group calls for NO deletion,
                    //we do it anyways inside of the mercurial folder (.hg)
                    source.NormallyPropogateDeletions = false;

                    var groups = new List <FileGroup>(new[] { source });
                    var sync   = new Synchronizer(to.Path, groups, 100, new NullProgress());
                    sync.DoSynchronization();
                    AssertFileExists(sync, source, to, Path.Combine(".hg", "test1.txt"));

                    File.Delete(from.Combine("test1.txt"));
                    sync = new Synchronizer(to.Path, groups, 100, new NullProgress());
                    sync.DoSynchronization();

                    AssertFileDoesNotExist(sync, source, to, Path.Combine(".hg", "test1.txt"));
                }
        }
Ejemplo n.º 15
0
        public void Run_PathIsVeryLong_DoesCopy()
        {
            //we're adding this guid because teh normal tempfolder code can't handle this super deap thing, can't clear it out for us
            //as we re-run this test
            var guid = Guid.NewGuid().ToString();

            using (var from = new TemporaryFolder("synctest_source" + guid))
                using (var to = new TemporaryFolder("synctest_dest" + guid))
                {
                    string sub = from.Path;
                    for (int i = 0; i < 10; i++)
                    {
                        sub = sub + Path.DirectorySeparatorChar + "OnePartOfTheDirectory" + i;
                        Microsoft.Experimental.IO.LongPathDirectory.Create(sub);
                    }

                    var fileName = "1.txt";
                    using (var file = Microsoft.Experimental.IO.LongPathFile.Open(sub.CombineForPath(fileName), FileMode.CreateNew,
                                                                                  FileAccess.ReadWrite))
                    {
                    }
                    var source   = new RawDirectoryGroup("Group1", from.Path, null, null);
                    var groups   = new List <FileGroup>(new[] { source });
                    var progress = new ConsoleProgress()
                    {
                        ShowVerbose = true
                    };

                    var sync = new MirrorController(to.Path, groups, 100, progress);

                    sync.Run();
                    string path = sub.Replace("synctest_source" + guid, "synctest_dest" + guid + Path.DirectorySeparatorChar + "Group1").CombineForPath("1.txt");

                    Assert.That(LongPathFile.Exists(path), path);
                }
        }
Ejemplo n.º 16
0
        private void AssertFileExists(Synchronizer sync, RawDirectoryGroup source, TemporaryFolder destFolder, string fileName)
        {
            string path = destFolder.Combine(sync.DestinationRootForThisUser, source.Name, fileName);

            Assert.IsTrue(File.Exists(path), path);
        }
Ejemplo n.º 17
0
        private void AssertFileExists(MirrorController controller, RawDirectoryGroup source, TemporaryFolder destFolder, string fileName)
        {
            string path = destFolder.Combine(controller.DestinationRootForThisUser, source.Name, fileName);

            Assert.IsTrue(File.Exists(path), path);
        }