public void DeleteTodo() { List <TodoNote> updateList = new List <TodoNote>(); HandleJson.WriteToJsonFile <List <TodoNote> >("Test.json", updateList); TodoNote addObject = new TodoNote(); string testString = "This is a delete test!"; string testString2 = "This is also a delete test!"; addObject.AddTask(testString, "Test.json"); addObject.AddTask(testString2, "Test.json"); List <TodoNote> todoList = HandleJson.ReadFromJsonFile <List <TodoNote> >("Test.json"); int sizeBeforeDelete = todoList.Count; TodoNote temp = new TodoNote(); temp.DeleteTask(1, "Test.json"); List <TodoNote> newTodoList = HandleJson.ReadFromJsonFile <List <TodoNote> >("Test.json"); int sizeAfterDelete = newTodoList.Count; // The new size of the list should match the old size -1 Assert.Equal(sizeBeforeDelete - 1, sizeAfterDelete); }
static void Main(string[] args) { Console.WriteLine("Welcome to this TODO application!"); Console.WriteLine("Commands supported: Add 'Your task'/ Do #TaskNumber / Print -> Prints all items!"); Console.WriteLine("Type 'quit' to exit the application"); string path = "todoList.json"; bool quitApplication = false; while (!quitApplication) { quitApplication = true; string userInput = Console.ReadLine(); string[] wordSplit = userInput.Split(" ", 2); string inputCommand = wordSplit[0]; // Close application if input = q quitApplication = (string.Compare(inputCommand.ToLower(), "quit") == 0) ? true : false; if (quitApplication) { break; } // Removes type sensitive input and compares input if (string.Compare(inputCommand.ToLower(), "add") == 0) { string inputText = wordSplit[1]; TodoNote newTask = new TodoNote(); newTask.AddTask(inputText, path); } else if (string.Compare(inputCommand.ToLower(), "print") == 0) { TodoNote newTask = new TodoNote(); newTask.ShowAllTasks(); } else if (string.Compare(inputCommand.ToLower(), "do") == 0) { string convertNumber = wordSplit[1]; int number; if (int.TryParse(convertNumber, out number)) { TodoNote newTask = new TodoNote(); newTask.DeleteTask(number, path); } else { Console.WriteLine("Something went wrong! Try again: Do <int>"); } } else { Console.WriteLine("Unknown command: {0}", userInput); } } }
public void TestAppendToJsonFile() { List <TodoNote> updateList = new List <TodoNote>(); HandleJson.WriteToJsonFile <List <TodoNote> >("Test.json", updateList); TodoNote addObject = new TodoNote(); string testString = "This is a new test!"; string testString2 = "Append to the now test!"; addObject.AddTask(testString, "Test.json"); addObject.AddTask(testString2, "Test.json"); TodoNote temp = new TodoNote(); List <TodoNote> todoList = HandleJson.ReadFromJsonFile <List <TodoNote> >("Test.json"); int lastTodo = todoList.Count; string expectTest2 = todoList[lastTodo - 1].task; // Last TODO object should be the last element Assert.Equal(testString2, expectTest2); }
// Test adding to a empty Json file public void TestAddEmptyJsonFile() { // Start with a empty test List <TodoNote> updateList = new List <TodoNote>(); HandleJson.WriteToJsonFile <List <TodoNote> >("Test.json", updateList); TodoNote addObject = new TodoNote(); string testString = "This is a test string!"; addObject.AddTask(testString, "Test.json"); TodoNote temp = new TodoNote(); List <TodoNote> todoList = HandleJson.ReadFromJsonFile <List <TodoNote> >("Test.json"); int lastTodo = todoList.Count; string containedString = todoList[0].task; // The first object should be printed as the first position Assert.Equal(testString, containedString); }