public void Teardown() { try { userid = 2; controller.ModelState.Clear(); var result = controller.DeleteDishes(item.id, userid); IngredientsController controllerIng = new IngredientsController(); var result2 = controllerIng.GetIngredient().ToList(); Ingredient temping = result2.Find(e => e.name == "testpepperoni"); if (temping != null) { controllerIng.DeleteIngredient(temping.id, userid); } temping = result2.Find(e => e.name == "ost"); if (temping != null) { controllerIng.DeleteIngredient(temping.id, userid); } } catch (Exception e) { } }
public async void Can_get_ingredient_without_recipe() { using var context = new RecAPIContext(ContextOptions); var controller = new IngredientsController(context); var ingredientActionResult = await controller.GetIngredient(1); var ingredient = ingredientActionResult.Value; Assert.Equal("Fusilli", ingredient.Name); }
public void Setup() { controller = new IngredientsController(); item = GetDemoIngredient(); var result = controller.PostIngredient(item); List <Ingredient> listing = controller.GetIngredient().ToList(); var ingredient = listing[listing.Count() - 1]; item.id = ingredient.id; }
public void GetIngredientTest() { Ingredient expectedIngredient = new Ingredient(); expectedIngredient.Id = 1; expectedIngredient.Name = "Name1"; _ingredientsService.Setup(i => i.GetIngredient(1)).Returns(expectedIngredient); ActionResult <Ingredient> resultIngredient = _ingredientsController.GetIngredient(1); Assert.AreEqual(expectedIngredient.Id, resultIngredient.Value.Id); Assert.AreEqual(expectedIngredient.Name, resultIngredient.Value.Name); }
public void PutDishes_StringNoIngredient() { IngredientsController ingcontroller = new IngredientsController(); List <Ingredient> ingredientswithID = ingcontroller.GetIngredient().ToList(); List <Ingredient> ingredienstodelete = new List <Ingredient>(); Ingredient temping = item.Ingredient.First(); ingredienstodelete = ingredientswithID.Where(e => e.name == temping.name).ToList(); foreach (var ing in ingredienstodelete) { ingcontroller.DeleteIngredient(ing.id, 2); } item.Ingredient = null; var specialpricenull = controller.PutDishess(item.id, 2, item); Assert.AreEqual("There was no ingredient attached", specialpricenull); }
public void GetIngredient_InvalidId_ReturnsNotFound() { // Arrange int invalidRecipeId = 2; ingredientsServiceMock = new Mock <IIngredientsService>(); ingredientsServiceMock .Setup(m => m.GetById(invalidRecipeId)) .Returns(null as IngredientDto); ingredientsController = new IngredientsController(ingredientsServiceMock.Object, mapper); // Act var result = ingredientsController.GetIngredient(invalidRecipeId); // Assert Assert.IsTrue(result.GetType() == typeof(NotFoundResult)); }
public void GetIngredient_ValidId_ReturnsOk() { // Arrange int validRecipeId = 1; ingredientsServiceMock = new Mock <IIngredientsService>(); ingredientsServiceMock .Setup(m => m.GetById(validRecipeId)) .Returns(new IngredientDto()); ingredientsController = new IngredientsController(ingredientsServiceMock.Object, mapper); // Act var result = ingredientsController.GetIngredient(validRecipeId); // Assert Assert.IsTrue(result.GetType() == typeof(OkObjectResult)); }
public void GetIngredients_ReturnsListOfIngredients() { var item = controller.GetIngredient(); Assert.IsNotNull(item); }