private void UpdateProcessWatch(IEnumerable <IProcessWatch> processWatches) { IEnumerable <IProcessWatch> processToRemove = ProcessesUnderWatch.Except(processWatches); IEnumerable <IProcessWatch> processToAdd = processWatches.Except(ProcessesUnderWatch); IEnumerable <IProcessWatch> processToUpdate = ProcessesUnderWatch.Union(processWatches); processToAdd.ToList().ForEach(p => _processWatcher.AddProcessToWatchList(p.ProcessName, p.DoCapture)); processToRemove.ToList().ForEach(p => _processWatcher.RemoveProcessFromWatchList(p.ProcessName)); processToUpdate.ToList().ForEach(p => _processWatcher.UpdateProcessCaptureInWatchList(p.ProcessName, p.DoCapture)); ProcessesUnderWatch = _processWatcher.GetProcessUnderWatch(); }
public void GivenNotRunningProcess_WhenAddProcessWatch_ProcessIsNotRunning() { const string processName = "NOT_A_PROCESS"; IProcessWatcher watchdog = GivenProcessWatcher(); watchdog.AddProcessToWatchList(processName, false); IEnumerable <IProcessWatch> processWatches = watchdog.GetProcessUnderWatch(); IProcessWatch processWatch = processWatches.SingleOrDefault(pw => pw.ProcessName.Equals(processName)); Assert.False(processWatch?.IsRunning); }
public void GivenAddedProcessWatchWithNoCapture_WhenStartCapture_CaptureDeviceFilterDoesntChange() { Process runningProcess = ProcessWatchTestHelper.GivenFirstRunningProcess(); IProcessWatcher watchdog = GivenProcessWatcher(); watchdog.AddProcessToWatchList(runningProcess.ProcessName, false); watchdog.StartCapture(); WatchJobHandler.Invoke(null, new EventArgs() as ElapsedEventArgs); Assert.Equal(string.Empty, CaptureDeviceFilter); }
public void GivenRunningProcess_WhenAddProcessWatch_ProcessIsRunning() { IProcessWatcher watchdog = GivenProcessWatcher(); Process runningProcess = ProcessWatchTestHelper.GivenFirstRunningProcess(); watchdog.AddProcessToWatchList(runningProcess.ProcessName, false); IEnumerable <IProcessWatch> processWatches = watchdog.GetProcessUnderWatch(); IProcessWatch processWatch = processWatches.SingleOrDefault(pw => pw.ProcessName.Equals(runningProcess.ProcessName)); Assert.True(processWatch?.IsRunning); Assert.Equal(2, processWatches.Count()); }
public void GivenUpdateProcessWatchToNoCapture_WhenStartCapture_ThenItRemovesProcessPortsFromWatchList() { Process runningProcess = ProcessWatchTestHelper.GivenFirstRunningProcess(); IProcessWatcher watchdog = GivenProcessWatcher(); watchdog.AddProcessToWatchList(runningProcess.ProcessName, true); watchdog.UpdateProcessCaptureInWatchList(runningProcess.ProcessName, false); watchdog.StartCapture(); WatchJobHandler.Invoke(null, new EventArgs() as ElapsedEventArgs); Assert.Equal(string.Empty, CaptureDeviceFilter); }
public void GivenProcessUnderWatch_WhenRemoveProcess_ThenItRemovesProperly() { Process runningProcess = ProcessWatchTestHelper.GivenFirstRunningProcess(); IProcessWatcher watchdog = GivenProcessWatcher(); watchdog.AddProcessToWatchList(runningProcess.ProcessName, false); IEnumerable <IProcessWatch> processWatches = watchdog.GetProcessUnderWatch(); Assert.Equal(2, processWatches.Count()); watchdog.RemoveProcessFromWatchList(runningProcess.ProcessName); processWatches = watchdog.GetProcessUnderWatch(); Assert.Single(processWatches); }