/// <inheritdoc /> public ExistingIngredientDto CreateIngredient(NewIngredientDto newIngredientDto) { var newIngredient = Mapper.Map <Ingredient>(newIngredientDto); var createdIngredient = IngredientDbAccess.AddIngredient(newIngredient); return(Mapper.Map <ExistingIngredientDto>(createdIngredient)); }
public void CreateIngredient() { using var inMemoryDbContext = new InMemoryDbContext(); var vegetables = new ArticleGroup("Vegetables"); var tomato = new Article { Name = "Tomato", ArticleGroup = vegetables, IsInventory = false }; var piece = new Unit("Piece"); inMemoryDbContext.ArticleGroups.Add(vegetables); inMemoryDbContext.Articles.Add(tomato); inMemoryDbContext.Units.Add(piece); inMemoryDbContext.SaveChanges(); var testee = new IngredientDbAccess(inMemoryDbContext); var result = testee.AddIngredient(new Ingredient(tomato, 2, piece)); inMemoryDbContext.SaveChanges(); inMemoryDbContext.Ingredients.Should().Contain(result); }
public void GetIngredient() { using var inMemoryDbContext = new InMemoryDbContext(); var vegetables = new ArticleGroup("Vegetables"); var tomato = new Article { Name = "Tomato", ArticleGroup = vegetables, IsInventory = false }; var piece = new Unit("Piece"); inMemoryDbContext.ArticleGroups.Add(vegetables); inMemoryDbContext.Articles.Add(tomato); inMemoryDbContext.Units.Add(piece); var ingredient = inMemoryDbContext.Ingredients.Add(new Ingredient(tomato, 2, piece)); inMemoryDbContext.SaveChanges(); var testee = new IngredientDbAccess(inMemoryDbContext); var result = testee.GetIngredient(ingredient.Entity.IngredientId); result.Article.Name.Should().Be("Tomato"); }
/// <inheritdoc /> public IEnumerable <ExistingIngredientDto> GetAllIngredients() { var ingredients = IngredientDbAccess.GetIngredients(); return(Mapper.Map <IEnumerable <ExistingIngredientDto> >(ingredients)); }
/// <inheritdoc /> public void DeleteIngredient(DeleteIngredientDto deleteIngredientDto) { IngredientDbAccess.DeleteIngredient(IngredientDbAccess.GetIngredient(deleteIngredientDto.IngredientId)); }