/// <summary> /// This operation generates an operation based on how this generator has been configured. /// </summary> /// <returns>The generated operation.</returns> public Operation CreateOperation() { Task task; Operation newOperation = null; switch (commandType) { case CommandType.ADD: task = Task.CreateNewTask(taskName, startDateTime, endDateTime, isSpecific); newOperation = new OperationAdd(task, sortType); break; case CommandType.DELETE: newOperation = new OperationDelete(taskName, taskRangeIndex, startDateTime, endDateTime, isSpecific, rangeIsAll, searchType, sortType); break; case CommandType.DISPLAY: newOperation = new OperationDisplayDefault(sortType); break; case CommandType.MODIFY: newOperation = new OperationModify(taskName, taskRangeIndex, startDateTime, endDateTime, isSpecific, rangeIsAll, searchType, sortType); break; case CommandType.SEARCH: newOperation = new OperationSearch(taskName, startDateTime, endDateTime, isSpecific, searchType, sortType); break; case CommandType.SORT: newOperation = new OperationSort(sortType); break; case CommandType.REDO: newOperation = new OperationRedo(sortType); break; case CommandType.UNDO: newOperation = new OperationUndo(sortType); break; case CommandType.DONE: newOperation = new OperationMarkAsDone(taskName, taskRangeIndex, startDateTime, endDateTime, isSpecific, rangeIsAll, searchType, sortType); break; case CommandType.UNDONE: newOperation = new OperationMarkAsUndone(taskName, taskRangeIndex, startDateTime, endDateTime, isSpecific, rangeIsAll, searchType, sortType); break; case CommandType.POSTPONE: TimeSpan postponeDuration = new TimeSpan(); if (timeRangeType == TimeRangeType.DEFAULT) { timeRangeType = CustomDictionary.defaultPostponeDurationType; timeRangeIndex = CustomDictionary.defaultPostponeDurationLength; } switch (timeRangeType) { case TimeRangeType.HOUR: postponeDuration = new TimeSpan(timeRangeIndex, 0, 0); break; case TimeRangeType.DAY: postponeDuration = new TimeSpan(timeRangeIndex, 0, 0, 0); break; case TimeRangeType.WEEK: postponeDuration = new TimeSpan(timeRangeIndex * CustomDictionary.DAYS_IN_WEEK, 0, 0, 0); break; case TimeRangeType.MONTH: postponeDuration = new TimeSpan(timeRangeIndex * CustomDictionary.DAYS_IN_MONTH, 0, 0, 0); break; } newOperation = new OperationPostpone(taskName, taskRangeIndex, startDateTime, endDateTime, isSpecific, rangeIsAll, searchType, postponeDuration, sortType); break; case CommandType.SCHEDULE: newOperation = new OperationSchedule(taskName, (DateTime)startDateTime, endDateTime, isSpecific, timeRangeIndex, timeRangeType, sortType); break; case CommandType.EXIT: System.Environment.Exit(0); break; } return newOperation; }
public void OperationSearchTest() { testStorage = new Storage("OpUnittest.xml", "OpUnittestsettings.xml"); testTaskList = testStorage.LoadTasksFromFile(); DateTime timeTest; timeTest = DateTime.ParseExact("10/15/2013 5:00 AM", formats, new CultureInfo("en-US"), DateTimeStyles.None); DateTimeSpecificity specific = new DateTimeSpecificity(); TaskDeadline testDeadline = new TaskDeadline("test", timeTest, specific); OperationAdd Op1 = new OperationAdd(testDeadline, sortType); OperationSearch Op2 = new OperationSearch("SearchConditionCannotBeMatching",DateTime.Now,timeTest.AddDays(1),specific,SearchType.NONE,SortType.DEFAULT); result = Op2.Execute(testTaskList, testStorage); Assert.AreEqual("No matching tasks found!", result.FeedbackString); result = Op1.Execute(testTaskList, testStorage); result = Op2.Execute(testTaskList, testStorage); Assert.AreEqual("No matching tasks found!", result.FeedbackString); return; }