public async Task Post_ReturnsNewlyCreatedTodoItems() { // Arrange var todo = FakeDatasHelper.GetTestTodos().FirstOrDefault(); var mockRepo = new Mock <ITodoItemRepository>(); mockRepo.Setup(repo => repo.AddAsync(todo)) .Returns(Task.CompletedTask) .Verifiable(); var controller = new TemporaryController(mockRepo.Object); // Act var result = await controller.Post(new TemporaryController.NewTodoModel() { Name = "test" }); // Assert var okResult = Assert.IsType <OkObjectResult>(result); var returnTodo = Assert.IsType <TodoItem>(okResult.Value); Assert.False(returnTodo.IsComplete); Assert.Equal("test", returnTodo.Name); Assert.Equal(DateTimeOffset.Now.Day, returnTodo.ModifyTime.Day); Assert.Equal(DateTimeOffset.Now.Day, returnTodo.CreateTime.Day); Assert.Empty(returnTodo.Steps); }
public async Task Post_ReturnsBadReqeust_GivenInvalidModel() { // Arrange var mockRepo = new Mock <ITodoItemRepository>(); var controller = new TemporaryController(mockRepo.Object); controller.ModelState.AddModelError("error", "some error"); // Act var result = await controller.Post(model : null); // Assert Assert.IsType <BadRequestObjectResult>(result); }