예제 #1
0
        public void ChangeTimePeriodWorkTimeStatus()
        {
            Clock clock = new CustomClock(DateTime.Now);
              _context = new NotifyIconApplicationContext(clock);
              TimeTracker tracker = _context.TimeTracker;

              // Add some events
              for (int i = 0; i < 3; i++)
              {
            clock.Now = clock.Now.AddMinutes(1);
            tracker.AddEvent(new TrackableEvent(TrackableEvent.EventType.Lock, clock.Now));
            clock.Now = clock.Now.AddMinutes(1);
            tracker.AddEvent(new TrackableEvent(TrackableEvent.EventType.Unlock, clock.Now));
              }

              // Change all time periods to be non-work
              clock.Now = clock.Now.AddMinutes(1);
              foreach (TimePeriod period in tracker.GetPeriods(clock.Now))
              {
            period.IsWorkTime = false;
              }
              Assert.That(tracker.GetWorkTime(clock.Now), Is.EqualTo(new TimeSpan()));

              // Change some periods to work time
              clock.Now = clock.Now.AddMinutes(1);
              IList<TimePeriod> periods = tracker.GetPeriods(clock.Now);
              TimeSpan workTime = new TimeSpan();
              workTime = SetPeriodToWorkTime(periods, 0, workTime);
              workTime = SetPeriodToWorkTime(periods, periods.Count - 1, workTime);
              workTime = SetPeriodToWorkTime(periods, periods.Count / 2, workTime);
              Assert.That(tracker.GetWorkTime(clock.Now), Is.EqualTo(workTime));
        }
예제 #2
0
        public void CheckNonCompletedPeriodDuration()
        {
            Clock clock = new CustomClock(DateTime.Now);
              _context = new NotifyIconApplicationContext(clock, true);
              DateTime startTime = clock.Now;

              TimeSpan duration = new TimeSpan(1, 1, 1);
              Assert.That(_context.TimeTracker.GetPeriods(startTime.Add(duration))[0].Duration,
                  Is.EqualTo(duration));

              duration = duration.Add(new TimeSpan(1, 1, 1));
              Assert.That(_context.TimeTracker.GetPeriods(startTime.Add(duration))[0].Duration,
                  Is.EqualTo(duration));
        }
예제 #3
0
 public void RunApplication()
 {
     _context = new NotifyIconApplicationContext(new SystemClock());
       _context.ShowReport(null, null);
 }
예제 #4
0
        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));
        }
예제 #5
0
 public void Init()
 {
     _context = null;
 }
예제 #6
0
        public void CloseMainForm()
        {
            _context = new NotifyIconApplicationContext(new SystemClock());

              Console.WriteLine("User closing main form");
              FormClosingEventArgs e1 = new FormClosingEventArgs(CloseReason.UserClosing, false);
              _context.MainForm.MainFormClosing(this, e1);
              Assert.That(e1.Cancel, Is.True);

              Console.WriteLine("Windows shutdown closing main form");
              FormClosingEventArgs e2 = new FormClosingEventArgs(CloseReason.WindowsShutDown, false);
              _context.MainForm.MainFormClosing(this, e2);
              Assert.That(e2.Cancel, Is.False);
        }
예제 #7
0
        public void CheckTrackedStateAfterDayChange()
        {
            // Run the application, forcing the start time to be updated
              CustomClock clock = new CustomClock(new DateTime(2012, 1, 1, 1, 1, 1));
              Console.WriteLine("Launching application at " + clock.Now);
              _context = new NotifyIconApplicationContext(clock, true);
              TimeTracker tracker = _context.TimeTracker;

              // Add some events on the same day
              clock.Now = clock.Now.AddMinutes(1);
              tracker.AddEvent(new TrackableEvent(TrackableEvent.EventType.Lock, clock.Now));
              clock.Now = clock.Now.AddMinutes(1);
              tracker.AddEvent(new TrackableEvent(TrackableEvent.EventType.Unlock, clock.Now));

              // Add some events the next day
              clock.Now = clock.Now.AddDays(1);
              Console.WriteLine("Adding unlock event the next day at " + clock.Now);
              _context.AddEvent(new TrackableEvent(TrackableEvent.EventType.Unlock, clock.Now));
              clock.Now = clock.Now.AddSeconds(1);

              Assert.That(tracker.GetEvents().Count, Is.EqualTo(1));
              Assert.That(tracker.GetPeriods(clock.Now).Count, Is.EqualTo(1));
              Assert.That(tracker.LastCompletedTimePeriod, Is.EqualTo(null));
        }
예제 #8
0
        public void CheckTimePeriods()
        {
            _context = new NotifyIconApplicationContext(new SystemClock());

              TimeTracker tracker = _context.TimeTracker;
              CheckLastPeriod(tracker, TrackableEvent.EventType.Lock);
              CheckLastPeriod(tracker, TrackableEvent.EventType.Lock);
              CheckLastPeriod(tracker, TrackableEvent.EventType.Unlock);
              CheckLastPeriod(tracker, TrackableEvent.EventType.Unlock);
        }
예제 #9
0
        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));
        }
예제 #10
0
        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
        }