public void Test_ParseCourses()
 {
     string coursesString = "KJ-111 BIO111 ML-112/BIO104 MU-139 Musikkdidaktikk, tirs -ERN100 for";
     List<string> courses = new List<string> {"KJ-111", "BIO111", "ML-112", "BIO104", "MU-139", "ERN100" };
     Activity activity = new Activity();
     activity.ParseCourses(coursesString);
     Assert.That(activity.Courses, Is.EquivalentTo(courses));
 }
 public void Test_ParseTimespan()
 {
     int year = 2015; string date = "17 Aug"; string time = "09.15-11.00";
     DateTime start = new DateTime(2015, 08, 17, 09, 15, 00);
     DateTime end = new DateTime(2015, 08, 17, 11, 00, 00);
     Activity activity = new Activity();
     activity.ParseTimespan(year, date, time);
     Assert.That(activity.Start, Is.EqualTo(start));
     Assert.That(activity.End, Is.EqualTo(end));
 }
        /// <summary>
        /// This method grabs the schedule for the department
        /// of this object, and stores the schedule
        /// in it's schedule property: a list of weeks
        /// which contain days with activities.
        /// </summary>
        /// <param name="requestData">
        ///     the request data from the HttpClient
        ///     required for posting to the website.
        /// </param>
        public void GrabSchedule(PostData requestData)
        {
            var urlEncoded = requestData.UrlEncode(this);
            var response = Grabber.Client.PostAsync(Grabber.URL, urlEncoded).Result;
            string htmlStr = response.Content.ReadAsStringAsync().Result;
            HtmlDocument scheduleHtml = Utility.ToHtml(htmlStr);
            if (scheduleHtml == null || scheduleHtml.DocumentNode == null)
                throw new ArgumentException("GrabSchedule + " + this.Id +
                ": something went wrong during the POST-request!");
            var weeks = scheduleHtml.DocumentNode.Descendants("table");

            var title = scheduleHtml.DocumentNode.Descendants()
                .Where(n => n.GetAttributeValue("class", null) == "title").FirstOrDefault();
            this.Name = Utility.Sanitize(title.InnerText);

            if (weeks.Count() == 0)
                return;

            foreach (var week in weeks)
            {
                var days = week.SelectNodes("tr[@class='tr2']");
                if (days != null && days.Count > 0)
                {
                    Week theWeek = new Week();
                    List<Day> dayList = new List<Day>();
                    string weekString = Utility.Sanitize(week.SelectSingleNode("tr[@class='tr1']/td[@class='td1']")
                        .InnerText);
                    theWeek.WeekNumber = Week.GetWeekNumber(weekString);
                    theWeek.Year = Week.GetYear(weekString);
                    foreach (var dayActivity in days)
                    {
                        Activity activity = new Activity();
                        activity.ParseCourses(Utility.Sanitize(dayActivity.ChildNodes[3].InnerText));
                        activity.ParseRooms(Utility.Sanitize(dayActivity.ChildNodes[4].InnerText));
                        activity.Lecturer = Utility.Sanitize(dayActivity.ChildNodes[5].InnerText);
                        activity.Notice = Utility.Sanitize(dayActivity.ChildNodes[6].InnerText);
                        string dateStr = Utility.Sanitize(dayActivity.ChildNodes[1].InnerText);
                        string timeStr = Utility.Sanitize(dayActivity.ChildNodes[2].InnerText);
                        activity.ParseTimespan(theWeek.Year, dateStr, timeStr);
                        var currentDate = dayList.Where(d => d.Date.Date.Equals(activity.Start.Date));
                        if (currentDate.Count() == 0)
                        {
                            Day aday = new Day();
                            aday.Activities.Add(activity);
                            aday.Date = new DateTime(activity.Start.Year, activity.Start.Month, activity.Start.Day);
                            aday.DayOfWeek = aday.Date.DayOfWeek.ToString();
                            dayList.Add(aday);
                        }
                        else if (currentDate.Count() == 1)
                        {
                            currentDate.First().Activities.Add(activity);
                        }
                    }

                    theWeek.Days.AddRange(dayList.ToArray());
                    this.Schedule.Add(theWeek);
                }
            }
        }