private static List <Week> SortTasks(List <Task> tasks)
        {
            List <Day>  days  = new List <Day>();
            List <Week> weeks = new List <Week>();

            foreach (Task t in tasks)
            {
                Day matchingDay = days.Find(d => d.Date.Date == t.DueDatetime.Date);
                if (matchingDay == null)
                {
                    days.Add(new Day(t.DueDatetime.Date, new List <Task>(new Task[] { t })));
                }
                else
                {
                    matchingDay.AddTask(t);
                }
            }

            foreach (Day d in days)
            {
                int  weekNum      = DateService.GetWeekNumber(d.Date);
                Week matchingWeek = weeks.Find(w => w.WeekNumber == weekNum);
                if (matchingWeek == null)
                {
                    weeks.Add(new Week(weekNum, new List <Day>(new Day[] { d })));
                }
                else
                {
                    matchingWeek.AddDay(d);
                }
            }

            return(weeks);
        }
Пример #2
0
        public void test_week_can_have_days()
        {
            Week week = new Week(string.Empty);
            Day  day  = new Day("Monday 2017-04-17");

            week.AddDay(day);

            Assert.True(week.DaysCount == 1);
        }
        public void Test_Week_Can_Have_Days()
        {
            Week week = new Week("Week 1");
            Day  day  = new Day("Monday 2016-05-01");

            week.AddDay(day);

            Assert.Equal(1, week.Days.Count);
        }
Пример #4
0
        public void test_week_adding_null_day_throws_exception()
        {
            Assert.Throws <ArgumentNullException>(() =>
            {
                Week week = new Week(string.Empty);
                Day day   = null;

                week.AddDay(day);
            });
        }
Пример #5
0
        private bool SaveNewTask(Task newTask, int weekNumber)
        {
            if (newTask == null)
            {
                Toastr.Error("Error", "Task is not defined");
                return(false);
            }
            if (weekNumber < 1 || weekNumber > 52)
            {
                Toastr.Error("Error", "Invalid week number");
                return(false);
            }

            Week week = FindWeek(weekNumber);

            if (week != null)
            {
                Day day = FindDay(week, newTask.DueDatetime.Date);

                if (day != null)
                {
                    day.AddTask(newTask);
                }
                else
                {
                    Day newDay = CreateNewDay(newTask);
                    week.AddDay(newDay);
                }
            }
            else
            {
                week = CreateNewWeek(weekNumber);
                Day newDay = CreateNewDay(newTask);
                week.AddDay(newDay);

                Planner.AddWeek(week);
            }

            Database.SaveTasks();

            return(true);
        }
Пример #6
0
        public void test_days_can_be_retrieved_from_week()
        {
            string title = "Monday 2017-03-11";

            Week week = new Week("Week 1");
            Day  day  = new Day(title);

            week.AddDay(day);

            Assert.That(week.Days.First().Title == title);
        }
        public void test_retrieve_tasks_from_week_multiple_days()
        {
            Week week   = new Week("Week 1");
            Day  monday = new Day("Monday 2017-04-03");

            monday.AddTask(new CustomTask("- First task"));
            monday.AddTask(new CustomTask("- Second task"));

            Day tuesday = new Day("Tuesday 2017-04-04");

            tuesday.AddTask(new CustomTask("- Third task"));
            tuesday.AddTask(new CustomTask("- Fourth task"));

            week.AddDay(monday);
            week.AddDay(tuesday);

            var tasks = act(week);

            Assert.That(tasks.Count() == 4);
        }
        public void test_week_with_days_with_no_tasks()
        {
            Week week = new Week("Week 1");
            Day  day  = new Day("Monday 2017-04-03");

            week.AddDay(day);

            var tasks = act(week);

            Assert.That(!tasks.Any());
        }
        private Week BuildTestWeek(int daysNumber)
        {
            Week week = new Week("Week 1");
            var  days = Enumerable.Range(0, daysNumber).Select(s => new Day("Monday 2016-05-01"));

            foreach (var day in days)
            {
                week.AddDay(day);
            }

            return(week);
        }
        public void test_retrieve_tasks_from_week_single_day()
        {
            Week week = new Week("Week 1");
            Day  day  = new Day("Monday 2017-04-03");

            day.AddTask(new CustomTask("- First task"));
            day.AddTask(new CustomTask("- Second task"));

            week.AddDay(day);

            var tasks = act(week);

            Assert.That(tasks.Count() == 2);
        }