Example #1
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);
            }
        }
Example #2
0
        public void TestRemove()
        {
            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(NormalNumber - i, watcher.GetChangeList().Count);
                    if (i % 2 == 0)
                    {
                        watcher.RemoveChange(names[i]);
                    }
                    else
                    {
                        watcher.RemoveChange(names[i],Watcher.ChangeTypes.Created);
                    }
                }
                names.Clear();

                for (int i = 0; i < NormalNumber; ++i)
                {
                    CreateTestFile();
                }
                WaitWatcher(40000,watcher,NormalNumber);
                Assert.AreEqual(NormalNumber, watcher.GetChangeList().Count);
                watcher.RemoveAll();
                Assert.AreEqual(0, watcher.GetChangeList().Count);
            }
        }