public void TestAddAgenda() { Agenda agenda = new Agenda(); _agendas.AddAgenda(agenda); Assert.AreEqual(1, _agendas.Count); _agendas.AddAgenda(agenda); Assert.AreEqual(2, _agendas.Count); }
public void SetEditState(Agenda agenda) { nowAgenda = agenda; _isNew = false; _isEdit = true; _isView = false; _textBoxTitle.IsReadOnly = false; _textBoxTitle.Text = agenda.Title; _textBoxContent.IsReadOnly = false; _textBoxContent.Text = agenda.Content; _textBoxStartDate.IsReadOnly = false; StartDatePicker.IsEnabled = true; _textBoxStartDate.Text = agenda.StartDateTime.Value.ToString("MM/dd/yyyy"); //StartDatePicker.SelectedDate = agenda.StartDateTime.Value; _comboBoxStartHour.SelectedIndex = agenda.StartDateTime.Value.Hour; _comboBoxStartHour.IsEnabled = true; _textBoxEndDate.IsReadOnly = false; EndDatePicker.IsEnabled = true; _textBoxEndDate.Text = agenda.EndDateTime.Value.ToString("MM/dd/yyyy"); //EndDatePicker.SelectedDate = agenda.EndDateTime.Value; _comboBoxEndHour.SelectedIndex = agenda.EndDateTime.Value.Hour; _comboBoxEndHour.IsEnabled = true; if (agenda.Value == Agenda.ValueEnum.Important) { _radioImportant.IsChecked = true; } else if (agenda.Value == Agenda.ValueEnum.Common) { _radioCommon.IsChecked = true; } else { _radioUnimportant.IsChecked = true; } _radioImportant.IsEnabled = true; _radioCommon.IsEnabled = true; _radioUnimportant.IsEnabled = true; pageTitle.Text = "Edit My Agenda"; }
public void TestChangeProperty() { List<string> receivedEvents = new List<string>(); _agendas.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e) { receivedEvents.Add(e.PropertyName); }; Agenda agenda = new Agenda(); _agendas.AddAgenda(agenda); Assert.AreEqual(1, receivedEvents.Count); Assert.AreEqual("AddAgenda", receivedEvents[0]); //_title = String.Empty; agenda.Title = "newValue"; Assert.AreEqual(2, receivedEvents.Count); Assert.AreEqual("Title", receivedEvents[1]); //_content = String.Empty; agenda.Content = "newValue"; Assert.AreEqual(3, receivedEvents.Count); Assert.AreEqual("Content", receivedEvents[2]); //_place = String.Empty; agenda.Place = "newValue"; Assert.AreEqual(4, receivedEvents.Count); Assert.AreEqual("Place", receivedEvents[3]); //_startDateTime = null; agenda.StartDateTime = new DateTime(2012, 12, 22); Assert.AreEqual(5, receivedEvents.Count); Assert.AreEqual("StartDateTime", receivedEvents[4]); //_endDateTime = null; agenda.EndDateTime = new DateTime(2012, 12, 21); Assert.AreEqual(6, receivedEvents.Count); Assert.AreEqual("EndDateTime", receivedEvents[5]); //_reminderDateTime = null; agenda.ReminderDateTime = new DateTime(2013, 1, 1); Assert.AreEqual(7, receivedEvents.Count); Assert.AreEqual("ReminderDateTime", receivedEvents[6]); //_isRemind = false; agenda.IsRemind = true; Assert.AreEqual(8, receivedEvents.Count); Assert.AreEqual("IsRemind", receivedEvents[7]); //_value = ValueEnum.Common; agenda.Value = Agenda.ValueEnum.Important; Assert.AreEqual(9, receivedEvents.Count); Assert.AreEqual("Value", receivedEvents[8]); }
public void TestPropertyChanged() { DateTime sameMonthDateTime1 = new DateTime(2012, 3, 30); DateTime sameMonthDateTime2 = new DateTime(2012, 3, 1); DateTime notDateTime = new DateTime(2000, 1, 1); MonthAgenda month = new MonthAgenda(_agendas, 2012, 3); Agenda agenda1 = new Agenda(sameMonthDateTime1); Agenda agenda2 = new Agenda(sameMonthDateTime2); Agenda notAgenda = new Agenda(notDateTime); Assert.AreEqual(0, month.AgendaCount); _agendas.AddAgenda(agenda1); Assert.AreEqual(1, month.AgendaCount); _agendas.AddAgenda(agenda2); Assert.AreEqual(2, month.AgendaCount); _agendas.AddAgenda(notAgenda); Assert.AreEqual(2, month.AgendaCount); }
public void TestSaveAgendaList() { DateTime dateTime = new DateTime(2012, 1, 2); Agenda agenda1 = new Agenda(dateTime); agenda1.Title = "agenda1"; Agenda agenda2 = new Agenda(dateTime); agenda2.Title = "agenda2"; Agenda agenda3 = new Agenda(dateTime); agenda3.Title = "agenda3"; Agenda agenda4 = new Agenda(dateTime); agenda4.Title = "agenda4"; Agenda agenda5 = new Agenda(dateTime); agenda5.Title = "agenda5"; _agendas.AddAgenda(agenda1); _agendas.AddAgenda(agenda2); _agendas.AddAgenda(agenda3); _agendas.AddAgenda(agenda4); _agendas.AddAgenda(agenda5); _agendas.SaveAgendaList(); }
public void TestConstructorByList() { DateTime dateTime = new DateTime(2012, 1, 2); //List<Agenda> agendaList = new List<Agenda>(); Agendas agendas = new Agendas(); Agenda agenda1 = new Agenda(dateTime); agenda1.Title = "agenda1"; Agenda agenda2 = new Agenda(dateTime); agenda2.Title = "agenda2"; Agenda agenda3 = new Agenda(dateTime); agenda3.Title = "agenda3"; Agenda agenda4 = new Agenda(dateTime); agenda4.Title = "agenda4"; Agenda agenda5 = new Agenda(dateTime); agenda5.Title = "agenda5"; agendas.AddAgenda(agenda1); agendas.AddAgenda(agenda2); agendas.AddAgenda(agenda3); agendas.AddAgenda(agenda4); agendas.AddAgenda(agenda5); DayAgenda day = new DayAgenda(agendas, dateTime); Assert.AreEqual(5, day.Count); }
public void Initialize() { _agendaList = new List<Agenda>(); Agenda agenda1 = new Agenda(new DateTime(2012, 1, 1)); agenda1.Value = Agenda.ValueEnum.Unimportant; agenda1.Title = "agenda1"; Agenda agenda2 = new Agenda(new DateTime(2012, 1, 3)); agenda2.Value = Agenda.ValueEnum.Important; agenda2.Title = "agenda2"; Agenda agenda3 = new Agenda(new DateTime(2012, 1, 5)); agenda3.Value = Agenda.ValueEnum.Important; agenda3.Title = "agenda3"; Agenda agenda4 = new Agenda(new DateTime(2012, 1, 4)); agenda4.Value = Agenda.ValueEnum.Common; agenda4.Title = "agenda4"; Agenda agenda5 = new Agenda(new DateTime(2012, 1, 2)); agenda5.Value = Agenda.ValueEnum.Important; agenda5.Title = "agenda5"; _agendaList.Add(agenda1); _agendaList.Add(agenda2); _agendaList.Add(agenda3); _agendaList.Add(agenda4); _agendaList.Add(agenda5); }
public void AddAgenda(Agenda agenda) { _agendaList.Add(agenda); agenda.PropertyChanged += NotifyPropertyChanged; NotifyPropertyChanged(agenda, new PropertyChangedEventArgs("AddAgenda")); }
public void RemoveAgenda(Agenda agenda) { agenda.PropertyChanged -= NotifyPropertyChanged; _agendaList.Remove(agenda); NotifyPropertyChanged(agenda, new PropertyChangedEventArgs("RemoveAgenda")); }
private void ClickButtonSubmit(object sender, RoutedEventArgs e) { if (_isNew) { Agenda agenda = new Agenda(); agenda.Title = _textBoxTitle.Text; agenda.Content = _textBoxContent.Text; int year, month, day, hour; DateTime startDateTime = Convert.ToDateTime(_textBoxStartDate.Text); year = startDateTime.Year; month = startDateTime.Month; day = startDateTime.Day; hour = _comboBoxStartHour.SelectedIndex;// Convert.ToInt32(_comboBoxStartHour.SelectedIndex); startDateTime = new DateTime(year, month, day, hour, 0, 0); agenda.StartDateTime = startDateTime; DateTime endDateTime = Convert.ToDateTime(_textBoxEndDate.Text); year = endDateTime.Year; month = endDateTime.Month; day = endDateTime.Day; hour = _comboBoxEndHour.SelectedIndex; endDateTime = new DateTime(year, month, day, hour, 0, 0); agenda.EndDateTime = endDateTime; if (_radioImportant.IsChecked.Value) { agenda.Value = Agenda.ValueEnum.Important; } else if (_radioCommon.IsChecked.Value) { agenda.Value = Agenda.ValueEnum.Common; } else { agenda.Value = Agenda.ValueEnum.Unimportant; } App.AgendasModel.AddAgenda(agenda); } else if (_isEdit) { nowAgenda.Title = _textBoxTitle.Text; nowAgenda.Content = _textBoxContent.Text; int year, month, day, hour; DateTime startDateTime = Convert.ToDateTime(_textBoxStartDate.Text); year = startDateTime.Year; month = startDateTime.Month; day = startDateTime.Day; hour = _comboBoxStartHour.SelectedIndex;// Convert.ToInt32(_comboBoxStartHour.SelectedIndex); startDateTime = new DateTime(year, month, day, hour, 0, 0); DateTime endDateTime = Convert.ToDateTime(_textBoxEndDate.Text); year = endDateTime.Year; month = endDateTime.Month; day = endDateTime.Day; hour = _comboBoxEndHour.SelectedIndex; endDateTime = new DateTime(year, month, day, hour, 0, 0); if (startDateTime < endDateTime) { nowAgenda._startDateTime = startDateTime; nowAgenda._endDateTime = endDateTime; } else { nowAgenda._startDateTime = endDateTime; nowAgenda._endDateTime = startDateTime; } if (_radioImportant.IsChecked.Value) { nowAgenda.Value = Agenda.ValueEnum.Important; } else if (_radioCommon.IsChecked.Value) { nowAgenda.Value = Agenda.ValueEnum.Common; } else { nowAgenda.Value = Agenda.ValueEnum.Unimportant; } } //Window.Current.Content = App.MyMainPage; App.DailyPage.Refresh(); App.MyGanttPage.RePaint(); Window.Current.Content = PreviousPage; }
public List <Agenda> GetFreeTimeAgendaList(DateTime dateTime) { DateTime startDateTime = new DateTime(); DateTime endDateTime = new DateTime(); int year = dateTime.Year; int month = dateTime.Month; int day = dateTime.Day; startDateTime = new DateTime(year, month, day, 0, 0, 0); endDateTime = new DateTime(year, month, day, 23, 59, 59); AgendaSorter dateTimeSorter = new DateTimeSorter(); List <Agenda> tempList = dateTimeSorter.Sort(GetAgendaList(dateTime)); List <Agenda> agendaList = new List <Agenda>(); foreach (Agenda agenda in tempList) { Agenda newAgenda = new Agenda(agenda.StartDateTime, agenda.EndDateTime); agendaList.Add(newAgenda); } //merge for (int i = 0; i < agendaList.Count; i++) { for (int j = i + 1; j < agendaList.Count; j++) { if (agendaList[i].EndDateTime >= agendaList[j].StartDateTime && agendaList[i].EndDateTime <= agendaList[j].EndDateTime) { agendaList[i].EndDateTime = agendaList[j].EndDateTime; agendaList.RemoveAt(j); } } } //change List <Agenda> freeTimeAgendaList = new List <Agenda>(); //first if (agendaList.Count > 0) { if (startDateTime < agendaList[0].StartDateTime) {//dateTime的前一天 Agenda agenda = new Agenda(startDateTime, agendaList[0].StartDateTime); freeTimeAgendaList.Add(agenda); } //last for (int i = 0; i < agendaList.Count - 1; i++) { Agenda agenda = new Agenda(agendaList[i].EndDateTime, agendaList[i + 1].StartDateTime); freeTimeAgendaList.Add(agenda); } if (agendaList[agendaList.Count - 1].EndDateTime < endDateTime) {//dateTime的前一天 Agenda agenda = new Agenda(agendaList[agendaList.Count - 1].EndDateTime, endDateTime); freeTimeAgendaList.Add(agenda); } } else { Agenda agenda = new Agenda(startDateTime, endDateTime); freeTimeAgendaList.Add(agenda); } return(freeTimeAgendaList); }
public void TestRemoveAgenda() { DateTime startDateTime = new DateTime(2012, 1, 2); DateTime endDateTime = new DateTime(2012, 1, 4); Agenda agenda1 = new Agenda(new DateTime(2012, 1, 1)); agenda1.Title = "agenda1"; Agenda agenda2 = new Agenda(startDateTime); agenda2.Title = "agenda2"; Agenda agenda3 = new Agenda(new DateTime(2012, 1, 3)); agenda3.Title = "agenda3"; Agenda agenda4 = new Agenda(endDateTime); agenda4.Title = "agenda4"; Agenda agenda5 = new Agenda(new DateTime(2012, 1, 5)); agenda5.Title = "agenda5"; _agendas.AddAgenda(agenda1); _agendas.AddAgenda(agenda2); _agendas.AddAgenda(agenda3); _agendas.AddAgenda(agenda4); _agendas.AddAgenda(agenda5); _agendas.RemoveAgenda(agenda5); Assert.AreEqual(4, _agendas.Count); _agendas.RemoveAgenda(agenda4); Assert.AreEqual(3, _agendas.Count); _agendas.RemoveAgenda(agenda3); Assert.AreEqual(2, _agendas.Count); _agendas.RemoveAgenda(agenda3); Assert.AreEqual(2, _agendas.Count); _agendas.RemoveAgenda(agenda2); Assert.AreEqual(1, _agendas.Count); _agendas.RemoveAgenda(agenda1); Assert.AreEqual(0, _agendas.Count); }
public void TestChangePropertyAddAgendaAndRemoveAgenda() { List<string> receivedEvents = new List<string>(); _agendas.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e) { receivedEvents.Add(e.PropertyName); }; Agenda agenda = new Agenda(); _agendas.AddAgenda(agenda); Assert.AreEqual(1, receivedEvents.Count); Assert.AreEqual("AddAgenda", receivedEvents[0]); _agendas.AddAgenda(agenda); Assert.AreEqual(2, receivedEvents.Count); Assert.AreEqual("AddAgenda", receivedEvents[1]); _agendas.RemoveAgenda(agenda); Assert.AreEqual(3, receivedEvents.Count); Assert.AreEqual("RemoveAgenda", receivedEvents[2]); _agendas.RemoveAgenda(agenda); Assert.AreEqual(4, receivedEvents.Count); Assert.AreEqual("RemoveAgenda", receivedEvents[3]); }
public void TestModifyRefernece() { Agenda agenda = new Agenda(); _agendas.AddAgenda(agenda); _agendas[0].Title = "changed"; Assert.AreEqual("changed", agenda.Title); }
public void TestGetAgendasByDateTime() { DateTime dateTime1 = new DateTime(2012, 3, 15); DateTime dateTime2 = new DateTime(2012, 4, 11, 3, 4, 5); Agenda agenda1 = new Agenda(dateTime1); agenda1.Title = "dateTime1"; Agenda agenda2 = new Agenda(dateTime2); agenda2.Title = "dateTime2"; Agenda agenda3 = new Agenda(dateTime1); agenda3.Title = "dateTime1"; Agenda agenda4 = new Agenda(dateTime2); agenda4.Title = "dateTime2"; Agenda agenda5 = new Agenda(dateTime1); agenda5.Title = "dateTime1"; _agendas.AddAgenda(agenda1); _agendas.AddAgenda(agenda2); _agendas.AddAgenda(agenda3); _agendas.AddAgenda(agenda4); _agendas.AddAgenda(agenda5); List<Agenda> agendaList = _agendas.GetAgendaList(dateTime1); Assert.AreEqual(3, agendaList.Count); foreach (Agenda agenda in agendaList) { Assert.AreEqual("dateTime1", agenda.Title); } }
public void TestLoadAgendaList() { Agenda agenda1 = new Agenda(new DateTime(2012, 1, 1)); agenda1.Title = "agenda1"; Agenda agenda2 = new Agenda(new DateTime(2012, 1, 2)); agenda2.Title = "agenda2"; Agenda agenda3 = new Agenda(new DateTime(2012, 1, 3)); agenda3.Title = "agenda3"; Agenda agenda4 = new Agenda(new DateTime(2012, 1, 4)); agenda4.Title = "agenda4"; Agenda agenda5 = new Agenda(new DateTime(2012, 1, 5)); agenda5.Title = "agenda5"; _agendas.AddAgenda(agenda1); _agendas.AddAgenda(agenda2); _agendas.AddAgenda(agenda3); _agendas.AddAgenda(agenda4); _agendas.AddAgenda(agenda5); _agendas.SaveAgendaList().ContinueWith((T) => { _agendas = new Agendas(); Assert.AreEqual(0, _agendas.Count); _agendas.LoadAgendaList(); Assert.AreEqual(5, _agendas.Count); }).ContinueWith((T) => { _agendas.SaveAgendaList().ContinueWith((X) => { _agendas = new Agendas(); Assert.AreEqual(0, _agendas.Count); _agendas.LoadAgendaList(); Assert.AreEqual(5, _agendas.Count); }); }); }
public void TestGetFreeTimeAgendaList() { //20120301 DateTime dateTime01 = new DateTime(2012, 03, 01); DateTime dateTime01_Start = new DateTime(2012, 03, 1, 0, 0, 0); DateTime dateTime01_End = new DateTime(2012, 03, 1, 23, 59, 59); DateTime dateTime0121 = new DateTime(2012, 3, 1, 21, 1, 0); DateTime dateTime0123 = new DateTime(2012, 3, 1, 23, 44, 0); //20120302 DateTime dateTime02 = new DateTime(2012, 03, 02); DateTime dateTime02_Start = new DateTime(2012, 03, 2, 0, 0, 0); DateTime dateTime02_End = new DateTime(2012, 03, 2, 23, 59, 59); DateTime dateTime0201 = new DateTime(2012, 3, 2, 1, 1, 0); DateTime dateTime0203 = new DateTime(2012, 3, 2, 3, 1, 0); DateTime dateTime0205 = new DateTime(2012, 3, 2, 5, 1, 0); DateTime dateTime0212 = new DateTime(2012, 3, 2, 12, 1, 0); DateTime dateTime0218 = new DateTime(2012, 3, 2, 18, 1, 0); DateTime dateTime0222 = new DateTime(2012, 3, 2, 22, 1, 0); //20120303 DateTime dateTime03 = new DateTime(2012, 03, 03); DateTime dateTime03_Start = new DateTime(2012, 03, 03, 0, 0, 0); DateTime dateTime03_End = new DateTime(2012, 03, 03, 23, 59, 59); DateTime dateTime0303 = new DateTime(2012, 3, 3, 3, 1, 0); DateTime dateTime0305 = new DateTime(2012, 3, 3, 5, 1, 0); Agenda agenda0121_0123 = new Agenda(dateTime0121, dateTime0123); Agenda agenda0121_0201 = new Agenda(dateTime0121, dateTime0201); Agenda agenda0121_0203 = new Agenda(dateTime0121, dateTime0203); Agenda agenda0203_0218 = new Agenda(dateTime0203, dateTime0218); Agenda agenda0203_0205 = new Agenda(dateTime0203, dateTime0205); Agenda agenda0203_0222 = new Agenda(dateTime0203, dateTime0222); Agenda agenda0212_0222 = new Agenda(dateTime0212, dateTime0222); Agenda agenda0218_0222 = new Agenda(dateTime0218, dateTime0222); Agenda agenda0212_0218 = new Agenda(dateTime0212, dateTime0218); Agenda agenda0222_0303 = new Agenda(dateTime0222, dateTime0303); /* * 0121----0123 * 0121------------0203 * 0203---------------0218 * 0212--------------0222 * * 0212-----0218 * 0222---------0303 */ _agendas.AddAgenda(agenda0121_0123); List<Agenda> agendaList = _agendas.GetFreeTimeAgendaList(dateTime02); Assert.AreEqual(1, agendaList.Count); Assert.AreEqual(dateTime02_Start, agendaList[0].StartDateTime); Assert.AreEqual(dateTime02_End, agendaList[0].EndDateTime); //Assert.AreEqual _agendas.AddAgenda(agenda0203_0218); agendaList = _agendas.GetFreeTimeAgendaList(dateTime02); Assert.AreEqual(2, agendaList.Count); Assert.AreEqual(dateTime02_Start, agendaList[0].StartDateTime); Assert.AreEqual(dateTime0203, agendaList[0].EndDateTime); Assert.AreEqual(dateTime0218, agendaList[1].StartDateTime); Assert.AreEqual(dateTime02_End, agendaList[1].EndDateTime); // _agendas.AddAgenda(agenda0203_0222); agendaList = _agendas.GetFreeTimeAgendaList(dateTime02); Assert.AreEqual(2, agendaList.Count); Assert.AreEqual(dateTime02_Start, agendaList[0].StartDateTime); Assert.AreEqual(dateTime0203, agendaList[0].EndDateTime); Assert.AreEqual(dateTime0222, agendaList[1].StartDateTime); Assert.AreEqual(dateTime02_End, agendaList[1].EndDateTime); _agendas.RemoveAgenda(agenda0203_0218); _agendas.RemoveAgenda(agenda0203_0222); _agendas.AddAgenda(agenda0212_0222); agendaList = _agendas.GetFreeTimeAgendaList(dateTime02); Assert.AreEqual(2, agendaList.Count); Assert.AreEqual(dateTime02_Start, agendaList[0].StartDateTime); Assert.AreEqual(dateTime0212, agendaList[0].EndDateTime); Assert.AreEqual(dateTime0222, agendaList[1].StartDateTime); Assert.AreEqual(dateTime02_End, agendaList[1].EndDateTime); _agendas.AddAgenda(agenda0203_0205); agendaList = _agendas.GetFreeTimeAgendaList(dateTime02); Assert.AreEqual(3, agendaList.Count); Assert.AreEqual(dateTime02_Start, agendaList[0].StartDateTime); Assert.AreEqual(dateTime0203, agendaList[0].EndDateTime); Assert.AreEqual(dateTime0205, agendaList[1].StartDateTime); Assert.AreEqual(dateTime0212, agendaList[1].EndDateTime); Assert.AreEqual(dateTime0222, agendaList[2].StartDateTime); Assert.AreEqual(dateTime02_End, agendaList[2].EndDateTime); _agendas.AddAgenda(agenda0218_0222); agendaList = _agendas.GetFreeTimeAgendaList(dateTime02); Assert.AreEqual(3, agendaList.Count); Assert.AreEqual(dateTime02_Start, agendaList[0].StartDateTime); Assert.AreEqual(dateTime0203, agendaList[0].EndDateTime); Assert.AreEqual(dateTime0205, agendaList[1].StartDateTime); Assert.AreEqual(dateTime0212, agendaList[1].EndDateTime); Assert.AreEqual(dateTime0222, agendaList[2].StartDateTime); Assert.AreEqual(dateTime02_End, agendaList[2].EndDateTime); _agendas = new Agendas(); _agendas.AddAgenda(agenda0121_0201); _agendas.AddAgenda(agenda0203_0205); _agendas.AddAgenda(agenda0212_0218); _agendas.AddAgenda(agenda0218_0222); agendaList = _agendas.GetFreeTimeAgendaList(dateTime02); Assert.AreEqual(3, agendaList.Count); Assert.AreEqual(dateTime0201, agendaList[0].StartDateTime); Assert.AreEqual(dateTime0203, agendaList[0].EndDateTime); Assert.AreEqual(dateTime0205, agendaList[1].StartDateTime); Assert.AreEqual(dateTime0212, agendaList[1].EndDateTime); Assert.AreEqual(dateTime0222, agendaList[2].StartDateTime); Assert.AreEqual(dateTime02_End, agendaList[2].EndDateTime); _agendas = new Agendas(); _agendas.AddAgenda(agenda0121_0201); _agendas.AddAgenda(agenda0203_0205); _agendas.AddAgenda(agenda0212_0218); _agendas.AddAgenda(agenda0222_0303); agendaList = _agendas.GetFreeTimeAgendaList(dateTime02); Assert.AreEqual(3, agendaList.Count); Assert.AreEqual(dateTime0201, agendaList[0].StartDateTime); Assert.AreEqual(dateTime0203, agendaList[0].EndDateTime); Assert.AreEqual(dateTime0205, agendaList[1].StartDateTime); Assert.AreEqual(dateTime0212, agendaList[1].EndDateTime); Assert.AreEqual(dateTime0218, agendaList[2].StartDateTime); Assert.AreEqual(dateTime0222, agendaList[2].EndDateTime); }
public void TestGetDayByDateTime() { DateTime dateTime1 = new DateTime(2012, 3, 15); DateTime dateTime2 = new DateTime(2012, 4, 11); Agenda agenda1 = new Agenda(dateTime1); agenda1.Title = "dateTime1"; Agenda agenda2 = new Agenda(dateTime2); agenda2.Title = "dateTime2"; Agenda agenda3 = new Agenda(dateTime1); agenda3.Title = "dateTime1"; Agenda agenda4 = new Agenda(dateTime2); agenda4.Title = "dateTime2"; Agenda agenda5 = new Agenda(dateTime1); agenda5.Title = "dateTime1"; _agendas.AddAgenda(agenda1); _agendas.AddAgenda(agenda2); _agendas.AddAgenda(agenda3); _agendas.AddAgenda(agenda4); _agendas.AddAgenda(agenda5); DayAgenda day = _agendas.GetDay(dateTime1); Assert.AreEqual(3, day.Count); for (int i = 0; i < day.Count; i++) { Assert.AreEqual("dateTime1", day[i].Title); } }
public void TestGetAgendasSequenceDays() { DateTime startDateTime = new DateTime(2012, 1, 1); DateTime endDateTime = new DateTime(2012, 1, 5); Agenda agenda1 = new Agenda(new DateTime(2012, 1, 1)); agenda1.Title = "agenda1"; Agenda agenda2 = new Agenda(new DateTime(2012, 1, 2)); agenda2.Title = "agenda2"; Agenda agenda3 = new Agenda(new DateTime(2012, 1, 3)); agenda3.Title = "agenda3"; Agenda agenda4 = new Agenda(new DateTime(2012, 1, 4)); agenda4.Title = "agenda4"; Agenda agenda5 = new Agenda(new DateTime(2012, 1, 5)); agenda5.Title = "agenda5"; _agendas.AddAgenda(agenda1); _agendas.AddAgenda(agenda2); _agendas.AddAgenda(agenda3); _agendas.AddAgenda(agenda4); _agendas.AddAgenda(agenda5); List<DayAgenda> dayList = _agendas.GetDayList(startDateTime, endDateTime); Assert.AreEqual(5, dayList.Count); Assert.AreEqual(1, dayList[0].Count); Assert.AreEqual(1, dayList[1].Count); Assert.AreEqual(1, dayList[2].Count); Assert.AreEqual(1, dayList[3].Count); Assert.AreEqual(1, dayList[4].Count); }
public List<Agenda> GetFreeTimeAgendaList(DateTime dateTime) { DateTime startDateTime = new DateTime(); DateTime endDateTime = new DateTime(); int year = dateTime.Year; int month = dateTime.Month; int day = dateTime.Day; startDateTime = new DateTime(year, month, day, 0, 0, 0); endDateTime = new DateTime(year, month, day, 23, 59, 59); AgendaSorter dateTimeSorter = new DateTimeSorter(); List<Agenda> tempList = dateTimeSorter.Sort(GetAgendaList(dateTime)); List<Agenda> agendaList = new List<Agenda>(); foreach (Agenda agenda in tempList) { Agenda newAgenda = new Agenda(agenda.StartDateTime, agenda.EndDateTime); agendaList.Add(newAgenda); } //merge for (int i = 0; i < agendaList.Count; i++) { for (int j = i + 1; j < agendaList.Count; j++) { if (agendaList[i].EndDateTime >= agendaList[j].StartDateTime && agendaList[i].EndDateTime <= agendaList[j].EndDateTime) { agendaList[i].EndDateTime = agendaList[j].EndDateTime; agendaList.RemoveAt(j); } } } //change List<Agenda> freeTimeAgendaList = new List<Agenda>(); //first if (agendaList.Count > 0) { if (startDateTime < agendaList[0].StartDateTime) {//dateTime的前一天 Agenda agenda = new Agenda(startDateTime, agendaList[0].StartDateTime); freeTimeAgendaList.Add(agenda); } //last for (int i = 0; i < agendaList.Count - 1; i++) { Agenda agenda = new Agenda(agendaList[i].EndDateTime, agendaList[i + 1].StartDateTime); freeTimeAgendaList.Add(agenda); } if (agendaList[agendaList.Count - 1].EndDateTime < endDateTime) {//dateTime的前一天 Agenda agenda = new Agenda(agendaList[agendaList.Count - 1].EndDateTime, endDateTime); freeTimeAgendaList.Add(agenda); } } else { Agenda agenda = new Agenda(startDateTime, endDateTime); freeTimeAgendaList.Add(agenda); } return freeTimeAgendaList; }
public void TestGetAgendaListByDuration() { DateTime startDateTime = new DateTime(2012, 1, 2); DateTime endDateTime = new DateTime(2012, 1, 4); Agenda agenda1 = new Agenda(new DateTime(2012, 1, 1)); agenda1.Title = "agenda1"; Agenda agenda2 = new Agenda(startDateTime); agenda2.Title = "agenda2"; Agenda agenda3 = new Agenda(new DateTime(2012, 1, 3)); agenda3.Title = "agenda3"; Agenda agenda4 = new Agenda(endDateTime); agenda4.Title = "agenda4"; Agenda agenda5 = new Agenda(new DateTime(2012, 1, 5)); agenda5.Title = "agenda5"; _agendas.AddAgenda(agenda1); _agendas.AddAgenda(agenda2); _agendas.AddAgenda(agenda3); _agendas.AddAgenda(agenda4); _agendas.AddAgenda(agenda5); List<Agenda> agendaList = _agendas.GetAgendaList(startDateTime, endDateTime); Assert.AreEqual(3, agendaList.Count); Assert.AreEqual("agenda2", agendaList[0].Title); Assert.AreEqual("agenda3", agendaList[1].Title); Assert.AreEqual("agenda4", agendaList[2].Title); }