public void SetUp()
 {
     TestUtils.ConfigureLog4Net();
     dispatched         = false;
     appName            = Guid.NewGuid().ToString();
     appFullPath        = Path.GetFullPath(appName);
     anotherAppName     = Guid.NewGuid().ToString();
     anotherAppFullPath = Path.GetFullPath(anotherAppName);
     Directory.CreateDirectory(appFullPath);
     Directory.CreateDirectory(anotherAppFullPath);
     eventLatch              = new Latch();
     controlledEventLatch    = new Latch();
     dispatcher              = new ForwardingDeployEventDispatcher();
     application             = new Application(appFullPath);
     dispatcher.DeployEvent += new DeployEventHandler(dispatcher_DeployEvent);
     watcher = new FileSystemApplicationWatcher(application);
 }
示例#2
0
        public void CreationViaARegexFilterConfigurerPrependsApplicationFullPathToRegex()
        {
            IApplication application       = new Application(Path.GetFullPath("."));
            FileSystemApplicationWatcher w =
                (FileSystemApplicationWatcher)DefaultApplicationWatcherFactory.Instance.CreateApplicationWatcher(application);

            Assert.AreEqual(1, w.DisallowFilters.Count);
            Assert.AreEqual(1, w.AllowFilters.Count);
            RegularExpressionFilter filter1 = w.AllowFilters[0] as RegularExpressionFilter;

            Assert.AreEqual(
                PathMatcher.ForwardifySlashes(application.FullPath + "/bin/**/*.*"), filter1.Patterns[0]);
            RegularExpressionFilter filter2 = w.DisallowFilters[0] as RegularExpressionFilter;

            Assert.AreEqual(
                PathMatcher.ForwardifySlashes(application.FullPath + "/**/*.log"), filter2.Patterns[0]);
        }
        public void IgnoreEventsRegardingTheDirectoryOfTheApplication()
        {
            FileSystemEventArgs e =
                new FileSystemEventArgs(WatcherChangeTypes.All,
                                        Directory.GetCurrentDirectory(), "foo");

            Assert.IsFalse(support.IsApplicationEvent(e, application, true));

            e = new FileSystemEventArgs(WatcherChangeTypes.All,
                                        Path.GetFullPath("foo"), "foo.dll");
            Assert.IsTrue(support.IsApplicationEvent(e, application, true));

            e = new FileSystemEventArgs(WatcherChangeTypes.All,
                                        Directory.GetCurrentDirectory(), "foo/foo.dll");
            Assert.IsTrue(support.IsApplicationEvent(e, application, true));

            e = new FileSystemApplicationWatcher(application,
                                                 new NullWatcherConfigurer()).GenericApplicationEvent;
            Assert.IsTrue(support.IsApplicationEvent(e, application, true));
        }
        public void CanBeConfiguredToIncludeOrExcludePathsForEvents()
        {
            string           simple = "Data/Xml/watcher-simple.xml";
            XmlObjectFactory f      = new XmlObjectFactory(new FileSystemResource(simple));

            f.RegisterSingleton(DefaultApplicationWatcherFactory.InjectedApplicationName, application);
            watcher = f["watcher"] as FileSystemApplicationWatcher;
            Assert.IsNotNull(watcher,
                             String.Format("test file [{0}] should define a file sistem resource!", simple));
            Assert.AreEqual(1, watcher.Excludes.Count);
            Assert.AreEqual(1, watcher.Includes.Count);

            watcher.StartWatching(dispatcher);

            // propagated
            string subDir = Path.Combine(appFullPath, "foo");

            Directory.CreateDirectory(subDir);
            using (File.Create(Path.Combine(subDir, "foo.bar"))) {}
            eventLatch.Acquire();
            Assert.IsFalse(dispatched);
        }
        public void CanBeConfiguredToIncludeOrExcludePathsForEvents ()
        {
            string simple = "Data/Xml/watcher-simple.xml";
            XmlObjectFactory f = new XmlObjectFactory(new FileSystemResource(simple));
            f.RegisterSingleton(DefaultApplicationWatcherFactory.InjectedApplicationName, application);
            watcher = f["watcher"] as FileSystemApplicationWatcher;
            Assert.IsNotNull(watcher, 
                String.Format("test file [{0}] should define a file sistem resource!", simple));
            Assert.AreEqual(1, watcher.Excludes.Count);
            Assert.AreEqual(1, watcher.Includes.Count);

            watcher.StartWatching(dispatcher);

            // propagated
            string subDir = Path.Combine(appFullPath, "foo");
            Directory.CreateDirectory(subDir);
            using (File.Create(Path.Combine (subDir, "foo.bar"))) {}
            eventLatch.Acquire();            
            Assert.IsFalse(dispatched);
        }
 public void SetUp ()
 {
     TestUtils.ConfigureLog4Net();
     dispatched = false;
     appName = Guid.NewGuid().ToString();
     appFullPath = Path.GetFullPath(appName);
     anotherAppName = Guid.NewGuid().ToString();
     anotherAppFullPath = Path.GetFullPath(anotherAppName);
     Directory.CreateDirectory(appFullPath);
     Directory.CreateDirectory(anotherAppFullPath);
     eventLatch = new Latch();
     controlledEventLatch = new Latch();
     dispatcher = new ForwardingDeployEventDispatcher();
     application = new Application(appFullPath);
     dispatcher.DeployEvent += new DeployEventHandler(dispatcher_DeployEvent);
     watcher = new FileSystemApplicationWatcher(application);
 }
        public void IgnoreEventsRegardingTheDirectoryOfTheApplication()
        {
            FileSystemEventArgs e = 
                new FileSystemEventArgs(WatcherChangeTypes.All, 
                Directory.GetCurrentDirectory(), "foo");
            Assert.IsFalse(support.IsApplicationEvent(e, application, true));

            e = new FileSystemEventArgs(WatcherChangeTypes.All, 
                Path.GetFullPath("foo"), "foo.dll");
            Assert.IsTrue(support.IsApplicationEvent(e, application, true));

            e = new FileSystemEventArgs(WatcherChangeTypes.All, 
                Directory.GetCurrentDirectory(), "foo/foo.dll");
            Assert.IsTrue(support.IsApplicationEvent(e, application, true));

            e = new FileSystemApplicationWatcher(application, 
                new NullWatcherConfigurer()).GenericApplicationEvent;
            Assert.IsTrue(support.IsApplicationEvent(e, application, true));
        }