public void EatsExceptionsThrownByAction()
        {
            AutoResetEvent finished = new AutoResetEvent(false);
            Action         action   = new Action(() =>
            {
                try
                {
                    throw new Exception();
                }
                finally
                {
                    finished.Set();
                }
            });

            using (ProfileWatcher watcher = new ProfileWatcher(
                       Path.GetDirectoryName(filename),
                       Path.GetFileName(filename),
                       null,
                       action))
            {
                File.AppendAllText(filename, "some-data");

                Assert.IsTrue(finished.WaitOne(50, false));
            }
        }
 private void UpdateServerSource(IServerSource source)
 {
     if (watcher != null)
     {
         watcher.Dispose();
     }
     watcher = source.CreateWatcher(Poll, this);
     Poll();
 }
        public void CreateWatcherReturnsNewProfileWatcher()
        {
            using (AutoResetEvent actionCalled = new AutoResetEvent(false))
            {
                Action action = new Action(() => { actionCalled.Set(); });
                using (ProfileWatcher watcher = serverSource.CreateWatcher(action, null))
                {
                    Assert.IsFalse(actionCalled.WaitOne(50, false));

                    File.WriteAllText(filename, "new contents");

                    Assert.IsTrue(actionCalled.WaitOne(50, false));
                }
            }
        }
        public void DoesNothingIfDirectoryDoesNotExist()
        {
            AutoResetEvent finished = new AutoResetEvent(false);
            Action         action   = new Action(() => finished.Set());

            Directory.Delete(tempdir, true);

            using (ProfileWatcher watcher = new ProfileWatcher(
                       Path.GetDirectoryName(filename),
                       Path.GetFileName(filename),
                       null,
                       action))
            {
                Assert.IsTrue(true);
            }
        }
        public void CallsActionWhenFileIsChanged()
        {
            AutoResetEvent finished = new AutoResetEvent(false);
            Action         action   = new Action(() => finished.Set());

            using (ProfileWatcher watcher = new ProfileWatcher(
                       Path.GetDirectoryName(filename),
                       Path.GetFileName(filename),
                       null,
                       action))
            {
                Assert.IsFalse(finished.WaitOne(50, false));

                File.AppendAllText(filename, "some-data");

                Assert.IsTrue(finished.WaitOne(50, false));
            }
        }