Beispiel #1
0
        public void TestEnableEvent()
        {
            using (Watcher watcher = new Watcher(TestFolder))
            {
                FileSystemEventCount count = new FileSystemEventCount();
                watcher.ChangeEvent += count.OnFileSystemEvent;

                CreateTestFile(1);
                WaitWatcher();
                Assert.AreEqual(0, count.Count);

                watcher.EnableRaisingEvents = true;

                CreateTestFile(2);
                WaitWatcher();
                Assert.AreEqual(0, count.Count);

                watcher.EnableRaisingEvents = false;
                watcher.EnableEvent         = true;

                CreateTestFile(3);
                WaitWatcher();
                Assert.AreEqual(0, count.Count);

                watcher.EnableRaisingEvents = true;

                CreateTestFile(4);
                WaitWatcher(40000, count, (c) =>
                {
                    return(c.Count >= 1);
                });
                Assert.LessOrEqual(1, count.Count);
                int number = count.Count;

                CreateTestFile(5);
                WaitWatcher(40000, count, (c) =>
                {
                    return(c.Count >= number + 1);
                });
                Assert.LessOrEqual(number + 1, count.Count);
                watcher.EnableEvent = false;
                number = count.Count;


                CreateTestFile(6);
                Assert.AreEqual(number, count.Count);
                number = count.Count;

                watcher.EnableEvent = true;

                CreateTestFile(7);
                WaitWatcher(40000, count, (c) =>
                {
                    return(c.Count >= number + 1);
                });
                Assert.LessOrEqual(number + 1, count.Count);
            }
        }
Beispiel #2
0
        public static void WaitWatcher(int milliseconds, FileSystemEventCount count, Func <FileSystemEventCount, bool> checkStop)
        {
#if __MonoCS__
            milliseconds = milliseconds * 10;
#endif
            while (milliseconds >= 0)
            {
                if (checkStop(count))
                {
                    return;
                }
                Thread.Sleep(10);
                milliseconds = milliseconds - 10;
            }
            Console.WriteLine("Timeout");
        }
Beispiel #3
0
        public static void WaitWatcher(int milliseconds, FileSystemEventCount count, Func<FileSystemEventCount,bool> checkStop)
        {
#if __MonoCS__
            milliseconds = milliseconds * 10;
#endif
            while (milliseconds >= 0)
            {
                if (checkStop(count))
                {
                    return;
                }
                Thread.Sleep(10);
                milliseconds = milliseconds - 10;
            }
            Console.WriteLine("Timeout");
        }
Beispiel #4
0
        public void TestEnableEvent()
        {
            using (Watcher watcher = new Watcher(TestFolder))
            {
                FileSystemEventCount count = new FileSystemEventCount();
                watcher.ChangeEvent += count.OnFileSystemEvent;

                CreateTestFile(1);
                WaitWatcher();
                Assert.AreEqual(0, count.Count);

                watcher.EnableRaisingEvents = true;

                CreateTestFile(2);
                WaitWatcher();
                Assert.AreEqual(0, count.Count);

                watcher.EnableRaisingEvents = false;
                watcher.EnableEvent = true;

                CreateTestFile(3);
                WaitWatcher();
                Assert.AreEqual(0, count.Count);

                watcher.EnableRaisingEvents = true;

                CreateTestFile(4);
                WaitWatcher(40000, count, (c) =>
                {
                    return c.Count >= 1;
                });
                Assert.LessOrEqual(1, count.Count);
                int number = count.Count;

                CreateTestFile(5);
                WaitWatcher(40000, count, (c) =>
                {
                    return c.Count >= number + 1;
                });
                Assert.LessOrEqual(number + 1, count.Count);
                watcher.EnableEvent = false;
                number = count.Count;


                CreateTestFile(6);
                Assert.AreEqual(number, count.Count);
                number = count.Count;

                watcher.EnableEvent = true;

                CreateTestFile(7);
                WaitWatcher(40000, count, (c) =>
                {
                    return c.Count >= number + 1;
                });
                Assert.LessOrEqual(number + 1, count.Count);
            }
        }