public async void Post_SingleTodo_Valid_ShouldSucceed() { var _dbContext = new TodoContext(new DbContextOptionsBuilder <TodoContext>().UseInMemoryDatabase("todo-db3").Options); TodoController controller = new TodoController(_dbContext); var result = await controller.AddTodo(new TodoItem { Description = "Laundry", Date = DateTime.UtcNow }); Assert.Equal(201, ((StatusCodeResult)result).StatusCode); }
public async void Post_SingleTodo_InvalidId_ShouldReturn400() { var _dbContext = new TodoContext(new DbContextOptionsBuilder <TodoContext>().UseInMemoryDatabase("todo-db2").Options); TodoController controller = new TodoController(_dbContext); var result = await controller.AddTodo(new TodoItem { Id = Guid.NewGuid() }); Assert.IsType <BadRequestResult>(result); }
public async void Delete_Item_ShouldSucceed() { var _dbContext = new TodoContext(new DbContextOptionsBuilder <TodoContext>().UseInMemoryDatabase("todo-db7").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.DeleteTodo(item.Id); Assert.IsType <OkResult>(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 AddTodo_Insert_Failed() { // Arrange todoController = new TodoController(todoMockDal); todoController.Request = new HttpRequestMessage(); todoController.Request.SetConfiguration(new HttpConfiguration()); //Act var result = todoController.AddTodo(new TodoDTO()); //Assert Assert.AreEqual(HttpStatusCode.InternalServerError, 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); }
public void AddTodo_Null_Request() { // Arrange todoController = new TodoController(todoMockDal); todoController.Request = new HttpRequestMessage(); todoController.Request.SetConfiguration(new HttpConfiguration()); //Act var result = todoController.AddTodo(null); //Assert ////Assert.IsInstanceOf<BadRequestResult>(result); Assert.AreEqual(HttpStatusCode.BadRequest, result.StatusCode); }
public void AddTodo_Positive() { // Arrange var tempTodoDal = new Mock <ITodoDal>(); tempTodoDal.Setup(m => m.Insert(It.IsAny <TodoDTO>())).Returns(1); todoMockDal = tempTodoDal.Object; todoController = new TodoController(todoMockDal); todoController.Request = new HttpRequestMessage(); todoController.Request.SetConfiguration(new HttpConfiguration()); //Act var result = todoController.AddTodo(new TodoDTO()); //Assert Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); }