public IEnumerable <IngredientListModel> GetAll() { using var dbContext = _dbContextFactory.Create(); return(dbContext.Ingredients .Select(e => IngredientMapper.MapIngredientEntityToListModel(e)).ToArray()); }
public void GetAll_Single_SeededWater() { var ingredient = _fixture.Repository .GetAll() .Single(i => i.Id == Seeds.Water.Id); Assert.Equal(IngredientMapper.MapListModel(Seeds.Water), ingredient, IngredientListModel.AllMembersComparer); }
public IEnumerable <IngredientListModel> GetAll() { using (var dbContext = dbContextFactory.CreateDbContext()) { return(dbContext.Ingredients .Select(e => IngredientMapper.MapIngredientEntityToListModel(e))); } }
public IngredientDetailModel GetById(Guid id) { using var dbContext = _dbContextFactory.Create(); var entity = dbContext.Ingredients.Single(t => t.Id == id); return(IngredientMapper.MapIngredientEntityToDetailModel(entity)); }
public void GetAll_Single_SeededWater() { var ingredient = _ingredientRepositorySUT .GetAll() .Single(i => i.Id == IngredientSeeds.Water.Id); Assert.Equal(IngredientMapper.MapEntityToListModel(IngredientSeeds.Water), ingredient); }
public IngredientDetailModel GetById(Guid id) { using (var dbContext = dbContextFactory.CreateDbContext()) { //SELECT * FROM Ingredient WHERE Id = id; var entity = dbContext.Ingredients.First(t => t.Id == id); return(IngredientMapper.MapIngredientEntityToDetailModel(entity)); } }
public void Update(IngredientDetailModel model) { using (var dbContext = dbContextFactory.CreateDbContext()) { var entity = IngredientMapper.MapIngredientDetailModelToEntity(model); dbContext.Ingredients.Update(entity); dbContext.SaveChanges(); } }
public IngredientDetailModel Create(IngredientDetailModel model) { using (var dbContext = dbContextFactory.CreateDbContext()) { var entity = IngredientMapper.MapIngredientDetailModelToEntity(model); dbContext.Ingredients.Add(entity); dbContext.SaveChanges(); return(IngredientMapper.MapIngredientEntityToDetailModel(entity)); } }
public IngredientDetailModel InsertOrUpdate(IngredientDetailModel model) { using var dbContext = _dbContextFactory.Create(); var entity = IngredientMapper.MapIngredientDetailModelToEntity(model); dbContext.Ingredients.Update(entity); dbContext.SaveChanges(); return(IngredientMapper.MapIngredientEntityToDetailModel(entity)); }
public void NewIngredient_InsertOrUpdate_IngredientAdded() { //Arrange var ingredient = new IngredientDetailModel() { Name = "Water", Description = "Mineral water" }; //Act ingredient = _ingredientRepositorySUT.InsertOrUpdate(ingredient); //Assert using var dbxAssert = _dbContextFactory.Create(); var ingredientFromDb = dbxAssert.Ingredients.Single(i => i.Id == ingredient.Id); Assert.Equal(ingredient, IngredientMapper.MapEntityToDetailModel(ingredientFromDb)); }
public void NewIngredient_InsertOrUpdate_IngredientAdded() { //Arrange var ingredient = new IngredientDetailModel() { Name = "Water", Description = "Mineral water" }; //Act ingredient = _fixture.Repository.InsertOrUpdate(ingredient); //Assert using var dbxAssert = _fixture.DbContextFactory.CreateDbContext(); var ingredientFromDb = dbxAssert.Ingredients.Single(i => i.Id == ingredient.Id); Assert.Equal(ingredient, IngredientMapper.MapDetailModel(ingredientFromDb), IngredientDetailModel.AllMembersComparer); }
protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); CommentMapper.Map(modelBuilder.Entity <Comment>()); IngredientMapper.Map(modelBuilder.Entity <Ingredient>()); LikeMapper.Map(modelBuilder.Entity <Like>()); MeasureMapper.Map(modelBuilder.Entity <Measure>()); RecipeTagMapper.Map(modelBuilder.Entity <RecipeTag>()); TagMapper.Map(modelBuilder.Entity <Tag>()); RecipeMapper.Map(modelBuilder.Entity <Recipe>()); UserMapper.Map(modelBuilder.Entity <User>()); foreach (var relationship in modelBuilder.Model.GetEntityTypes().SelectMany(e => e.GetForeignKeys())) { relationship.DeleteBehavior = DeleteBehavior.Restrict; } }
public void CorrectMapping_ToIngredient() { //Arrange var options = Utils.GetOptions(nameof(CorrectMapping_ToIngredient)); //Act & Assert using (var assertContext = new CocktailMagicianContext(options)) { var ingredientDTO = new IngredientDTO { Name = "Coke" }; var sut = new IngredientMapper(); var result = sut.MapToIngredient(ingredientDTO); Assert.IsInstanceOfType(result, typeof(Ingredient)); Assert.AreEqual(ingredientDTO.Name, result.Name); } }
public void SeededWater_InsertOrUpdate_IngredientUpdated() { //Arrange var ingredient = new IngredientDetailModel() { Id = Seeds.Water.Id, Name = Seeds.Water.Name, Description = Seeds.Water.Description, }; ingredient.Name += "updated"; ingredient.Description += "updated"; //Act _fixture.Repository.InsertOrUpdate(ingredient); //Assert using var dbxAssert = _fixture.DbContextFactory.CreateDbContext(); var ingredientFromDb = dbxAssert.Ingredients.Single(i => i.Id == ingredient.Id); Assert.Equal(ingredient, IngredientMapper.MapDetailModel(ingredientFromDb), IngredientDetailModel.AllMembersComparer); }
public void SeededWater_InsertOrUpdate_IngredientUpdated() { //Arrange var ingredient = new IngredientDetailModel() { Id = IngredientSeeds.Water.Id, Name = IngredientSeeds.Water.Name, Description = IngredientSeeds.Water.Description, }; ingredient.Name += "updated"; ingredient.Description += "updated"; //Act _ingredientRepositorySUT.InsertOrUpdate(ingredient); //Assert using var dbxAssert = _dbContextFactory.Create(); var ingredientFromDb = dbxAssert.Ingredients.Single(i => i.Id == ingredient.Id); Assert.Equal(ingredient, IngredientMapper.MapEntityToDetailModel(ingredientFromDb)); }
public void CorretMapping_ToDTO() { //Arrange var options = Utils.GetOptions(nameof(CorretMapping_ToDTO)); Utils.GetInMemoryDataBase(options); //Act & Assert using (var assertContext = new CocktailMagicianContext(options)) { var ingredient = assertContext.Ingredients .Include(ic => ic.IngredientsCocktails) .ThenInclude(c => c.Cocktail) .FirstOrDefault(i => i.Id == 2); var sut = new IngredientMapper(); var result = sut.MapToIngredientDTO(ingredient); Assert.IsInstanceOfType(result, typeof(IngredientDTO)); Assert.AreEqual(ingredient.Id, result.Id); Assert.AreEqual(ingredient.Name, result.Name); Assert.AreEqual(ingredient.IngredientsCocktails.Count, result.CocktailDTOs.Count); } }
public List <IngredientModel> GetAllIngredients() { return(IngredientMapper.IngredientsToIngredientModels(_ingredientRepo.GetAll())); }
public IngredientModel GetIngredientById(int id) { return(IngredientMapper.IngredientToIngredientModel(_ingredientRepo.GetById(id))); }
public List <IngredientModel> GetIngredientsByType(IngredientType type) { return(IngredientMapper.IngredientsToIngredientModels(_ingredientRepo.GetAll().Where(i => i.Type == type).ToList())); }
public IngredientMapperTests() { _ingredientMapper = new IngredientMapper(); }
public void GetById_SeededWater() { var ingredient = _fixture.Repository.GetById(Seeds.Water.Id); Assert.Equal(IngredientMapper.MapDetailModel(Seeds.Water), ingredient, IngredientDetailModel.AllMembersComparer); }
public void GetById_SeededWater() { var ingredient = _ingredientRepositorySUT.GetById(IngredientSeeds.Water.Id); Assert.Equal(IngredientMapper.MapIngredientEntityToDetailModel(IngredientSeeds.Water), ingredient, IngredientDetailModel.AllMembersComparer); }
public void GetById_SeededWater() { var ingredient = _ingredientRepositorySUT.GetById(IngredientSeeds.Water.Id); Assert.Equal(IngredientMapper.MapEntityToDetailModel(IngredientSeeds.Water), ingredient); }