Esempio n. 1
0
 public void TestChangeTypeForMoveIntoSyncedFolder()
 {
     using (Watcher watcher = new Watcher(TestFolder))
     {
         watcher.EnableRaisingEvents = true;
         CreateTestFile(oldnameOut, 1);
         WaitWatcher();
         File.Move(oldnameOut, newname);
         WaitWatcher(40000,watcher,1);
         Assert.AreEqual(1, watcher.GetChangeList().Count);
         Assert.AreEqual(newname, watcher.GetChangeList()[0]);
         Assert.AreEqual(Watcher.ChangeTypes.Created, watcher.GetChangeType(newname));
     }
 }
Esempio n. 2
0
        public void TestChangeTypeForMoveOutOfSyncedFolder()
        {

            using (Watcher watcher = new Watcher(TestFolder))
            {
                watcher.EnableRaisingEvents = true;
                CreateTestFile(oldname, 1);
                WaitWatcher(40000,watcher,(w) => 
                {
#if __MonoCS__
                    List<Watcher.ChangeTypes> types = new List<Watcher.ChangeTypes>();
                    types.Add(Watcher.ChangeTypes.Created);
                    types.Add(Watcher.ChangeTypes.Changed);
                    return types.Contains(w.GetChangeType(oldname));
#else
                    return w.GetChangeType(oldname) == Watcher.ChangeTypes.Changed;
#endif
                });
                File.Move(oldname, newnameOut);
                Console.WriteLine("moved:"+oldname);
                WaitWatcher(40000,watcher,(w) => 
                {
                    return w.GetChangeType(oldname) == Watcher.ChangeTypes.Deleted;
                });
                Assert.AreEqual(1, watcher.GetChangeList().Count);
                Assert.AreEqual(oldname, watcher.GetChangeList()[0]);
                Assert.AreEqual(Watcher.ChangeTypes.Deleted, watcher.GetChangeType(oldname));
            }
        }
Esempio n. 3
0
 public void TestChangeTypeNone()
 {
     using (Watcher watcher = new Watcher(TestFolder))
     {
         watcher.EnableRaisingEvents = true;
         Assert.AreEqual(Watcher.ChangeTypes.None, watcher.GetChangeType(GetPathname()));
     }
 }
Esempio n. 4
0
 public void TestChangeTypeForMoveInsideSyncedFolder()
 {
     using (Watcher watcher = new Watcher(TestFolder))
     {
         watcher.EnableRaisingEvents = true;
         CreateTestFile(oldname, 1);
         WaitWatcher(40000,watcher,1);
         File.Move(oldname, newname);
         WaitWatcher(40000,watcher,2);
         WaitWatcher(40000,watcher,(w)=>
         {
             return w.GetChangeType(oldname) == Watcher.ChangeTypes.Deleted;
         });
         List<string> changeList = watcher.GetChangeList();
         Assert.AreEqual(2, changeList.Count);
         Assert.Contains(oldname, changeList);
         Assert.Contains(newname, changeList);
         Assert.AreEqual(Watcher.ChangeTypes.Deleted, watcher.GetChangeType(oldname));
         Assert.AreEqual(Watcher.ChangeTypes.Created, watcher.GetChangeType(newname));
     }
 }
Esempio n. 5
0
        public void TestChangeTypeChanged()
        {
            using (Watcher watcher = new Watcher(TestFolder))
            {
                watcher.EnableRaisingEvents = true;

                List<string> names = new List<string>();
                for (int i = 0; i < NormalNumber; ++i)
                {
                    CreateTestFile();
                    names.Add(GetPathname());
                }
                for (int i = 0; i < NormalNumber; ++i)
                {
                    CreateTestFile(names[i], i + 1);
                }
                WaitWatcher(40000,watcher,NormalNumber);
                WaitWatcher(40000,watcher,(w)=>
                {
#if __MonoCS__
                    List<Watcher.ChangeTypes> types = new List<Watcher.ChangeTypes>();
                    types.Add(Watcher.ChangeTypes.Created);
                    types.Add(Watcher.ChangeTypes.Changed);
#endif
                    for (int i = 0; i < NormalNumber; ++i)
                    {
#if __MonoCS__
                        if (!types.Contains(w.GetChangeType(names[i])))
#else
                        if (w.GetChangeType(names[i]) != Watcher.ChangeTypes.Changed)
#endif
                        {
                            return false;
                        }
                    }
                    return true;
                });
                List<string> changeList = watcher.GetChangeList();
                Assert.AreEqual(NormalNumber, changeList.Count);
                for (int i = 0; i < NormalNumber; ++i)
                {
                    Assert.Contains(names[i], changeList);
#if __MonoCS__
                    List<Watcher.ChangeTypes> types = new List<Watcher.ChangeTypes>();
                    types.Add(Watcher.ChangeTypes.Created);
                    types.Add(Watcher.ChangeTypes.Changed);
                    Assert.Contains(
                        watcher.GetChangeType(names[i]), types);
#else
                    Assert.AreEqual(
                        watcher.GetChangeType(names[i]),
                        Watcher.ChangeTypes.Changed);
#endif
                }
            }
        }
Esempio n. 6
0
        public void TestChangeTypeDeleted()
        {
            using (Watcher watcher = new Watcher(TestFolder))
            {
                watcher.EnableRaisingEvents = true;

                List<string> names = new List<string>();
                for (int i = 0; i < NormalNumber; ++i)
                {
                    CreateTestFile();
                    names.Add(GetPathname());
                }
                WaitWatcher(40000,watcher,NormalNumber);
                for (int i = 0; i < NormalNumber; ++i)
                {
                    File.Delete(names[i]);
                }
                WaitWatcher(40000,watcher,(w) =>
                {
                    return w.GetChangeType(names[NormalNumber-1])
                        == Watcher.ChangeTypes.Deleted;
                });
                List<string> changeList = watcher.GetChangeList();
                Assert.AreEqual(NormalNumber, changeList.Count);
                for (int i = 0; i < NormalNumber; ++i)
                {
                    Assert.Contains(names[i], changeList);
                    Assert.AreEqual(
                        watcher.GetChangeType(names[i]),
                        Watcher.ChangeTypes.Deleted);
                }
            }
        }
Esempio n. 7
0
        public void TestChangeTypeCreatedHeavy()
        {
            using (Watcher watcher = new Watcher(TestFolder))
            {
                watcher.EnableRaisingEvents = true;

                List<string> names = new List<string>();
                for (int i = 0; i < HeavyNumber; ++i)
                {
                    CreateTestFile(0, i / FileInFolderNumber);
                    names.Add(GetPathname(i / FileInFolderNumber));
                }
                Assert.IsTrue(watcher.EnableRaisingEvents);
                int totalNumber = HeavyNumber + (HeavyNumber - 1) / FileInFolderNumber;
                WaitWatcher(60000,watcher,totalNumber);
                Assert.AreEqual(totalNumber, watcher.GetChangeList().Count);
                for (int i = 0; i < HeavyNumber; ++i)
                {
#if __MonoCS__
                    List<Watcher.ChangeTypes> types = new List<Watcher.ChangeTypes>();
                    types.Add(Watcher.ChangeTypes.Created);
                    types.Add(Watcher.ChangeTypes.Changed);
                    Assert.Contains(
                        watcher.GetChangeType(names[i]), types);
#else
                    Assert.AreEqual(
                        watcher.GetChangeType(names[i]),
                        Watcher.ChangeTypes.Created,
                        names[i]);
#endif
                }
            }
        }
Esempio n. 8
0
        public void TestChangeTypeCreated()
        {
            using (Watcher watcher = new Watcher(TestFolder))
            {
                watcher.EnableRaisingEvents = true;

                List<string> names = new List<string>();
                for (int i = 0; i < NormalNumber; ++i)
                {
                    CreateTestFile();
                    names.Add(GetPathname());
                }
                WaitWatcher(40000, watcher, (w) =>
                {
                    return watcher.GetChangeType(names[NormalNumber -1]) == Watcher.ChangeTypes.Created;
                });
                for (int i = 0; i < NormalNumber; ++i)
                {
                    Assert.AreEqual(
                        Watcher.ChangeTypes.Created,
                        watcher.GetChangeType(names[i]));
                }
            }
        }
Esempio n. 9
0
        public void TestRemoveInsert()
        {
            using (Watcher watcher = new Watcher(TestFolder))
            {
                for (int i = 0; i < NormalNumber; ++i)
                {
                    watcher.InsertChange(i.ToString(), Watcher.ChangeTypes.None);
                }
                Assert.AreEqual(0, watcher.GetChangeList().Count);

                for (int i = 0; i < NormalNumber; ++i)
                {
                    watcher.InsertChange(i.ToString(), Watcher.ChangeTypes.Created);
                }
                Assert.AreEqual(NormalNumber, watcher.GetChangeList().Count);
                for (int i = 0; i < NormalNumber; ++i)
                {
                    Assert.AreEqual(i.ToString(), watcher.GetChangeList()[i]);
                    Assert.AreEqual(Watcher.ChangeTypes.Created, watcher.GetChangeType(i.ToString()));
                }

                for (int i = 0; i < NormalNumber; ++i)
                {
                    watcher.InsertChange(i.ToString(), Watcher.ChangeTypes.Deleted);
                }
                Assert.AreEqual(NormalNumber, watcher.GetChangeList().Count);
                for (int i = 0; i < NormalNumber; ++i)
                {
                    Assert.AreEqual(i.ToString(), watcher.GetChangeList()[i]);
                    Assert.AreEqual(Watcher.ChangeTypes.Created, watcher.GetChangeType(i.ToString()));
                }

                for (int i = 0; i < NormalNumber; ++i)
                {
                    watcher.RemoveChange(i.ToString(), Watcher.ChangeTypes.Deleted);
                }
                Assert.AreEqual(NormalNumber, watcher.GetChangeList().Count);
                for (int i = 0; i < NormalNumber; ++i)
                {
                    Assert.AreEqual(i.ToString(), watcher.GetChangeList()[i]);
                    Assert.AreEqual(Watcher.ChangeTypes.Created, watcher.GetChangeType(i.ToString()));
                }

                for (int i = 0; i < NormalNumber; ++i)
                {
                    watcher.RemoveChange(i.ToString(), Watcher.ChangeTypes.Created);
                }
                Assert.AreEqual(0, watcher.GetChangeList().Count);
            }
        }
Esempio n. 10
0
        public void TestChangeTypeForMove()
        {
            string oldnameOut = Path.Combine(TestFolderParent, "test.old");
            string newnameOut = Path.Combine(TestFolderParent, "test.new");
            string oldname = Path.Combine(TestFolder, "test.old");
            string newname = Path.Combine(TestFolder, "test.new");

            using (Watcher watcher = new Watcher(TestFolder))
            {
                File.Delete(newname);
                watcher.EnableRaisingEvents = true;
                CreateTestFile(oldname, 1);
                WaitWatcher(40000,watcher,1);
                File.Move(oldname, newname);
                WaitWatcher(40000,watcher,2);
                WaitWatcher(40000,watcher,(w)=>
                {
                    return w.GetChangeType(oldname) == Watcher.ChangeTypes.Deleted;
                });
                List<string> changeList = watcher.GetChangeList();
                Assert.AreEqual(2, changeList.Count);
                Assert.Contains(oldname, changeList);
                Assert.Contains(newname, changeList);
                Assert.AreEqual(Watcher.ChangeTypes.Deleted, watcher.GetChangeType(oldname));
                Assert.AreEqual(Watcher.ChangeTypes.Created, watcher.GetChangeType(newname));
                File.Delete(newname);
            }

            using (Watcher watcher = new Watcher(TestFolder))
            {
                File.Delete(newname);
                watcher.EnableRaisingEvents = true;
                CreateTestFile(oldnameOut, 1);
                WaitWatcher();
                File.Move(oldnameOut, newname);
                WaitWatcher(40000,watcher,1);
                Assert.AreEqual(1, watcher.GetChangeList().Count);
                Assert.AreEqual(newname, watcher.GetChangeList()[0]);
                Assert.AreEqual(Watcher.ChangeTypes.Created, watcher.GetChangeType(newname));
                File.Delete(newname);
            }

            using (Watcher watcher = new Watcher(TestFolder))
            {
                File.Delete(newnameOut);
                watcher.EnableRaisingEvents = true;
                CreateTestFile(oldname, 1);
                WaitWatcher(40000,watcher,1);
                File.Move(oldname, newnameOut);
                WaitWatcher(40000,watcher,(w) => 
                {
                    return w.GetChangeType(oldname) == Watcher.ChangeTypes.Deleted;
                });
                Assert.AreEqual(1, watcher.GetChangeList().Count);
                Assert.AreEqual(oldname, watcher.GetChangeList()[0]);
                Assert.AreEqual(Watcher.ChangeTypes.Deleted, watcher.GetChangeType(oldname));
                File.Delete(newnameOut);
            }

            using (Watcher watcher = new Watcher(TestFolder))
            {
                File.Delete(newnameOut);
                watcher.EnableRaisingEvents = true;
                CreateTestFile(oldnameOut, 1);
                WaitWatcher();
                File.Move(oldnameOut, newnameOut);
                WaitWatcher();
                Assert.AreEqual(0, watcher.GetChangeList().Count);
                File.Delete(newnameOut);
            }
        }
Esempio n. 11
0
        public void TestChangeTypeCreated()
        {
            using (Watcher watcher = new Watcher(TestFolder))
            {
                watcher.EnableRaisingEvents = true;

                List<string> names = new List<string>();
                for (int i = 0; i < NormalNumber; ++i)
                {
                    CreateTestFile();
                    names.Add(GetPathname());
                }
                WaitWatcher(40000,watcher,NormalNumber);
                Assert.AreEqual(NormalNumber, watcher.GetChangeList().Count);
                for (int i = 0; i < NormalNumber; ++i)
                {
                    Assert.AreEqual(names[i], watcher.GetChangeList()[i]);
                    Assert.AreEqual(
                        Watcher.ChangeTypes.Created,
                        watcher.GetChangeType((string)watcher.GetChangeList()[i]));
                }
            }
        }