public void FsChange_WontMakeRestart_WhenDllOutsideWatchedFolderChanged()
        {
            var dummyFsWatcherProxy = new Fake_FsWatcherProxy();
            RestartHandler restartHandler = new RestartHandler();
            var spyRestarter = new Fake_AppRestarter();
            restartHandler.Init(spyRestarter, @"C:\watchedFolder", dummyFsWatcherProxy);

            restartHandler.OnFsChange(@"C:\otherFolder\abc.dll");

            Assert.AreEqual(0, spyRestarter.CalledRestartsCount);
        }
        public void FsChange_WillMakeRestart_WhenDllInWatchedFolderChanged()
        {
            var dummyFsWatcherProxy = new Fake_FsWatcherProxy();
            RestartHandler restartHandler = new RestartHandler();
            var spyRestarter = new Fake_AppRestarter();
            restartHandler.Init(spyRestarter, @"C:\watchedFolder", dummyFsWatcherProxy);

            restartHandler.OnFsChange(@"C:\watchedFolder\abc.dll");

            Assert.IsTrue(spyRestarter.CalledRestartsCount > 0);
        }
        public void Dispose_WillDisposeFsWatcher_Always()
        {
            var spyFsWatcherProxy = new Fake_FsWatcherProxy();

            using (RestartHandler restartHandler = new RestartHandler())
            {
                restartHandler.Init(null, null, spyFsWatcherProxy);
            }

            Assert.IsTrue(spyFsWatcherProxy.CalledDispose);
        }
        public void FsChange_WontMakeMultipleRestarts_WhenMultipleFsChangesDetected()
        {
            var dummyFsWatcherProxy = new Fake_FsWatcherProxy();
            RestartHandler restartHandler = new RestartHandler();
            var spyRestarter = new Fake_AppRestarter();
            restartHandler.Init(spyRestarter, @"C:\watchedFolder", dummyFsWatcherProxy);

            restartHandler.OnFsChange(@"C:\watchedFolder\abc.dll");
            restartHandler.OnFsChange(@"C:\watchedFolder\abc.dll");
            restartHandler.OnFsChange(@"C:\watchedFolder\abc.dll");

            Assert.AreEqual(1, spyRestarter.CalledRestartsCount);
        }
        public void FsChange_WontMakeRestart_WhenFsChangeDetectedBothDuringAndAfterLoadingTime()
        {
            var dummyFsWatcherProxy = new Fake_FsWatcherProxy();
            RestartHandler restartHandler = new RestartHandler();
            var spyRestarter = new Fake_AppRestarter();
            restartHandler.Init(spyRestarter, @"C:\watchedFolder", dummyFsWatcherProxy);

            restartHandler.OnLoadingBegin();
            restartHandler.OnFsChange(@"C:\watchedFolder\abc.dll");
            restartHandler.OnLoadingEnd();
            restartHandler.OnFsChange(@"C:\watchedFolder\abc.dll");

            Assert.AreEqual(0, spyRestarter.CalledRestartsCount);
        }
        public void RestartNow_WillMakeRestart_Always()
        {
            var dummyFsWatcherProxy = new Fake_FsWatcherProxy();
            RestartHandler restartHandler = new RestartHandler();
            var spyRestarter = new Fake_AppRestarter();
            restartHandler.Init(spyRestarter, null, dummyFsWatcherProxy);

            restartHandler.RestartNow();

            Assert.IsTrue(spyRestarter.CalledRestartsCount > 0);
        }
        public void Init_WontEnableRaisingEventsOfFsWatcherProxy_WhenFolderPathToWatchEmpty()
        {
            var spyFsWatcherProxy = new Fake_FsWatcherProxy();
            RestartHandler restartHandler = new RestartHandler();
            {
                restartHandler.Init(null, "", spyFsWatcherProxy);
            }

            Assert.IsFalse(spyFsWatcherProxy.EnableRaisingEvents);
        }
        public void Init_WillSetWatchedFolderToFsWatcherProxy_Always()
        {
            var spyFsWatcherProxy = new Fake_FsWatcherProxy();
            RestartHandler restartHandler = new RestartHandler();
            {
                restartHandler.Init(null, @"D:\someFolder", spyFsWatcherProxy);
            }

            Assert.AreEqual(@"D:\someFolder", spyFsWatcherProxy.Path);
        }
        public void Init_WillEnableRaisingEventsOfFsWatcherProxy_WhenFolderPathToWatchNotEmpty()
        {
            var spyFsWatcherProxy = new Fake_FsWatcherProxy();
            RestartHandler restartHandler = new RestartHandler();
            {
                restartHandler.Init(null, @"D:\someFolder", spyFsWatcherProxy);
            }

            Assert.IsTrue(spyFsWatcherProxy.EnableRaisingEvents);
        }