示例#1
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
                }
            }
        }
示例#2
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
                }
            }
        }
示例#3
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);
            }
        }
示例#4
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));
            }
        }
示例#5
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);
                }
            }
        }
示例#6
0
 public void TestChangeTypeNone()
 {
     using (Watcher watcher = new Watcher(TestFolder))
     {
         watcher.EnableRaisingEvents = true;
         Assert.AreEqual(Watcher.ChangeTypes.None, watcher.GetChangeType(GetPathname()));
     }
 }
示例#7
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));
     }
 }
示例#8
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));
     }
 }
示例#9
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]));
                }
            }
        }