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 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 ProcessLine(string line) { currentActivity.Name = line; currentActivity.Stop(); lastActivity = currentActivity; currentActivity = RunningActivity.After(currentActivity, ""); Save(); }
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); }
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); } }
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); }
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 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); }
/// <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); }
/// <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); }
private void StartNext(string nextActivityName) { previousActivity = currentActivity; currentActivity = RunningActivity.After(previousActivity, nextActivityName); }
public static RunningActivity After(RunningActivity previous, string name) { return new RunningActivity(name, previous); }
/// <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; }
private RunningActivity(string name, RunningActivity previous) { Name = name; this.timeSystem = previous.timeSystem; this.start = previous.start + previous.duration; }
public void ActivityRecordsStartTime() { Stub.On(mockTimeSystem).GetProperty("Now").Will(Return.Value(startTime)); activity = new RunningActivity("test activity", mockTimeSystem); Assert.AreEqual(startTime, activity.Start); }
private RunningActivity(string name, RunningActivity previous) { Name = name; this.start = previous.start + previous.duration; }
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 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); }
public Interpreter(ITimeSystem timeSystem) { Load(); this.timeSystem = timeSystem; currentActivity = new RunningActivity("", timeSystem); }
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); }