public void RenamedShouldRaiseFileLostFollowedByFileFound()
 {
     MockFileSystemWatcher fsw = new MockFileSystemWatcher();
       PluginDirectory tested = new PluginDirectory(fsw);
       DateTime FileFoundRaised = DateTime.MinValue;
       DateTime FileLostRaised = DateTime.MinValue;
       tested.FileFound += (s, e) => { FileFoundRaised = DateTime.Now; Thread.Sleep(1); };
       tested.FileLost += (s, e) => { FileLostRaised = DateTime.Now; Thread.Sleep(1); };
       fsw.RaiseRenamed(GetType().Assembly.Location, GetType().Assembly.Location);
       Assert.AreNotEqual(DateTime.MinValue, FileFoundRaised);
       Assert.AreNotEqual(DateTime.MinValue, FileLostRaised);
       Assert.IsTrue(FileLostRaised < FileFoundRaised);
 }
        public void ShouldDelayRaiseRenamedUntilFileIsUnlocked()
        {
            AutoResetEvent raisedEvent = new AutoResetEvent(false);
              MockFileSystemWatcher mockInternal = new MockFileSystemWatcher();
              using (SafeEventFileSystemWatcher tested = new SafeEventFileSystemWatcher(mockInternal))
              {
            int RenamedRaised = 0;
            tested.Renamed += (s, e) =>
            {
              RenamedRaised++;
              raisedEvent.Set();
            };

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

            mockInternal.RaiseRenamed(fileName, newFileName);
            Assert.AreEqual(0, RenamedRaised);
            raisedEvent.WaitOne(500);
              }
              raisedEvent.WaitOne(500);
              Assert.AreEqual(1, RenamedRaised);
            }
            finally
            {
              System.IO.File.Delete(fileName);
            }
              }
        }