public async void Update_NonExistent_Item_ShouldReturnNotFound() { var _dbContext = new TodoContext(new DbContextOptionsBuilder <TodoContext>().UseInMemoryDatabase("todo-db5").Options); TodoController controller = new TodoController(_dbContext); var id = Guid.NewGuid(); var result = await controller.UpdateTodo(id, new TodoItem { Id = id, Description = "Laundry 2", Date = DateTime.UtcNow, Completed = true }); Assert.IsType <NotFoundResult>(result); }
public async void Update_SingleTodo_WrongId_In_body_ShoulReturn400() { var _dbContext = new TodoContext(new DbContextOptionsBuilder <TodoContext>().UseInMemoryDatabase("todo-db4").Options); TodoController controller = new TodoController(_dbContext); await controller.AddTodo(new TodoItem { Description = "Laundry", Date = DateTime.UtcNow }); var item = _dbContext.TodoItems.First(); var result = await controller.UpdateTodo(item.Id, new TodoItem {}); Assert.IsType <BadRequestResult>(result); }
public void UpdateTodo_Positive() { // Arrange todoController = new TodoController(todoMockDal); todoController.Request = new HttpRequestMessage(); todoController.Request.SetConfiguration(new HttpConfiguration()); //Act var result = todoController.UpdateTodo(new TodoDTO()); //Assert Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); }
public void UpdateTodo_Invalid_Request() { // Arrange todoController = new TodoController(todoMockDal); todoController.Request = new HttpRequestMessage(); todoController.Request.SetConfiguration(new HttpConfiguration()); //Act var result = todoController.UpdateTodo(null); //Assert //Assert.IsInstanceOf<BadRequestResult>(result); Assert.AreEqual(HttpStatusCode.BadRequest, result.StatusCode); }
public async void Update_SingleTodo_ValidId_ValidBody_ShouldSucceed() { var _dbContext = new TodoContext(new DbContextOptionsBuilder <TodoContext>().UseInMemoryDatabase("todo-db4").Options); TodoController controller = new TodoController(_dbContext); await controller.AddTodo(new TodoItem { Description = "Laundry", Date = DateTime.UtcNow }); var item = _dbContext.TodoItems.First(); var result = await controller.UpdateTodo(item.Id, new TodoItem { Id = item.Id, Description = "Laundry 2", Date = item.Date, Completed = true }); Assert.IsType <OkResult>(result); item = _dbContext.TodoItems.First(); Assert.Equal("Laundry 2", item.Description); Assert.True(item.Completed); }