public void HandleSessionEvents() { CustomClock clock = new CustomClock(new DateTime(2012, 1, 1, 1, 1, 1)); _context = new NotifyIconApplicationContext(clock, true); Console.WriteLine("Session locked at " + clock.Now); int eventCount = _context.TimeTracker.GetEvents().Count; _context.SessionEventOccurred(this, new SessionSwitchEventArgs(SessionSwitchReason.SessionLock)); Assert.That(_context.TimeTracker.LastEvent.Type, Is.EqualTo(TrackableEvent.EventType.Lock)); Assert.That(_context.TimeTracker.StartTime, Is.EqualTo(clock.Now)); Assert.That(_context.TimeTracker.GetEvents().Count, Is.EqualTo(++eventCount)); // Verify that the start time remains unchanged when a Lock event is received the following day clock.Now = clock.Now.AddDays(1); Console.WriteLine("Session locked at " + clock.Now); DateTime startTimeBefore = _context.TimeTracker.StartTime; _context.SessionEventOccurred(this, new SessionSwitchEventArgs(SessionSwitchReason.SessionLock)); Assert.That(_context.TimeTracker.LastEvent.Type, Is.EqualTo(TrackableEvent.EventType.Lock)); Assert.That(_context.TimeTracker.StartTime, Is.EqualTo(startTimeBefore)); Assert.That(_context.TimeTracker.GetEvents().Count, Is.EqualTo(++eventCount)); // Verify that the start time is updated when an Unlock event is received the following day clock.Now = clock.Now.AddHours(1); Console.WriteLine("Session unlocked at " + clock.Now); _context.SessionEventOccurred(this, new SessionSwitchEventArgs(SessionSwitchReason.SessionUnlock)); Assert.That(_context.TimeTracker.LastEvent.Type, Is.EqualTo(TrackableEvent.EventType.Start)); Assert.That(_context.TimeTracker.StartTime, Is.EqualTo(clock.Now)); Assert.That(_context.TimeTracker.GetEvents().Count, Is.EqualTo(1)); // Verify that the remote connection event is ignored TrackableEvent.EventType lastType = _context.TimeTracker.LastEvent.Type; eventCount = _context.TimeTracker.GetEvents().Count; Console.WriteLine("Remote connection"); _context.SessionEventOccurred(this, new SessionSwitchEventArgs(SessionSwitchReason.RemoteConnect)); Assert.That(_context.TimeTracker.LastEvent.Type, Is.EqualTo(lastType)); Assert.That(_context.TimeTracker.GetEvents().Count, Is.EqualTo(eventCount)); }
public void CheckThatEventsAreStored() { CustomClock clock = new CustomClock(new DateTime(2012, 1, 1, 1, 1, 1)); Console.WriteLine("Starting application at " + clock.Now); _context = new NotifyIconApplicationContext(clock, true); clock.Now = clock.Now.AddHours(1); _context.SessionEventOccurred(this, new SessionSwitchEventArgs(SessionSwitchReason.SessionLock)); clock.Now = clock.Now.AddHours(1); _context.SessionEventOccurred(this, new SessionSwitchEventArgs(SessionSwitchReason.SessionUnlock)); int eventCount = _context.TimeTracker.GetEvents().Count; Console.WriteLine("Exiting application at " + clock.Now + ", " + eventCount + " events tracked"); _context.Exit(); clock.Now = clock.Now.AddHours(1); Console.WriteLine("Restarting application at " + clock.Now); _context = new NotifyIconApplicationContext(clock, false); Assert.That(_context.TimeTracker.GetEvents().Count, Is.EqualTo(eventCount)); }