Ejemplo n.º 1
0
        public void it_should_calculate_correct_hours_left_to_zero()
        {
            var now = DateTime.Now;
            var target = new GoalProcessor(now);
            var goal = new Goal() { Amount = 7, IntervalType = IntervalType.Weekly };

            // Week
            goal.DoneIts = new List<DoneIt>() { new DoneIt() { Amount = 7.01M, Date = now.AddDays(-7) } };
            var vm = target.ProcessGoal(goal);
            Assert.AreEqual(GoalStatus.OnTrack, vm.Status);

            goal.DoneIts = new List<DoneIt>(){ new DoneIt() { Amount = 6.99M, Date = now.AddDays(-7) }};
            vm = target.ProcessGoal(goal);
            Assert.AreEqual(GoalStatus.Behind, vm.Status);

            // Hour
            goal = new Goal() { Amount = 24, IntervalType = IntervalType.Dayly };
            goal.DoneIts = new List<DoneIt>() { new DoneIt() { Amount = 24.01M, Date = now.AddDays(-1) } };
            vm = target.ProcessGoal(goal);
            Assert.AreEqual(GoalStatus.OnTrack, vm.Status);

            goal.DoneIts = new List<DoneIt>() { new DoneIt() { Amount = 23.99M, Date = now.AddDays(-1) } };
            vm = target.ProcessGoal(goal);
            Assert.AreEqual(GoalStatus.Behind, vm.Status);

            // Month
            goal = new Goal() { Amount = 3, IntervalType = IntervalType.Monthly };
            goal.DoneIts = new List<DoneIt>() { new DoneIt() { Amount = 3.01M, Date = now.AddDays(-30) } };
            vm = target.ProcessGoal(goal);
            Assert.AreEqual(GoalStatus.OnTrack, vm.Status);

            goal.DoneIts = new List<DoneIt>() { new DoneIt() { Amount = 2.99M, Date = now.AddDays(-30) } };
            vm = target.ProcessGoal(goal);
            Assert.AreEqual(GoalStatus.Behind, vm.Status);
        }
Ejemplo n.º 2
0
        public void it_should_build_a_flat_zero_line_if_no_donits()
        {
            var now = DateTime.Now;
            var target = new GoalProcessor(now);
            var goal = new Goal() { IntervalType = IntervalType.Weekly };

            var vm= target.ProcessGoal(goal);
            Assert.AreEqual(vm.Graph.Points.Count, 2);
        }
Ejemplo n.º 3
0
        public void it_should_set_value_of_first_point_to_the_amount_the_first_doneit()
        {
            var now = DateTime.Now;
            var target = new GoalProcessor(now);
            var goal = new Goal() { Amount = 7, IntervalType = IntervalType.Weekly };

            goal.DoneIts = new List<DoneIt>() { new DoneIt() { Amount = 10, Date = now.AddDays(-2) } };
            var vm = target.ProcessGoal(goal);
            Assert.AreEqual(10, vm.Graph.Points.Where(p => p.Time == now.AddDays(-2).AddSeconds(1)).FirstOrDefault().Amount);
        }
Ejemplo n.º 4
0
        public ActionResult Index()
        {
            var vm = new HomeViewModel();
            var logic = new GoalProcessor();
            var goals =  db.Goals.Include("DoneIts").Where(x => x.UserName == User.Identity.Name && x.Enabled).ToList();
            foreach (var goal in goals)
            {
                vm.Goals.Add(logic.ProcessGoal(goal));
            }
            vm.OverallStatus = logic.FindOverallStatus(vm.Goals);

            return View(vm);
        }
Ejemplo n.º 5
0
        public void it_should_calcualte_cutofftime_correct()
        {
            var now = DateTime.Now;
            var firstDoneit = new DateTime(2012, 5, 27);
            var target = new GoalProcessor(now);
            var goal = new Goal() { Amount = 1, IntervalType = IntervalType.Dayly };

            var calculated = target.CalculateLowerCutoffTime(goal, 1, firstDoneit);
            AssertTimesAreAlmostEqual(firstDoneit.AddDays(3), calculated);

            calculated = target.CalculateLowerCutoffTime(goal, 0, now);
            AssertTimesAreAlmostEqual(now.AddDays(2), calculated);

            calculated = target.CalculateLowerCutoffTime(goal, 1M, now.AddDays(-10));
            AssertTimesAreAlmostEqual(now.AddDays(-7), calculated);
        }
Ejemplo n.º 6
0
        public void it_should_increase_hours_left_when_adding_a_new_doneit()
        {
            var now = DateTime.Now;
            var target = new GoalProcessor(now);

            // Week
            var goal = new Goal() { Amount = 7, IntervalType = IntervalType.Weekly };
            goal.DoneIts = new List<DoneIt>() { new DoneIt() { Amount = 3.01M, Date = now.AddDays(-7) } };
            goal.DoneIts.Add(new DoneIt() { Amount = 3, Date = now.AddDays(-4) } );
            goal.DoneIts.Add(new DoneIt() { Amount = 1, Date = now.AddDays(-1) });
            var vm = target.ProcessGoal(goal);
            Assert.AreEqual(GoalStatus.OnTrack, vm.Status);

            goal.DoneIts = new List<DoneIt>() { new DoneIt() { Amount = 2.9M, Date = now.AddDays(-7) } };
            goal.DoneIts.Add(new DoneIt() { Amount = 3, Date = now.AddDays(-4) });
            goal.DoneIts.Add(new DoneIt() { Amount = 1, Date = now.AddDays(-1) });
            vm = target.ProcessGoal(goal);
            Assert.AreEqual(GoalStatus.Behind, vm.Status);
        }
Ejemplo n.º 7
0
        public void it_should_show_a_stright_line_when_in_cutoff()
        {
            var now = DateTime.Now;
            var target = new GoalProcessor(now);
            var goal = new Goal() { Amount = 7, IntervalType = IntervalType.Weekly };

            // Simple one entry
            // -28,7
            // -21,0
            // -14,-7
            // -7, -14
            // -6, -14 (cutoff)
            // 0, -14 (cutoff)
            goal.DoneIts = new List<DoneIt>() {
                new DoneIt() { Amount = 7, Date = now.AddDays(-28) } ,
                new DoneIt() { Amount = 0, Date = now.AddDays(-21) } ,
                new DoneIt() { Amount = 0, Date = now.AddDays(-14) } ,
                new DoneIt() { Amount = 0, Date = now.AddDays(-7) } ,
            };
            var vm = target.ProcessGoal(goal);
            // 1: 7
            AssertPointOnGraph(vm, 0, 0, now.AddDays(-28));
            AssertPointOnGraph(vm, 1, 7, now.AddDays(-28));
            // 2: 0
            AssertPointOnGraph(vm, 2, 0, now.AddDays(-21));
            AssertPointOnGraph(vm, 3, 0, now.AddDays(-21));
            // 3: 0
            AssertPointOnGraph(vm, 4, -7, now.AddDays(-14));
            AssertPointOnGraph(vm, 5, -7, now.AddDays(-14));
            // 4: 0
            AssertPointOnGraph(vm, 6, -14, now.AddDays(-7));
            AssertPointOnGraph(vm, 7, -14, now.AddDays(-7));
            // Cutoff
            AssertPointOnGraph(vm, 8, -14, now.AddDays(-7));
            // Cutoff
            AssertPointOnGraph(vm, 9, -14, now.AddDays(-7));
            // Final
            AssertPointOnGraph(vm, 10, -14, now.AddDays(0));
        }
Ejemplo n.º 8
0
        public void it_should_never_go_below_a_configurable_threshold()
        {
            var now = DateTime.Now;
            var target = new GoalProcessor(now);
            var goal = new Goal() { Amount = 7, IntervalType = IntervalType.Weekly };

            // Hour
            goal = new Goal() { Amount = 24, IntervalType = IntervalType.Dayly };
            goal.DoneIts = new List<DoneIt>() { new DoneIt() { Amount = 24.01M, Date = now.AddDays(-1) } };
            var vm = target.ProcessGoal(goal);
            Assert.AreEqual(GoalStatus.OnTrack, vm.Status);
            Assert.IsTrue(Math.Abs(vm.CurrentLevel - 0) < 0.1M);

            goal.DoneIts = new List<DoneIt>() { new DoneIt() { Amount = 23.99M, Date = now.AddDays(-1) } };
            vm = target.ProcessGoal(goal);
            Assert.AreEqual(GoalStatus.Behind, vm.Status);
            Assert.IsTrue(Math.Abs(vm.CurrentLevel - 0) < 0.1M);

            goal.DoneIts = new List<DoneIt>() { new DoneIt() { Amount = 24.01M, Date = now.AddDays(-2) } };
            vm = target.ProcessGoal(goal);
            Assert.IsTrue(Math.Abs(vm.CurrentLevel - -24) < 0.1M);

            // Hour limited by threshold (2*)
            goal.DoneIts = new List<DoneIt>() { new DoneIt() { Amount = 24.01M, Date = now.AddDays(-4) } };
            vm = target.ProcessGoal(goal);
            Assert.IsTrue(Math.Abs(vm.CurrentLevel - -48) < 0.1M);
        }
Ejemplo n.º 9
0
        public void when_no_doneits_it_should_show_status_not_started()
        {
            var target = new GoalProcessor();
            var goal = new Goal() { Amount = 7, IntervalType = IntervalType.Weekly };
            var now = DateTime.Now;

            var vm = target.ProcessGoal(goal);
            Assert.AreEqual(GoalStatus.NotStarted, vm.Status);
            //goal.DoneIts.Add(new DoneIt() { Amount = 1, Date = now.a
        }
Ejemplo n.º 10
0
        public void when_first_doneit_it_should_start_counting_down()
        {
            var now = DateTime.Now;
            var target = new GoalProcessor(now);
            var goal = new Goal() { Amount = 7, IntervalType = IntervalType.Weekly };

            goal.DoneIts.Add(new DoneIt() { Amount = 1, Date = now });

            var vm = target.ProcessGoal(goal);
            Assert.AreEqual(GoalStatus.OnTrack, vm.Status);
        }
Ejemplo n.º 11
0
 public void overallstatus_should_be_showing_worst_case()
 {
     var target = new GoalProcessor();
     Assert.AreEqual(GoalStatus.NoGoalsDefined, target.FindOverallStatus(new List<GoalViewModel>()));
     Assert.AreEqual(GoalStatus.OnTrack, target.FindOverallStatus(new List<GoalViewModel>() { new GoalViewModel { Status=GoalStatus.NotStarted }, new GoalViewModel { Status=GoalStatus.OnTrack} }));
     Assert.AreEqual(GoalStatus.Behind, target.FindOverallStatus(new List<GoalViewModel>() { new GoalViewModel { Status = GoalStatus.Behind }, new GoalViewModel { Status = GoalStatus.OnTrack } }));
 }
Ejemplo n.º 12
0
        public void it_should_show_a_stright_line_when_in_cutoff2()
        {
            var now = DateTime.Now;
            var target = new GoalProcessor(now);
            var goal = new Goal() { Amount = 1, IntervalType = IntervalType.Dayly };

            // Simple one entry
            // -8,1
            goal.DoneIts = new List<DoneIt>() {
                new DoneIt() { Amount = 1, Date = now.AddDays(-10) } ,
            };
            var vm = target.ProcessGoal(goal);
            // Start 0,1
            AssertPointOnGraph(vm, 0, 0, now.AddDays(-10));
            AssertPointOnGraph(vm, 1, 1, now.AddDays(-10));
            //
            AssertPointOnGraph(vm, 2, -2, now.AddDays(-8));
            AssertPointOnGraph(vm, 3, -2, now);
        }
Ejemplo n.º 13
0
        public void it_should_start_one_interval_before_and_end_one_interval_after_if_interval()
        {
            var now = DateTime.Now;
            var target = new GoalProcessor(now);
            var goal = new Goal() { EvaluationType = GoalEvaluation.Countinious, IntervalType = IntervalType.Weekly };

            var vm = target.ProcessGoal(goal);
            Assert.AreEqual(vm.Graph.Points[0].Time, now.AddDays(-14));
            Assert.AreEqual(vm.Graph.Points[1].Time, now.AddDays(7));
            Assert.AreEqual(0, vm.Graph.Points[0].Amount);
            Assert.AreEqual(0, vm.Graph.Points[1].Amount);

            goal = new Goal() { EvaluationType = GoalEvaluation.Countinious, IntervalType = IntervalType.Monthly };
            vm = target.ProcessGoal(goal);
            Assert.AreEqual(vm.Graph.Points[0].Time, now.AddMonths(-2));
            Assert.AreEqual(vm.Graph.Points[1].Time, now.AddMonths(1));

            goal = new Goal() { EvaluationType = GoalEvaluation.Countinious, IntervalType = IntervalType.Dayly };
            vm = target.ProcessGoal(goal);
            Assert.AreEqual(vm.Graph.Points[0].Time, now.AddDays(-2));
            Assert.AreEqual(vm.Graph.Points[1].Time, now.AddDays(2));
        }
Ejemplo n.º 14
0
        public void it_should_start_and_end_on_specified_dates_if_timelimited()
        {
            var now = DateTime.Now;
            var target = new GoalProcessor(now);
            var goal = new Goal() { EvaluationType = GoalEvaluation.Timelimited };

            var vm = target.ProcessGoal(goal);
            Assert.AreEqual(0, vm.Graph.Points[0].Amount);
            Assert.AreEqual(0, vm.Graph.Points[1].Amount);

            goal = new Goal() { EvaluationType = GoalEvaluation.Timelimited, StartDate = now.AddDays(-10), EndDate = now.AddDays(10) };
            vm = target.ProcessGoal(goal);
            Assert.AreEqual(vm.Graph.Points[0].Time, now.AddDays(-10));
            Assert.AreEqual(vm.Graph.Points[1].Time, now.AddDays(10));
        }