Пример #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void notifyListenersOnDeletion() throws InterruptedException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void NotifyListenersOnDeletion()
        {
            TestFileSystemWatcher       watcher   = CreateWatcher();
            AssertableFileEventListener listener1 = new AssertableFileEventListener();
            AssertableFileEventListener listener2 = new AssertableFileEventListener();

            watcher.AddFileWatchEventListener(listener1);
            watcher.AddFileWatchEventListener(listener2);

            TestWatchEvent <Path> watchEvent  = new TestWatchEvent <Path>(ENTRY_DELETE, Paths.get("file1"));
            TestWatchEvent <Path> watchEvent2 = new TestWatchEvent <Path>(ENTRY_DELETE, Paths.get("file2"));
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: TestWatchKey watchKey = new TestWatchKey(asList(watchEvent, watchEvent2));
            TestWatchKey watchKey = new TestWatchKey(new IList <WatchEvent <object> > {
                watchEvent, watchEvent2
            });

            PrepareWatcher(watchKey);

            Watch(watcher);

            listener1.AssertDeleted("file1");
            listener1.AssertDeleted("file2");
            listener2.AssertDeleted("file1");
            listener2.AssertDeleted("file2");
        }
Пример #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void stopWatchingAndCloseEverythingOnClosed() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void StopWatchingAndCloseEverythingOnClosed()
        {
            TestFileSystemWatcher watcher = CreateWatcher();

            watcher.Dispose();

            verify(_watchServiceMock).close();
            assertTrue(watcher.Closed);
        }
Пример #3
0
 private void Watch(TestFileSystemWatcher watcher)
 {
     try
     {
         watcher.StartWatching();
     }
     catch (InterruptedException)
     {
         // expected
     }
 }
Пример #4
0
    public static void FileSystemWatcher_OnRenamed()
    {
        using (TestFileSystemWatcher watcher = new TestFileSystemWatcher())
        {
            bool             eventOccured = false;
            object           obj = null;
            RenamedEventArgs actualArgs = null, expectedArgs = new RenamedEventArgs(WatcherChangeTypes.Renamed, "directory", "file", "oldFile");

            watcher.Renamed += (o, e) =>
            {
                eventOccured = true;
                obj          = o;
                actualArgs   = e;
            };

            watcher.CallOnRenamed(expectedArgs);
            Assert.True(eventOccured, "Event should be invoked");
            Assert.Equal(watcher, obj);
            Assert.Equal(expectedArgs, actualArgs);
        }
    }
Пример #5
0
    public static void FileSystemWatcher_OnError()
    {
        using (TestFileSystemWatcher watcher = new TestFileSystemWatcher())
        {
            bool           eventOccured = false;
            object         obj = null;
            ErrorEventArgs actualArgs = null, expectedArgs = new ErrorEventArgs(new Exception());

            watcher.Error += (o, e) =>
            {
                eventOccured = true;
                obj          = o;
                actualArgs   = e;
            };

            watcher.CallOnError(expectedArgs);
            Assert.True(eventOccured, "Event should be invoked");
            Assert.Equal(watcher, obj);
            Assert.Equal(expectedArgs, actualArgs);
        }
    }
Пример #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void skipEmptyEvent() throws InterruptedException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void SkipEmptyEvent()
        {
            TestFileSystemWatcher watcher = CreateWatcher();

            AssertableFileEventListener listener = new AssertableFileEventListener();

            watcher.AddFileWatchEventListener(listener);

            TestWatchEvent <string> @event = new TestWatchEvent(ENTRY_MODIFY, null);
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: TestWatchKey watchKey = new TestWatchKey(asList(event));
            TestWatchKey watchKey = new TestWatchKey(new IList <WatchEvent <object> > {
                @event
            });

            PrepareWatcher(watchKey);

            Watch(watcher);

            listener.AssertNoEvents();
        }
Пример #7
0
    public static void FileSystemWatcher_OnRenamed()
    {
        using (TestFileSystemWatcher watcher = new TestFileSystemWatcher())
        {
            bool eventOccured = false;
            object obj = null;
            RenamedEventArgs actualArgs = null, expectedArgs = new RenamedEventArgs(WatcherChangeTypes.Renamed, "directory", "file", "oldFile");

            watcher.Renamed += (o, e) =>
            {
                eventOccured = true;
                obj = o;
                actualArgs = e;
            };

            watcher.CallOnRenamed(expectedArgs);
            Assert.True(eventOccured, "Event should be invoked");
            Assert.Equal(watcher, obj);
            Assert.Equal(expectedArgs, actualArgs);
        }
    }
Пример #8
0
    public static void FileSystemWatcher_OnError()
    {
        using (TestFileSystemWatcher watcher = new TestFileSystemWatcher())
        {
            bool eventOccured = false;
            object obj = null;
            ErrorEventArgs actualArgs = null, expectedArgs = new ErrorEventArgs(new Exception());

            watcher.Error += (o, e) =>
            {
                eventOccured = true;
                obj = o;
                actualArgs = e;
            };

            watcher.CallOnError(expectedArgs);
            Assert.True(eventOccured, "Event should be invoked");
            Assert.Equal(watcher, obj);
            Assert.Equal(expectedArgs, actualArgs);
        }
    }