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)); }
public void CheckStartTimeAfterRestarts() { // Run the application, forcing the start time to be updated DateTime launchTime1 = new DateTime(2012, 1, 1, 1, 1, 1); CustomClock clock = new CustomClock(launchTime1); Console.WriteLine("Launching application at " + clock.Now); _context = new NotifyIconApplicationContext(clock, true); Assert.That(_context.TimeTracker.StartTime, Is.EqualTo(launchTime1)); _context.Exit(); // Run the application again on the same day DateTime launchTime2 = launchTime1.AddMinutes(1); clock.Now = launchTime2; Console.WriteLine("Launching application at " + clock.Now); _context = new NotifyIconApplicationContext(clock); Assert.That(_context.TimeTracker.StartTime, Is.EqualTo(launchTime1)); _context.Exit(); // Run the application again on the next day DateTime launchTime3 = launchTime1.AddDays(1); clock.Now = launchTime3; Console.WriteLine("Launching application at " + clock.Now); _context = new NotifyIconApplicationContext(clock); Assert.That(_context.TimeTracker.StartTime, Is.EqualTo(launchTime3)); // The context will be exited in TearDown }