Example #1
0
        public IEnumerable <IngredientListModel> GetAll()
        {
            using var dbContext = _dbContextFactory.Create();

            return(dbContext.Ingredients
                   .Select(e => IngredientMapper.MapIngredientEntityToListModel(e)).ToArray());
        }
Example #2
0
        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);
        }
Example #3
0
 public IEnumerable <IngredientListModel> GetAll()
 {
     using (var dbContext = dbContextFactory.CreateDbContext())
     {
         return(dbContext.Ingredients
                .Select(e => IngredientMapper.MapIngredientEntityToListModel(e)));
     }
 }
Example #4
0
        public IngredientDetailModel GetById(Guid id)
        {
            using var dbContext = _dbContextFactory.Create();

            var entity = dbContext.Ingredients.Single(t => t.Id == id);

            return(IngredientMapper.MapIngredientEntityToDetailModel(entity));
        }
Example #5
0
        public void GetAll_Single_SeededWater()
        {
            var ingredient = _ingredientRepositorySUT
                             .GetAll()
                             .Single(i => i.Id == IngredientSeeds.Water.Id);

            Assert.Equal(IngredientMapper.MapEntityToListModel(IngredientSeeds.Water), ingredient);
        }
Example #6
0
 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));
     }
 }
Example #7
0
 public void Update(IngredientDetailModel model)
 {
     using (var dbContext = dbContextFactory.CreateDbContext())
     {
         var entity = IngredientMapper.MapIngredientDetailModelToEntity(model);
         dbContext.Ingredients.Update(entity);
         dbContext.SaveChanges();
     }
 }
Example #8
0
 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));
     }
 }
Example #9
0
        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));
        }
Example #10
0
        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));
        }
Example #11
0
        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);
        }
Example #12
0
        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;
            }
        }
Example #13
0
        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);
            }
        }
Example #14
0
        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);
        }
Example #15
0
        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));
        }
Example #16
0
        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);
            }
        }
Example #17
0
 public List <IngredientModel> GetAllIngredients()
 {
     return(IngredientMapper.IngredientsToIngredientModels(_ingredientRepo.GetAll()));
 }
Example #18
0
 public IngredientModel GetIngredientById(int id)
 {
     return(IngredientMapper.IngredientToIngredientModel(_ingredientRepo.GetById(id)));
 }
Example #19
0
 public List <IngredientModel> GetIngredientsByType(IngredientType type)
 {
     return(IngredientMapper.IngredientsToIngredientModels(_ingredientRepo.GetAll().Where(i => i.Type == type).ToList()));
 }
 public IngredientMapperTests()
 {
     _ingredientMapper = new IngredientMapper();
 }
Example #21
0
        public void GetById_SeededWater()
        {
            var ingredient = _fixture.Repository.GetById(Seeds.Water.Id);

            Assert.Equal(IngredientMapper.MapDetailModel(Seeds.Water), ingredient, IngredientDetailModel.AllMembersComparer);
        }
Example #22
0
        public void GetById_SeededWater()
        {
            var ingredient = _ingredientRepositorySUT.GetById(IngredientSeeds.Water.Id);

            Assert.Equal(IngredientMapper.MapIngredientEntityToDetailModel(IngredientSeeds.Water), ingredient, IngredientDetailModel.AllMembersComparer);
        }
Example #23
0
        public void GetById_SeededWater()
        {
            var ingredient = _ingredientRepositorySUT.GetById(IngredientSeeds.Water.Id);

            Assert.Equal(IngredientMapper.MapEntityToDetailModel(IngredientSeeds.Water), ingredient);
        }