public async Task PutTodo_WhenIdNotMatch_ReturnsBadRequest() { // Arrange var todoServiceMock = new Mock <ITodoService>(); var todoController = new TodoController(todoServiceMock.Object); var todo = GetTodo(); todo.Id = 1; // Act var result = await todoController.PutTodo(2, todo); // Assert Assert.IsAssignableFrom <BadRequestResult>(result); }
public async Task PutTodo_Should_ReturnBadRequest() { // Arrange var adapterMock = new Mock <ITodoAdapter>(); var loggerMock = new Mock <ILogger <TodoController> >(); var controller = new TodoController(adapterMock.Object, loggerMock.Object); // Act var result = await controller.PutTodo(5, null); // Assert var actionResult = Assert.IsAssignableFrom <IActionResult>(result); var returnValue = Assert.IsAssignableFrom <BadRequestObjectResult>(actionResult); Assert.Equal("Todo object is null", returnValue.Value); }
public async Task PutTodo_WhenFound_ReturnsOk() { // Arrange var todoServiceMock = new Mock <ITodoService>(); var todoController = new TodoController(todoServiceMock.Object); var todo = GetTodo(); todoServiceMock .Setup(s => s.UpdateAsync(It.IsAny <Todo>())) .Returns(Task.FromResult(true)); // Act var result = await todoController.PutTodo(todo.Id, todo); // Assert Assert.IsAssignableFrom <OkResult>(result); }
public async Task PutTodo_Should_ReturnOk() { // Arrange var adapterMock = new Mock <ITodoAdapter>(); var loggerMock = new Mock <ILogger <TodoController> >(); var testTodo = new TodoViewModel { TodoId = 2, Title = "Updated", Points = new List <TodoPointViewModel> { } }; var testTodos = GetTestTodos(); adapterMock.Setup(x => x.UpdateTodo(It.IsAny <TodoViewModel>())) .Callback(() => { var todo = testTodos.Where(x => x.TodoId == testTodo.TodoId).FirstOrDefault(); todo.Title = testTodo.Title; }); var controller = new TodoController(adapterMock.Object, loggerMock.Object); // Act var result = await controller.PutTodo(testTodo.TodoId, testTodo); var todoAfterUpdate = testTodos.Where(x => x.TodoId == testTodo.TodoId).FirstOrDefault(); // Assert var okResult = Assert.IsAssignableFrom <OkObjectResult>(result); var returnValue = Assert.IsAssignableFrom <TodoViewModel>(okResult.Value); Assert.Equal(testTodo.Title, todoAfterUpdate.Title); Assert.Equal(2, testTodos.Count); }