public override GGResult Execute(string userCommand, GGList ggList) { Debug.Assert(userCommand != null && !userCommand.Equals(string.Empty)); Debug.Assert(ggList != null); this.SetGGList(ggList); userCommand = StripAddCommandFromUserCommand(userCommand).Trim(); try { ThrowExceptionIfIsEmptyInput(userCommand); newGgItem = QuickParser.Parse(userCommand); ggList.AddGGItem(newGgItem); this.SetIsSuccessful(true); string successMsg = string.Format(MESSAGE_ADD_SUCCESS, newGgItem.GetDescription()); Debug.WriteLine(successMsg, "info"); result = CreateResultInstance(successMsg, GGResult.RESULT_TYPE.RESULT_ADD, ggList.IndexOfGGItem(newGgItem),newGgItem.GetTag()); } catch (Exception e) { error = e.Message; string errorMsg = string.Format(MESSAGE_ERROR, error); Debug.WriteLine(errorMsg, "error"); result = CreateResultInstance(errorMsg, GGResult.RESULT_TYPE.RESULT_INVALID); } return result; }
private static void AddOriginalDataToList(GGList originalList) { for (int i = 0; i < originalData.Length / 3; i++) { GGItem item = new GGItem(originalData[i, 0], DateTime.Parse(originalData[i, 1], usCulture), originalData[i, 2]); originalList.AddGGItem(item); } }
private void GGSyncUnitTest() { GGSync mySync = new GGSync("*****@*****.**", "cs2103trocks"); PrintSperateLine(); Console.WriteLine("\nPlease delete GG to-do calendar\n"); Console.ReadKey(); GGList myList = new GGList(); for (int i = 0; i < 3; i++) { myList.AddGGItem(new GGItem("desciption_test" + i, DateTime.Now.AddDays(i + 1), "tag_test" + i)); } PrintSperateLine(); Console.WriteLine("\nTest: add to empty google calender\n"); PreTestPrint(myList); mySync.SyncWithGoogleCalendar(myList); PostTestPrint(myList); Console.WriteLine("\nPlease check if Google Calendar has 3 events."); PrintSperateLine(); Console.WriteLine("\nTest: local has the latest version\n"); Console.ReadKey(); myList.GetGGItemAt(0).SetDescription(myList.GetGGItemAt(0).GetDescription() + " local updated"); Console.WriteLine("\nupdate local: " + myList.GetGGItemAt(0).ToString()); GGItem newGGItem = new GGItem("description_test_new", DateTime.Now.AddDays(5).AddHours(3), "tag_test3"); myList.AddGGItem(newGGItem); Console.WriteLine("\nadd local: " + newGGItem.ToString()); PreTestPrint(myList); mySync.SyncWithGoogleCalendar(myList); PostTestPrint(myList); Console.WriteLine("\nPlease check Google Calendar: event0->description: 'local updated' appended"); Console.WriteLine("\nPlease check Google Calendar: new event added: tag_test3"); PrintSperateLine(); Console.WriteLine("\nTest: server has the latest version\n"); Console.WriteLine("\nPlease modified one task, add one task and delete one task on calendar"); Console.ReadKey(); PreTestPrint(myList); mySync.SyncWithGoogleCalendar(myList); PostTestPrint(myList); Console.WriteLine("\nPlease check: there should be 4 items after sync"); PrintSperateLine(); Console.WriteLine("\nTest: both have some latest events\n"); myList.GetGGItemAt(2).SetTag(myList.GetGGItemAt(2).GetTag() + " local update"); Console.WriteLine("\nupdate local: " + myList.GetGGItemAt(2).ToString()); Console.WriteLine("\nPlease update on server"); Console.ReadKey(); PreTestPrint(myList); mySync.SyncWithGoogleCalendar(myList); PostTestPrint(myList); Console.WriteLine("\nPlease check Google Calendar: event_2->tag: 'local update' appended"); Console.WriteLine("\nPlease check: there should be 4 items after sync"); PrintSperateLine(); Console.WriteLine("\nTest: delete from server"); Console.WriteLine("\nRemove at local list: " + myList.GetGGItemAt(0)); myList.GetDeletedList().Add(myList.GetGGItemAt(0)); myList.GetInnerList().Remove(myList.GetGGItemAt(0)); Console.ReadKey(); PreTestPrint(myList); mySync.SyncWithGoogleCalendar(myList); PostTestPrint(myList); Console.WriteLine("\nPlease check Google Calendar: there should be 3 events"); Console.ReadKey(); }
private void GGSyncCornerCaseTest() { GGSync syncTest = new GGSync("*****@*****.**", "cs2103trocks"); GGList testList = new GGList(); PrintSperateLine(); Console.WriteLine("\nPlease delete GG to-do calendar."); Console.ReadKey(); Console.WriteLine("\nTest: Sync with empty GGList"); Console.ReadKey(); PreTestPrint(testList); syncTest.SyncWithGoogleCalendar(testList); PostTestPrint(testList); Console.WriteLine("\nPlease check: there should be no event on both sides"); PrintSperateLine(); Console.WriteLine("\nTest: Add to empty calendar"); Console.ReadKey(); for (int i = 0; i < 3; i++) { testList.AddGGItem(new GGItem("corner test description " + i, DateTime.Now.AddDays(-i).AddHours(i), "corner test tag " + i)); } PreTestPrint(testList); syncTest.SyncWithGoogleCalendar(testList); PostTestPrint(testList); Console.WriteLine("\nPlease check: there should be 3 events on Google Calendar"); PrintSperateLine(); Console.WriteLine("\nTest: Add to non-empty calendar"); Console.ReadKey(); for (int i = 3; i < 5; i++) { GGItem testItem = new GGItem("corner test description " + i, DateTime.Now.AddDays(-i).AddHours(i), "corner test tag " + i); testList.AddGGItem(testItem); Console.WriteLine("\nAdd to local GGList: " + testItem.ToString()); } PreTestPrint(testList); syncTest.SyncWithGoogleCalendar(testList); PostTestPrint(testList); Console.WriteLine("\nPlease check: there should be 5 events on Google Calendar"); PrintSperateLine(); Console.WriteLine("\nTest: Sync after deleting all events in local GGList"); Console.ReadKey(); testList.ClearGGList(); PreTestPrint(testList); syncTest.SyncWithGoogleCalendar(testList); PostTestPrint(testList); Console.WriteLine("\nPlease check: there should be no event on Google Calendar"); Console.ReadKey(); PrintSperateLine(); Console.WriteLine("\nTest: Sync after deleting all events on Google Calendar"); for (int i = 0; i < 3; i++) { testList.AddGGItem(new GGItem("corner test description " + i, DateTime.Now.AddDays(-i).AddHours(i), "corner test tag " + i)); } syncTest.SyncWithGoogleCalendar(testList); Console.WriteLine("\nPlease delete all 3 events on Google Calendar"); Console.ReadKey(); PreTestPrint(testList); syncTest.SyncWithGoogleCalendar(testList); PostTestPrint(testList); Console.WriteLine("Please check: there should be no events in local GGList"); Console.ReadKey(); PrintSperateLine(); Console.WriteLine("\nTest: Delete the same event both sides"); testList.AddGGItem(new GGItem("corner test description 0", DateTime.Now, "corner test tag 0")); syncTest.SyncWithGoogleCalendar(testList); Console.WriteLine("Please delete the only event on Google Calendar"); Console.ReadKey(); testList.ClearGGList(); PreTestPrint(testList); syncTest.SyncWithGoogleCalendar(testList); PostTestPrint(testList); Console.WriteLine("Please check: there should be no event on both sides"); Console.ReadKey(); }
/// <summary> /// Update GGList /// </summary> /// <param name="addToLocal">List of GGItems to be added to local GGList</param> /// <param name="removeFromLocal">List of GGItems to be removed from local GGList</param> /// <param name="toBeSyncedList">List of GGItems to be synced</param> /// <param name="toBeDeletedList">List of GGItems to be deleted on Google calendar</param> private void UpdateLocalList(List<GGItem> addToLocal, List<GGItem> removeFromLocal, GGList ggList, List<GGItem> toBeDeletedist) { for (int i = 0; i < removeFromLocal.Count; i++) { ggList.RemoveGGItem(removeFromLocal[i]); } for (int i = 0; i < addToLocal.Count; i++) { ggList.AddGGItem(addToLocal[i]); } toBeDeletedist.Clear(); }