public void OperationAddTest()
        {
            testStorage = new Storage("OpUnittest.xml", "OpUnittestsettings.xml");
            testTaskList = testStorage.LoadTasksFromFile();

            OperationAdd Op = new OperationAdd(testTask, sortType);
            result = Op.Execute(testTaskList, testStorage);
            Assert.AreEqual("Added new task \"test\" successfully.", result.FeedbackString);
            return;
        }
        public void OperationAddFailTest()
        {
            testStorage = new Storage("OpUnittest.xml", "OpUnittestsettings.xml");
            testTaskList = testStorage.LoadTasksFromFile();

            OperationAdd Op = new OperationAdd(null, sortType);
            result = Op.Execute(testTaskList, testStorage);
            Assert.AreEqual(result.FeedbackString, "Failed to add task!");
            return;
        }
        public void OperationDeleteMultipleTest()
        {
            testStorage = new Storage("OpUnittest.xml", "OpUnittestsettings.xml");
            testTaskList = testStorage.LoadTasksFromFile();

            int[] index = new int[2] { 1, 2 };
            OperationAdd Op = new OperationAdd(testTask, sortType);
            Op.Execute(testTaskList, testStorage);
            Op = new OperationAdd(testTaskNew, sortType);
            Op.Execute(testTaskList, testStorage);
            OperationDelete Op1 = new OperationDelete("", index, null, null, null, false, SearchType.NONE, sortType);
            result = Op1.Execute(testTaskList, testStorage);
            Assert.AreEqual("Deleted all indicated tasks successfully.", result.FeedbackString);
            return;
        }
 /// <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 OperationDeleteRangeFailTest()
        {
            testStorage = new Storage("OpUnittest.xml", "OpUnittestsettings.xml");
            testTaskList = testStorage.LoadTasksFromFile();

            int[] index = new int[2] { 1, 4 };
            OperationDelete Op1;
            OperationAdd Op = new OperationAdd(testTask, sortType);
            result = Op.Execute(testTaskList, testStorage);
            Op1 = new OperationDelete("", index, null, null, null, false, SearchType.NONE, sortType);
            result = Op1.Execute(testTaskList, testStorage);
            Assert.AreEqual("Invalid task index!", result.FeedbackString);
            index = new int[2] { 1, 1 };
            Op1 = new OperationDelete("", index, null, null, null, false, SearchType.NONE, sortType);
            result = Op1.Execute(testTaskList, testStorage);
            Assert.AreEqual("Deleted task \"test\" successfully.", result.FeedbackString);
            return;
        }
        public void OperationUndoAddTest()
        {
            testStorage = new Storage("OpUnittest.xml", "OpUnittestsettings.xml");
            testTaskList = testStorage.LoadTasksFromFile();

            OperationAdd Op = new OperationAdd(testTask, sortType);
            Op.Execute(testTaskList, testStorage);
            result = Op.Undo(testTaskList, testStorage);
            Assert.AreEqual(result.FormatType.ToString(), "DEFAULT");
            return;
        }
        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;
        }