Ejemplo n.º 1
0
        public IngredientDetailModel GetById(Guid id)
        {
            using var dbContext = _dbContextFactory.Create();

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

            return(IngredientMapper.MapIngredientEntityToDetailModel(entity));
        }
Ejemplo n.º 2
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));
     }
 }
Ejemplo n.º 3
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));
     }
 }
Ejemplo n.º 4
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));
        }
Ejemplo n.º 5
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.MapIngredientEntityToDetailModel(ingredientFromDb), IngredientDetailModel.AllMembersComparer);
        }
Ejemplo n.º 6
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.MapIngredientEntityToDetailModel(ingredientFromDb), IngredientDetailModel.AllMembersComparer);
        }
Ejemplo n.º 7
0
        public void GetById_SeededWater()
        {
            var ingredient = _ingredientRepositorySUT.GetById(IngredientSeeds.Water.Id);

            Assert.Equal(IngredientMapper.MapIngredientEntityToDetailModel(IngredientSeeds.Water), ingredient, IngredientDetailModel.AllMembersComparer);
        }