// GET: ToDoList/Details/5 public async Task <IActionResult> Details(int?id) { if (id == null) { return(NotFound()); } var list = await _toDoListService.FindById(id.Value); if (list == null) { return(NotFound()); } return(View(list)); }
// GET: Task public async Task <IActionResult> Index(int listId) { ToDoList toDoToDoList = await _toDoListService.FindById(listId); if (toDoToDoList == null) { return(NotFound()); } var taskIndexViewModel = new TaskIndexViewModel { Id = listId, ListName = toDoToDoList.Name, ToDoTasks = toDoToDoList.Tasks.Where(t => t.Done == false).OrderByDescending(x => x.Id), CompletedTasks = toDoToDoList.Tasks.Where(t => t.Done).OrderByDescending(x => x.Id) }; return(View(taskIndexViewModel)); }
public void Edit_ToDoListExists_ReturnEditViewName() { //Arrange int toDoListId = 1; ToDoList toDoList = CreateToDoListDefault(); IToDoListService toDoListServiceFake = A.Fake <IToDoListService>(); A.CallTo(() => toDoListServiceFake.FindById(A <int> .Ignored)) .Returns(toDoList); ToDoListController sut = CreateSut(toDoListServiceFake); //Act IActionResult result = sut.Edit(toDoListId).Result; //Assert result .As <ViewResult>() .ViewName .Should() .Be("Edit"); }
public void Edit_ToDoListNotFound_ReturnNotFoundStatusCode() { //Arrange int toDoListId = 1; int notFoundStatusCode = 404; IToDoListService toDoListServiceFake = A.Fake <IToDoListService>(); A.CallTo(() => toDoListServiceFake.FindById(A <int> .Ignored)) .Returns(System.Threading.Tasks.Task.FromResult((ToDoList)null)); ToDoListController sut = CreateSut(toDoListServiceFake); //Act IActionResult result = sut.Edit(toDoListId).Result; //Assert result .As <NotFoundResult>() .StatusCode .Should() .Be(notFoundStatusCode); }