File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . Collections . Concurrent ;
3+ using System . Collections . Generic ;
4+ using System . Reflection ;
5+ using Xunit ;
6+
7+ namespace EventViewerX . Tests {
8+ public class TestWatchEvents {
9+ private static ConcurrentBag < int > GetIds ( WatchEvents watcher ) {
10+ var field = typeof ( WatchEvents ) . GetField ( "_watchEventId" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
11+ Assert . NotNull ( field ) ;
12+ return ( ConcurrentBag < int > ) field ! . GetValue ( watcher ) ! ;
13+ }
14+
15+ [ Fact ]
16+ public void DisposeClearsWatchEventIds ( ) {
17+ var watcher = new WatchEvents ( ) ;
18+ watcher . Watch ( Environment . MachineName , "Application" , new List < int > { 1 } ) ;
19+ watcher . Dispose ( ) ;
20+ var ids = GetIds ( watcher ) ;
21+ Assert . Empty ( ids ) ;
22+ }
23+
24+ [ Fact ]
25+ public void SubsequentWatchesUseNewIdsOnly ( ) {
26+ var watcher = new WatchEvents ( ) ;
27+ watcher . Watch ( Environment . MachineName , "Application" , new List < int > { 1 } ) ;
28+ watcher . Watch ( Environment . MachineName , "Application" , new List < int > { 2 } ) ;
29+ var ids = GetIds ( watcher ) ;
30+ Assert . DoesNotContain ( 1 , ids ) ;
31+ Assert . Contains ( 2 , ids ) ;
32+ }
33+ }
34+ }
Original file line number Diff line number Diff line change @@ -83,6 +83,7 @@ public void Dispose() {
8383 _eventLogWatcher . Dispose ( ) ;
8484 _eventLogWatcher = null ;
8585 }
86+ _watchEventId = new ConcurrentBag < int > ( ) ;
8687 _eventLogSession ? . Dispose ( ) ;
8788 _eventLogSession = null ;
8889 }
You can’t perform that action at this time.
0 commit comments