public async void CanDeleteIngredient() { DbContextOptions <CookBookDbContext> options = new DbContextOptionsBuilder <CookBookDbContext>().UseInMemoryDatabase("CanDeleteIngredient").Options; using (CookBookDbContext context = new CookBookDbContext(options)) { //Arrange Ingredients ingredient = new Ingredients(); ingredient.ID = 1; ingredient.Name = "Swag"; Ingredients ingredient2 = new Ingredients(); ingredient2.ID = 2; ingredient2.Name = "Energy"; //Act IngredientsController ingredientsController = new IngredientsController(context, configuration); await ingredientsController.Post(ingredient); await ingredientsController.Post(ingredient2); await ingredientsController.Delete(ingredient.ID); var result = context.Ingredients.FirstOrDefault(c => c.ID == ingredient.ID); //Assert Assert.Null(result); } }
public void Delete_IngredientNotFound_ReturnsNotFound() { var sut = new IngredientsController(_mealService.Object, _dtoConverter); var response = sut.Delete("doesn't exist"); Assert.IsType <NotFoundResult>(response); }
public void Delete_IngredientFound_ReturnsOk() { _mealService.Setup(m => m.TryDeleteIngredient(_ingredientName)).Returns(true); var sut = new IngredientsController(_mealService.Object, _dtoConverter); var response = sut.Delete(_ingredientName); Assert.IsType <NoContentResult>(response); }
public async Task Delete_ReturnOk() { //Arrange _mockService.MockDeleteAsync(); //Act var result = await _controller.Delete(_idTestIngredient); //Assert var viewResult = Assert.IsType <OkResult>(result); _mockService.Verify(); }