public void CreatedShouldRaiseFileFound()
 {
     MockFileSystemWatcher fsw = new MockFileSystemWatcher();
       PluginDirectory tested = new PluginDirectory(fsw);
       int FileFoundRaised = 0;
       tested.FileFound += (s, e) => FileFoundRaised++;
       fsw.RaiseCreated(GetType().Assembly.Location);
       Assert.AreEqual(1, FileFoundRaised);
 }
        public void FileFoundShouldBeRasedForDlls()
        {
            MockFileSystemWatcher fsw = new MockFileSystemWatcher();

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

              fsw.RaiseCreated(@"file.dll");

              Assert.AreEqual(1, FileFoundRaised);
        }
 public void ShouldLogToDebugWhenRaisingFileFound()
 {
     string expected = "SomePath";
       MockFileSystemWatcher mockWatcher = new MockFileSystemWatcher();
       PluginDirectory tested = new PluginDirectory(mockWatcher);
       MockLog mockLog = new MockLog(tested);
       mockWatcher.RaiseCreated(expected);
       Assert.IsTrue(mockLog.Any(x => x.Level == MockLog.Level.Debug && x.Message.Contains(expected)));
 }
        public void FileFoundShouldNotBeReportedAfterRemoval()
        {
            MockFileSystemWatcher fsw = new MockFileSystemWatcher();

              PluginDirectory tested = new PluginDirectory(fsw);
              int FileFoundRaised = 0;

              EventHandler<PluginDirectoryEventArgs> handler = ((s, e) => FileFoundRaised++);
              tested.FileFound += handler;
              tested.FileFound -= handler;

              fsw.RaiseCreated(@"file.dll");
              Assert.AreEqual(0, FileFoundRaised);
        }
        public void ShouldWaitRaisingCreatedUntilFileIsUnlocked()
        {
            AutoResetEvent raisedEvent = new AutoResetEvent(false);
              MockFileSystemWatcher mockInternal = new MockFileSystemWatcher();
              using (SafeEventFileSystemWatcher tested = new SafeEventFileSystemWatcher(mockInternal))
              {
            int CreatedRaised = 0;
            tested.Created += (s, e) =>
            {
              CreatedRaised++;
              raisedEvent.Set();
            };

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

            mockInternal.RaiseCreated(fileName);

            raisedEvent.WaitOne(500);

            Assert.AreEqual(0, CreatedRaised);
              }

              raisedEvent.WaitOne(500);

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

            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);
              }
              Thread.Sleep(500);
              Assert.AreEqual(1, CreatedRaised);
              Assert.AreEqual(0, ChangedRaised);
            }
            finally
            {
              System.IO.File.Delete(fileName);
            }
              }
        }