Пример #1
0
        public IEnumerable <IngredientListModel> GetAll()
        {
            using var dbContext = _dbContextFactory.Create();

            return(dbContext.Ingredients
                   .Select(e => IngredientMapper.MapIngredientEntityToListModel(e)).ToArray());
        }
Пример #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);
        }
Пример #3
0
 public IEnumerable <IngredientListModel> GetAll()
 {
     using (var dbContext = dbContextFactory.CreateDbContext())
     {
         return(dbContext.Ingredients
                .Select(e => IngredientMapper.MapIngredientEntityToListModel(e)));
     }
 }
Пример #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));
        }
Пример #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);
        }
Пример #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));
     }
 }
Пример #7
0
 public void Update(IngredientDetailModel model)
 {
     using (var dbContext = dbContextFactory.CreateDbContext())
     {
         var entity = IngredientMapper.MapIngredientDetailModelToEntity(model);
         dbContext.Ingredients.Update(entity);
         dbContext.SaveChanges();
     }
 }
Пример #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));
     }
 }
Пример #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));
        }
Пример #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));
        }
Пример #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);
        }
Пример #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;
            }
        }
Пример #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);
            }
        }
Пример #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);
        }
Пример #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));
        }
Пример #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);
            }
        }
Пример #17
0
 public List <IngredientModel> GetAllIngredients()
 {
     return(IngredientMapper.IngredientsToIngredientModels(_ingredientRepo.GetAll()));
 }
Пример #18
0
 public IngredientModel GetIngredientById(int id)
 {
     return(IngredientMapper.IngredientToIngredientModel(_ingredientRepo.GetById(id)));
 }
Пример #19
0
 public List <IngredientModel> GetIngredientsByType(IngredientType type)
 {
     return(IngredientMapper.IngredientsToIngredientModels(_ingredientRepo.GetAll().Where(i => i.Type == type).ToList()));
 }
 public IngredientMapperTests()
 {
     _ingredientMapper = new IngredientMapper();
 }
Пример #21
0
        public void GetById_SeededWater()
        {
            var ingredient = _fixture.Repository.GetById(Seeds.Water.Id);

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

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

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