示例#1
0
        public void StartTimeAtTheEndOfMinute()
        {
            Stub.On(mockTimeSystem).GetProperty("Now").Will(Return.Value(DateTime.Parse("17:59:59.500")));

            activity = new RunningActivity("name", mockTimeSystem);

            Assert.AreEqual(DateTime.Parse("18:00:00"), activity.Start);
        }
示例#2
0
 public void StopActivity()
 {
     Stub.On(mockTimeSystem).GetProperty("Now").Will(Return.Value(startTime));
     activity = new RunningActivity("test activity", mockTimeSystem);
     Assert.IsTrue(activity.IsRunning);
     activity.Stop();
     Assert.IsFalse(activity.IsRunning);
 }
示例#3
0
 public void ProcessLine(string line)
 {
     currentActivity.Name = line;
     currentActivity.Stop();
     lastActivity = currentActivity;
     currentActivity = RunningActivity.After(currentActivity, "");
     Save();
 }
示例#4
0
        public void SplitNames()
        {
            Stub.On(mockTimeSystem).GetProperty("Now").Will(Return.Value(startTime));
            activity = new RunningActivity("first,second", mockTimeSystem);
            activity.Stop();
            RunningActivity second = activity.SplitByComma()[1];

            Assert.AreEqual("first", activity.Name);
            Assert.AreEqual("second", second.Name);
        }
示例#5
0
 public TimeManager(ITimeSystem timeSystem, ITimeLogsManager timeLogsManager)
 {
     currentActivity = new RunningActivity(FIRST_ACTIVITY, timeSystem);
     midnightCorrector = new MidnightSwitcher();
     if (timeLogsManager != null)
     {
         TimeLogsManager = timeLogsManager;
         timeLogsManager.ActivateTimeLog(currentActivity.Start.Date);
     }
 }
示例#6
0
 public void MillisecondsAreRounded()
 {
     using (mocks.Ordered)
     {
         Expect.Once.On(mockTimeSystem).GetProperty("Now").Will(Return.Value(DateTime.Parse("2007-11-18 5:00:00")));
         Expect.Once.On(mockTimeSystem).GetProperty("Now").Will(Return.Value(DateTime.Parse("2007-11-18 5:07:00.5")));
     }
     activity = new RunningActivity("activity", mockTimeSystem);
     activity.Stop();
     Assert.AreEqual(TimeSpan.Parse("0:07:01"), activity.Duration);
 }
 public void MillisecondsAreRounded()
 {
     using (mocks.Ordered)
     {
         Expect.Once.On(mockTimeSystem).GetProperty("Now").Will(Return.Value(DateTime.Parse("2007-11-18 5:00:00")));
         Expect.Once.On(mockTimeSystem).GetProperty("Now").Will(Return.Value(DateTime.Parse("2007-11-18 5:07:00.5")));
     }
     activity = new RunningActivity("activity", mockTimeSystem);
     activity.Stop();
     Assert.AreEqual(TimeSpan.Parse("0:07:01"), activity.Duration);
 }
 public void Split3()
 {
     using (mocks.Ordered)
     {
         Expect.Once.On(mockTimeSystem).GetProperty("Now").Will(Return.Value(DateTime.Parse("7:00:00")));
         Expect.Once.On(mockTimeSystem).GetProperty("Now").Will(Return.Value(DateTime.Parse("8:00:00")));
     }
     activity = new RunningActivity("first, second, third", mockTimeSystem);
     activity.Stop();
     RunningActivity third = activity.SplitByComma()[2];
     Assert.AreEqual(DateTime.Parse("7:40:00"), third.Start);
 }
示例#9
0
        public void Split3()
        {
            using (mocks.Ordered)
            {
                Expect.Once.On(mockTimeSystem).GetProperty("Now").Will(Return.Value(DateTime.Parse("7:00:00")));
                Expect.Once.On(mockTimeSystem).GetProperty("Now").Will(Return.Value(DateTime.Parse("8:00:00")));
            }
            activity = new RunningActivity("first, second, third", mockTimeSystem);
            activity.Stop();
            RunningActivity third = activity.SplitByComma()[2];

            Assert.AreEqual(DateTime.Parse("7:40:00"), third.Start);
        }
示例#10
0
 public void ThereIsNoNegativeDuration()
 {
     using (mocks.Ordered)
     {
         Expect.Once.On(mockTimeSystem).GetProperty("Now").Will(
             Return.Value(DateTime.Parse("2111-11-11 5:00:00")));
         Expect.Once.On(mockTimeSystem).GetProperty("Now").Will(
             Return.Value(DateTime.Parse("2111-11-11 5:00:00.6")));
         Expect.Once.On(mockTimeSystem).GetProperty("Now").Will(
             Return.Value(DateTime.Parse("2111-11-11 5:00:00.7")));
     }
     activity = new RunningActivity("first", mockTimeSystem);
     activity.Stop();
     activity = RunningActivity.After(activity, "second");
     Assert.AreEqual(TimeSpan.Parse("0:00:00"), activity.Duration);
 }
示例#11
0
        public void SplitTime()
        {
            using (mocks.Ordered)
            {
                Expect.Once.On(mockTimeSystem).GetProperty("Now").Will(Return.Value(DateTime.Parse("7:00:00")));
                Expect.Once.On(mockTimeSystem).GetProperty("Now").Will(Return.Value(DateTime.Parse("8:00:00")));
            }
            activity = new RunningActivity("first, second", mockTimeSystem);
            activity.Stop();
            RunningActivity second = activity.SplitByComma()[1];

            Assert.AreEqual(DateTime.Parse("7:00:00"), activity.Start);
            Assert.AreEqual(DateTime.Parse("7:30:00"), activity.End, "first end");
            Assert.AreEqual(DateTime.Parse("7:30:00"), second.Start, "second start");
            Assert.AreEqual(DateTime.Parse("8:00:00"), second.End);
        }
示例#12
0
 /// <summary>
 /// Split running activity by comma and returns array of activities
 /// </summary>
 /// <returns>array of activities, created after split</returns>
 public RunningActivity[] SplitByComma()
 {
     string[]          names = Name.Split(',');
     RunningActivity[] next  = new RunningActivity[names.Length];
     if (names.Length > 0)
     {
         this.Name = names[0];
         TimeSpan totalDuration = this.duration;
         this.duration = TimeSpan.FromMilliseconds(totalDuration.TotalMilliseconds / names.Length);
         next[0]       = this;
         for (int i = 1; i < names.Length; i++)
         {
             next[i]           = RunningActivity.After(next[i - 1], names[i]);
             next[i].IsRunning = false;
             next[i].duration  = this.duration;
         }
     }
     return(next);
 }
示例#13
0
 /// <summary>
 /// Check current activity for comma and split if necessary
 /// <returns>list of additional activities created by split by comma or empty array</returns>
 /// </summary>
 private List<IActivity> CheckForComma()
 {
     RunningActivity[] additionalActivities = (splitByComma) ?
         currentActivity.SplitByComma() :
         new RunningActivity[]{currentActivity};
     foreach (RunningActivity additionalActivity in additionalActivities)
     {
         CheckForMidnight();
         currentActivity = additionalActivity;
         AddToTimeLog();
     }
     return new List<IActivity>(additionalActivities);
 }
示例#14
0
 private void StartNext(string nextActivityName)
 {
     previousActivity = currentActivity;
     currentActivity = RunningActivity.After(previousActivity, nextActivityName);
 }
示例#15
0
 public static RunningActivity After(RunningActivity previous, string name)
 {
     return new RunningActivity(name, previous);
 }
示例#16
0
 /// <summary>
 /// Split running activity by comma and returns array of activities
 /// </summary>
 /// <returns>array of activities, created after split</returns>
 public RunningActivity[] SplitByComma()
 {
     string[] names = Name.Split(',');
     RunningActivity[] next = new RunningActivity[names.Length];
     if (names.Length > 0)
     {
         this.Name = names[0];
         TimeSpan totalDuration = this.duration;
         this.duration = TimeSpan.FromMilliseconds(totalDuration.TotalMilliseconds / names.Length);
         next[0] = this;
         for (int i = 1; i < names.Length; i++)
         {
             next[i] = RunningActivity.After(next[i - 1], names[i]);
             next[i].IsRunning = false;
             next[i].duration = this.duration;
         }
     }
     return next;
 }
 public void SplitNames()
 {
     Stub.On(mockTimeSystem).GetProperty("Now").Will(Return.Value(startTime));
     activity = new RunningActivity("first,second", mockTimeSystem);
     activity.Stop();
     RunningActivity second = activity.SplitByComma()[1];
     Assert.AreEqual("first", activity.Name);
     Assert.AreEqual("second", second.Name);
 }
示例#18
0
 private RunningActivity(string name, RunningActivity previous)
 {
     Name = name;
     this.timeSystem = previous.timeSystem;
     this.start = previous.start + previous.duration;
 }
示例#19
0
 public void ActivityRecordsStartTime()
 {
     Stub.On(mockTimeSystem).GetProperty("Now").Will(Return.Value(startTime));
     activity = new RunningActivity("test activity", mockTimeSystem);
     Assert.AreEqual(startTime, activity.Start);
 }
示例#20
0
 private RunningActivity(string name, RunningActivity previous)
 {
     Name       = name;
     this.start = previous.start + previous.duration;
 }
示例#21
0
 public void SplitByCommaWhenNoComma()
 {
     Stub.On(mockTimeSystem).GetProperty("Now").Will(Return.Value(startTime));
     activity = new RunningActivity("just one", mockTimeSystem);
     Assert.AreEqual(1, activity.SplitByComma().Length);
 }
 public void ThereIsNoNegativeDuration()
 {
     using (mocks.Ordered)
     {
         Expect.Once.On(mockTimeSystem).GetProperty("Now").Will(
             Return.Value(DateTime.Parse("2111-11-11 5:00:00")));
         Expect.Once.On(mockTimeSystem).GetProperty("Now").Will(
             Return.Value(DateTime.Parse("2111-11-11 5:00:00.6")));
         Expect.Once.On(mockTimeSystem).GetProperty("Now").Will(
             Return.Value(DateTime.Parse("2111-11-11 5:00:00.7")));
     }
     activity = new RunningActivity("first",mockTimeSystem);
     activity.Stop();
     activity = RunningActivity.After(activity, "second");
     Assert.AreEqual(TimeSpan.Parse("0:00:00"),activity.Duration);
 }
 public void ActivityRecordsStartTime()
 {
     Stub.On(mockTimeSystem).GetProperty("Now").Will(Return.Value(startTime));
     activity = new RunningActivity("test activity", mockTimeSystem);
     Assert.AreEqual(startTime, activity.Start);
 }
        public void StartTimeAtTheEndOfMinute()
        {
            Stub.On(mockTimeSystem).GetProperty("Now").Will(Return.Value(DateTime.Parse("17:59:59.500")));

            activity = new RunningActivity("name",mockTimeSystem);

            Assert.AreEqual(DateTime.Parse("18:00:00"), activity.Start);
        }
 public void SplitByCommaWhenNoComma()
 {
     Stub.On(mockTimeSystem).GetProperty("Now").Will(Return.Value(startTime));
     activity = new RunningActivity("just one", mockTimeSystem);
     Assert.AreEqual(1,activity.SplitByComma().Length);
 }
 public void StartTimeIsRounded()
 {
     Expect.Once.On(mockTimeSystem).GetProperty("Now").Will(Return.Value(DateTime.Parse("2111-11-11 5:00:00.5")));
     activity = new RunningActivity("activity", mockTimeSystem);
     Assert.AreEqual(DateTime.Parse("2111-11-11 5:00:01"), activity.Start);
 }
示例#27
0
 public Interpreter(ITimeSystem timeSystem)
 {
     Load();
     this.timeSystem = timeSystem;
     currentActivity = new RunningActivity("", timeSystem);
 }
示例#28
0
 public static RunningActivity After(RunningActivity previous, string name)
 {
     return(new RunningActivity(name, previous));
 }
 public void StopActivity()
 {
     Stub.On(mockTimeSystem).GetProperty("Now").Will(Return.Value(startTime));
     activity = new RunningActivity("test activity",mockTimeSystem);
     Assert.IsTrue(activity.IsRunning);
     activity.Stop();
     Assert.IsFalse(activity.IsRunning);
 }
 public void SplitTime()
 {
     using (mocks.Ordered)
     {
         Expect.Once.On(mockTimeSystem).GetProperty("Now").Will(Return.Value(DateTime.Parse("7:00:00")));
         Expect.Once.On(mockTimeSystem).GetProperty("Now").Will(Return.Value(DateTime.Parse("8:00:00")));
     }
     activity = new RunningActivity("first, second", mockTimeSystem);
     activity.Stop();
     RunningActivity second = activity.SplitByComma()[1];
     Assert.AreEqual(DateTime.Parse("7:00:00"), activity.Start);
     Assert.AreEqual(DateTime.Parse("7:30:00"), activity.End, "first end");
     Assert.AreEqual(DateTime.Parse("7:30:00"), second.Start, "second start");
     Assert.AreEqual(DateTime.Parse("8:00:00"), second.End);
 }
示例#31
0
 public void StartTimeIsRounded()
 {
     Expect.Once.On(mockTimeSystem).GetProperty("Now").Will(Return.Value(DateTime.Parse("2111-11-11 5:00:00.5")));
     activity = new RunningActivity("activity", mockTimeSystem);
     Assert.AreEqual(DateTime.Parse("2111-11-11 5:00:01"), activity.Start);
 }