/// <summary> /// checks basic properties /// </summary> private void basic_properties() { it["new task is false"] = () => { TaskItem t1 = new TaskItem(1, "description1"); t1.Completed.should_be_false(); }; }
/// <summary> /// checks json parsing /// </summary> private void json_parsing_works() { it["all attributes specified"] = () => { TaskItem t1 = new TaskItem(1, "description1", false); string json = JsonConvert.SerializeObject(t1); TaskItem t2 = JsonConvert.DeserializeObject<TaskItem>(json); t1.Completed.should_be(t2.Completed); t1.Description.should_be(t1.Description); t1.Id.should_be(t2.Id); }; it["missing attributes"] = () => { TaskItem t1 = new TaskItem(1, "description1"); string json = JsonConvert.SerializeObject(t1); TaskItem t2 = JsonConvert.DeserializeObject<TaskItem>(json); t1.Completed.should_be(t2.Completed); t1.Description.should_be(t1.Description); t1.Id.should_be(t2.Id); }; }
/// <summary> /// Add task /// </summary> /// <param name="description"></param> /// <param name="completed"></param> public void AddTask(string description, bool completed = false) { LastAddedtTaskId++; TaskItem ti = new TaskItem(LastAddedtTaskId,description,completed); AllTasks.Add(ti); }
/// <summary> /// togle the state of given task /// </summary> /// <param name="t"></param> private void ToggleCopleteTask(TaskItem t) { t.Completed = !t.Completed; UpdateCounts(); }
/// <summary> /// delete given task /// </summary> /// <param name="t"></param> private void DeleteIndividualTask(TaskItem t) { Tasks.Remove(t); UpdateCounts(); }
/// <summary> /// Test behaviour when updating a task /// </summary> void updating_a_task() { context["completing a task"] = () => { before = () => { _tasks = new List<TaskItem> {new TaskItem(1, "task1", false)}; _taskRepository.GetTasks().Returns(Task.FromResult(_tasks)); _taskListViewModel = new TaskListViewModel(_taskRepository, _collectionSource); _taskListViewModel.VisibleTasks.Items.Count().should_be(1); _taskListViewModel.ClearCompletedMessage.should_be_empty(); _taskListViewModel.ToggleStateOfTask.Execute(_tasks[0]); }; it["item not visible in active"] = () => { _taskListViewModel.SelectedIndex = (int) TaskListState.Active; _taskListViewModel.VisibleTasks.Items.Count().should_be(0); }; it["item visible in all"] = () => { _taskListViewModel.SelectedIndex = (int)TaskListState.All; _taskListViewModel.VisibleTasks.Items.Count().should_be(1); }; it["item visible in complete"] = () => { _taskListViewModel.SelectedIndex = (int)TaskListState.Completed; _taskListViewModel.VisibleTasks.Items.Count().should_be(1); }; it["correct active message"] = () => _taskListViewModel.TasksLeftMessage.should_be_empty(); it["correct completed message"] = () => _taskListViewModel.ClearCompletedMessage.should_be("Clear Completed (" + 1 + ")"); }; context["deleting a task"] = () => { before = () => { _tasks = new List<TaskItem>(); TaskItem taskItem = new TaskItem(1, "task1", true); _tasks.Add(taskItem); _taskRepository.GetTasks().Returns(Task.FromResult(_tasks)); _taskListViewModel = new TaskListViewModel(_taskRepository, _collectionSource); _taskListViewModel.VisibleTasks.Items.ToArray().Count().should_be(1); _taskListViewModel.DeleteTask.Execute(taskItem); }; it["item not visible"] = () => _taskListViewModel.VisibleTasks.IsEmpty().should_be_true(); it["correct active message"] = () => _taskListViewModel.TasksLeftMessage.should_be_empty(); it["correct completed message"] = () => _taskListViewModel.ClearCompletedMessage.should_be_empty(); }; context["editing a task"] = () => { TaskItem taskItem = new TaskItem(1, "task1", true); before = () => { _tasks = new List<TaskItem> {taskItem}; _taskListViewModel = new TaskListViewModel(_taskRepository, _collectionSource); }; it["shows updated task message"] = () => { _tasks[0].Description = "new task description"; _tasks[0].Description.should_be("new task description"); }; }; }