public void DeletedShouldRaiseFileLost()
 {
     MockFileSystemWatcher fsw = new MockFileSystemWatcher();
       PluginDirectory tested = new PluginDirectory(fsw);
       int FileLostRaised = 0;
       tested.FileLost += (s, e) => FileLostRaised++;
       fsw.RaiseDeleted(GetType().Assembly.Location);
       Assert.AreEqual(1, FileLostRaised);
 }
 public void ShouldLogToDebugWhenRaisingFileLost()
 {
     string expected = "SomePath";
       MockFileSystemWatcher mockWatcher = new MockFileSystemWatcher();
       PluginDirectory tested = new PluginDirectory(mockWatcher);
       MockLog mockLog = new MockLog(tested);
       mockWatcher.RaiseDeleted(expected);
       Assert.IsTrue(mockLog.Any(x => x.Level == MockLog.Level.Debug && x.Message.Contains(expected)));
 }
        public void FileLostShouldNotBeRasedForNonDlls()
        {
            MockFileSystemWatcher fsw = new MockFileSystemWatcher();

              PluginDirectory tested = new PluginDirectory(fsw);
              int FileLostRaised = 0;
              tested.FileLost += (s, e) => FileLostRaised++;

              fsw.RaiseDeleted(@"file.img");

              Assert.AreEqual(0, FileLostRaised);
        }
        public void ShouldRaiseDeletedIfInternalRaisesDeleted()
        {
            AutoResetEvent raisedEvent = new AutoResetEvent(false);
              MockFileSystemWatcher mockInternal = new MockFileSystemWatcher();
              using (SafeEventFileSystemWatcher tested = new SafeEventFileSystemWatcher(mockInternal))
              {
            int DeletedRaised = 0;
            tested.Deleted += (s, e) =>
            {
              DeletedRaised++;
              raisedEvent.Set();
            };

            string fileName = Guid.NewGuid().ToString();
            try
            {
              using (var file = System.IO.File.CreateText(fileName))
            file.WriteLine("somedata");

              mockInternal.RaiseDeleted(fileName);
              raisedEvent.WaitOne(TimeSpan.FromSeconds(1));

              Assert.AreEqual(1, DeletedRaised);
            }
            finally
            {
              System.IO.File.Delete(fileName);
            }
              }
        }
        public void ShouldNotRaiseEventsOnNonExistingFileUntilPendingDeleted()
        {
            MockFileSystemWatcher mockInternal = new MockFileSystemWatcher();
              using (SafeEventFileSystemWatcher tested = new SafeEventFileSystemWatcher(mockInternal))
              {
            int ChangedRaised = 0;
            int DeletedRaised = 0;
            tested.Changed += (s, e) => ChangedRaised++;
            tested.Deleted += (s, e) => DeletedRaised++;

            string fileName = Guid.NewGuid().ToString();
            mockInternal.RaiseChanged(fileName);
            Thread.Sleep(500);
            Assert.AreEqual(0, ChangedRaised);

            mockInternal.RaiseDeleted(fileName);
            Thread.Sleep(500);

            Assert.AreEqual(1, ChangedRaised);
            Assert.AreEqual(1, DeletedRaised);
              }
        }
        public void ShouldNotEmitAnythingIfDeletedWhileStillPendingRaiseCreated()
        {
            MockFileSystemWatcher mockInternal = new MockFileSystemWatcher();
              using (SafeEventFileSystemWatcher tested = new SafeEventFileSystemWatcher(mockInternal))
              {
            int CreatedRaised = 0;
            int ChangedRaised = 0;
            int DeletedRaised = 0;
            tested.Created += (s, e) => CreatedRaised++;
            tested.Changed += (s, e) => ChangedRaised++;
            tested.Deleted += (s, e) => DeletedRaised++;

            string fileName = Guid.NewGuid().ToString();
            try
            {
              using (var file = System.IO.File.CreateText(fileName))
              {
            file.WriteLine("somedata");

            mockInternal.RaiseCreated(fileName);
            mockInternal.RaiseChanged(fileName);
            Thread.Sleep(500);
            Assert.AreEqual(0, CreatedRaised);
            Assert.AreEqual(0, ChangedRaised);
            mockInternal.RaiseDeleted(fileName);
              }
              Thread.Sleep(500);

              Assert.AreEqual(0, CreatedRaised);
              Assert.AreEqual(0, ChangedRaised);
              Assert.AreEqual(0, DeletedRaised);
            }
            finally
            {
              System.IO.File.Delete(fileName);
            }
              }
        }