コード例 #1
0
        private static void Main(string[] args)
        {
            WatchDirectory watchDir = new WatchDirectory();

            ThreadPool.QueueUserWorkItem((e) =>
            {
                watchDir.StartDirectoryWatcher();
            });
            var key = Console.ReadKey();

            watchDir.Stop();
        }
コード例 #2
0
        public void Watcher_StartDirectoryWatcher_ShouldHandleEvent()
        {
            // Arrange
            var watchDirectory = new WatchDirectory(_fileProcessorMoq.Object);

            // Act
            ThreadPool.QueueUserWorkItem((e) =>
            {
                Thread.Sleep(2000);
                using (var file = File.CreateText(Path.Combine(watchDirectory.WorkDirectory, "test.txt")))
                {
                    file.WriteLine("Hello from test method: Watcher_StartDirectoryWatcher_ShouldHandleEvent  ");
                }
                Thread.Sleep(1000);
                watchDirectory.Stop();
            });

            watchDirectory.StartDirectoryWatcher();

            // Assert
            _fileProcessorMoq.Verify(x => x.Process(It.IsAny <string>()));
        }