コード例 #1
0
        public void Create_WithIngredient_DoesNotThrowAndEqualsCreated()
        {
            //Arrange
            RecipeDetailModel model = new RecipeDetailModel
            {
                Name        = "Recipe 2",
                Description = "Testing recipe 2",
                Duration    = TimeSpan.FromHours(2),
                FoodType    = FoodType.Dessert,
                ImageUrl    = "https://d2v9mhsiek5lbq.cloudfront.net/eyJidWNrZXQiOiJsb21hLW1lZGlhLXVrIiwia2V5IjoiZm9vZG5ldHdvcmstaW1hZ2UtOGI5ZWM4YTAtODc1OC00MDcyLTg2YTItMzMzYTA4NTY5NTkwLmpwZyIsImVkaXRzIjp7InJlc2l6ZSI6eyJmaXQiOiJjb3ZlciIsIndpZHRoIjo3NTAsImhlaWdodCI6NDIyfX19",
                Ingredients =
                {
                    new IngredientAmountDetailModel
                    {
                        IngredientName        = IngredientSeeds.IngredientEntity1.Name,
                        IngredientDescription = IngredientSeeds.IngredientEntity1.Description,
                        IngredientImageUrl    = IngredientSeeds.IngredientEntity1.ImageUrl,
                        IngredientId          = IngredientSeeds.IngredientEntity1.Id,

                        Amount = 5,
                        Unit   = Unit.L
                    }
                }
            };

            //Act
            RecipeDetailModel returnedModel = _repositorySUT.InsertOrUpdate(model);

            //Assert
            FixIds(model, returnedModel);
            Assert.Equal(model, returnedModel);
        }
コード例 #2
0
ファイル: RecipeRepositoryTests.cs プロジェクト: lori1998/ICS
        public void Create_WithExistingIngredient_DoesNotThrowAndEqualsCreated()
        {
            //Arrange
            var model = new RecipeDetailModel
            {
                Name        = "Recipe 2",
                Description = "Testing recipe 2",
                Duration    = TimeSpan.FromHours(2),
                FoodType    = FoodType.Dessert,
                Ingredients =
                {
                    new IngredientAmountDetailModel
                    {
                        IngredientName        = "Ingredient 1",
                        IngredientDescription = "Testing Ingredient",
                    },
                    IngredientAmountMapper.MapDetailModel(CookBookSeedingDbContext.IngredientAmountEntity1)
                }
            };

            //Act
            var returnedModel = RepositorySUT.InsertOrUpdate(model);


            //Assert
            Assert.NotEqual(Guid.Empty, returnedModel.Id);
            Assert.NotEqual(Guid.Empty, returnedModel.Ingredients.First().Id);
            FixIds(returnedModel, model);

            Assert.Equal(model, returnedModel, RecipeDetailModel.RecipeDetailModelComparer);
        }
コード例 #3
0
        private void GetAssertRecipeDetailModel(RecipeDetailModel recipe)
        {
            var detailModel = this._recipeRepository.GetById(recipe.Id);

            Assert.IsNotNull(detailModel);
            Assert.AreEqual(detailModel, recipe);
        }
コード例 #4
0
        public ChangeNotificationCollectionProperty()
        {
            _ingredientAmountDetailModel = new IngredientAmountDetailModel
            {
                IngredientName        = "Ingredient 1",
                IngredientDescription = "Testing Ingredient",
                Amount = 5
            };

            _recipeDetailModel = new RecipeDetailModel
            {
                Name        = "Recipe 2",
                Description = "Testing recipe 2",
                Duration    = TimeSpan.FromHours(2),
                FoodType    = FoodType.Dessert,
                Ingredients =
                {
                    _ingredientAmountDetailModel,
                    new IngredientAmountDetailModel
                    {
                        IngredientName        = "Ingredient 2",
                        IngredientDescription = "Testing Ingredient 2",
                        Amount = 6
                    }
                }
            };
        }
コード例 #5
0
        private static RecipeDetailModel CreateRecipeDetailModel()
        {
            var recipe = new RecipeDetailModel()
            {
                Name        = "RecipeName",
                Description = "RecipeDescription",
                Duration    = new TimeSpan(0, 0, 1),
                Type        = FoodType.MainCourse,
                Ingredients = new List <IngredienceModel>()
                {
                    new IngredienceModel()
                    {
                        Name        = "Ingredient1Name",
                        Description = "Ingredient1Description",
                        Unit        = Unit.Kg,
                        Amount      = 3.14
                    },
                    new IngredienceModel()
                    {
                        Name        = "Ingredient2Name",
                        Description = "Ingredient2Description",
                        Unit        = Unit.Kg,
                        Amount      = 3.14
                    }
                }
            };

            return(recipe);
        }
コード例 #6
0
        public async Task Create_WithNonExistingIngredient_Throws()
        {
            //Arrange
            var model = new RecipeDetailModel
                        (
                Name: "Recipe 2",
                Description: "Testing recipe 2",
                Duration: TimeSpan.FromHours(2),
                FoodType: FoodType.Dessert
                        )
            {
                Ingredients =
                {
                    new IngredientAmountDetailModel(
                        IngredientId:Guid.Empty,
                        IngredientName: "Ingredient 1",
                        IngredientDescription: "Testing Ingredient",
                        Amount:0,
                        Unit: Unit.None
                        )
                }
            };

            //Act & Assert
            try
            {
                await _facadeSUT.SaveAsync(model); //In-memory pass without exception
            }
            catch (DbUpdateException) {} //SqlServer throws on FK
        }
コード例 #7
0
        public async Task Create_WithExistingAndNotExistingIngredient_Throws()
        {
            //Arrange
            var model = new RecipeDetailModel
                        (
                Name: "Recipe 2",
                Description: "Testing recipe 2",
                Duration: TimeSpan.FromHours(2),
                FoodType: FoodType.Dessert
                        )
            {
                Ingredients =
                {
                    new IngredientAmountDetailModel(
                        IngredientId:Guid.Empty,
                        IngredientName: "Ingredient 1",
                        IngredientDescription: "Testing Ingredient",
                        Amount:0,
                        Unit: Unit.None
                        ),
                    Mapper.Map <IngredientAmountDetailModel>(IngredientAmountSeeds.IngredientAmountEntity1)
                }
            };

            //Act & Assert
            try
            {
                await _facadeSUT.SaveAsync(model);

                Assert.True(false, "Assert Fail");
            }
            catch (DbUpdateException) {} //SqlServer
            catch (ArgumentException) {} //In-memory
        }
コード例 #8
0
        public override async Task OnAppearing()
        {
            await base.OnAppearing();

            if (viewModelParameter == null)
            {
                Recipe = new RecipeDetailModel();
            }
            else
            {
                Recipe = await recipesFacade.GetRecipeAsync(viewModelParameter.Value);

                OnPropertyChanged("Recipe.FoodType");
            }

            if (IngredientsAll == null)
            {
                IngredientsAll = await ingredientsFacade.GetIngredientsAsync();
            }

            if (UnitTexts == null)
            {
                UnitTexts = Enum.GetNames(typeof(Unit)).ToList();
            }

            if (FoodTypeTexts == null)
            {
                FoodTypeTexts = Enum.GetNames(typeof(FoodType)).ToList();
            }
        }
コード例 #9
0
        public void Create_WithNonExistingIngredient_DoesNotThrowAndEqualsCreated()
        {
            //Arrange
            RecipeDetailModel model = new RecipeDetailModel
            {
                Name        = "Recipe 2",
                Description = "Testing recipe 2",
                Duration    = TimeSpan.FromHours(2),
                FoodType    = FoodType.Dessert,
                Ingredients =
                {
                    new IngredientAmountDetailModel
                    {
                        IngredientName        = "Ingredient 1",
                        IngredientDescription = "Testing Ingredient",
                    }
                }
            };

            //Act
            RecipeDetailModel returnedModel = _repositorySUT.InsertOrUpdate(model);


            //Assert
            Assert.NotEqual(Guid.Empty, returnedModel.Id);
            Assert.NotEqual(Guid.Empty, returnedModel.Ingredients.First().Id);
            FixIds(returnedModel, model);

            Assert.Equal(model, returnedModel);
        }
コード例 #10
0
        public void Delete_FromSeeded_DoesNotThrow()
        {
            //Arrange
            RecipeDetailModel detailModel = RecipeMapper.MapEntityToDetailModel(DAL.Seeds.RecipeSeeds.RecipeEntity);

            //Act & Assert
            _repositorySUT.Delete(detailModel);
        }
コード例 #11
0
 public void InsertRecipe(RecipeDetailModel recipeDetailModel)
 {
     using (var dbx = new CookBookDbContext())
     {
         dbx.Recipes.Add(_mapper.Map(recipeDetailModel));
         dbx.SaveChanges();
     }
 }
コード例 #12
0
 private static void AssertIngredience(RecipeDetailModel recipe, IngredienceDetailModel[] ingrediences)
 {
     foreach (var ingredient in recipe.Ingredients)
     {
         Assert.Contains(ingredient.Name, ingrediences.Select(i => i.Name).ToList());
         Assert.Contains(ingredient.Description, ingrediences.Select(i => i.Description).ToList());
         Assert.Contains(ingredient.Id, ingrediences.Select(i => i.Id).ToList());
     }
 }
コード例 #13
0
        public async Task <ActionResult <int> > Put(int id, [FromBody] RecipeDetailModel recipeDetailModel)
        {
            if (id != recipeDetailModel.Id)
            {
                return(BadRequest());
            }

            return(await _recipeDetailService.Update(recipeDetailModel));
        }
コード例 #14
0
 public void InsertOrUpdateRecipe(RecipeDetailModel detail)
 {
     using (var dbx = new CookBookDbContext())
     {
         var state = detail.Id == Guid.Empty ?
                     EntityState.Added : EntityState.Modified;
         dbx.Entry(this._mapper.Map(detail)).State = state;
         dbx.SaveChanges();
     }
 }
コード例 #15
0
 public RecipeListModel MapDetailModelToListModel(RecipeDetailModel detailModel)
 {
     return(new RecipeListModel
     {
         Id = detailModel.Id,
         Duration = detailModel.Duration,
         Name = detailModel.Name,
         Type = detailModel.Type
     });
 }
コード例 #16
0
        public void Update_FromSeeded_DoesNotThrow()
        {
            //Arrange
            RecipeDetailModel detailModel = RecipeMapper.MapEntityToDetailModel(DAL.Seeds.RecipeSeeds.RecipeEntity);

            detailModel.Name = "Changed recipe name";

            //Act & Assert
            _repositorySUT.InsertOrUpdate(detailModel);
        }
コード例 #17
0
ファイル: RecipeMapper.cs プロジェクト: lori1998/ICS
 public static RecipeEntity MapToEntity(RecipeDetailModel detailModel, IEntityFactory<RecipeEntity> entityFactory)
 {
     var entity = (entityFactory ??= new DummyEntityFactory<RecipeEntity>()).Create(detailModel.Id);
     entity.Id = detailModel.Id;
     entity.Name = detailModel.Name;
     entity.Description = detailModel.Description;
     entity.Duration = detailModel.Duration;
     entity.FoodType = (DAL.Enums.FoodType) detailModel.FoodType;
     entity.Ingredients = detailModel.Ingredients.Select(model => IngredientAmountMapper.MapEntity(model, entityFactory.As<IngredientAmountEntity>())).ToList();
     return entity;
 }
コード例 #18
0
        public void GetById_FromSeeded_DoesNotThrowAndEqualsSeeded()
        {
            //Arrange
            RecipeDetailModel detailModel = RecipeMapper.MapEntityToDetailModel(DAL.Seeds.RecipeSeeds.RecipeEntity);

            //Act
            RecipeDetailModel returnedModel = _repositorySUT.GetById(detailModel.Id);

            //Assert
            Assert.Equal(detailModel, returnedModel);
        }
コード例 #19
0
ファイル: RecipeFacade.cs プロジェクト: SuperMartas/iw5
        public Guid?Update(RecipeDetailModel recipeModel)
        {
            var recipeEntityExisting = recipeRepository.GetById(recipeModel.Id);

            recipeEntityExisting.IngredientAmounts = ingredientAmountRepository.GetByRecipeId(recipeModel.Id);
            UpdateIngredientAmounts(recipeModel, recipeEntityExisting);

            var recipeEntityUpdated = mapper.Map <RecipeEntity>(recipeModel);

            return(recipeRepository.Update(recipeEntityUpdated));
        }
コード例 #20
0
        public IActionResult Save([Bind("Name,Type,Description,Duration,Id")] RecipeDetailModel recipe)
        {
            if (!ModelState.IsValid)
            {
                return(View("Detail", recipe));
            }

            var savedRecipe = recipeFacade.Save(recipe);

            return(RedirectToAction(nameof(Index)));
        }
コード例 #21
0
 public RecipeEntity MapDetailModelToEntity(RecipeDetailModel entity)
 {
     return(new RecipeEntity()
     {
         Id = entity.Id,
         Name = entity.Name,
         Type = entity.Type,
         Description = entity.Description,
         Duration = entity.Duration,
         Ingredients = entity.Ingredients
     });
 }
コード例 #22
0
 public RecipeDetailModel Save(RecipeDetailModel model)
 {
     if (model.Id == Guid.Empty)
     {
         return(recipeRepository.Insert(model));
     }
     else
     {
         recipeRepository.Update(model);
         return(model);
     }
 }
コード例 #23
0
        internal RecipeDetailModel Insert(RecipeDetailModel detail)
        {
            using (var cookBookDbContext = dbContextFactory())
            {
                var entity = mapper.MapDetailModelToEntity(detail);
                entity.Id = Guid.NewGuid();

                cookBookDbContext.Recipes.Add(entity);
                cookBookDbContext.SaveChanges();

                return(mapper.MapEntityToDetailModel(entity));
            }
        }
コード例 #24
0
ファイル: RecipesFacade.cs プロジェクト: SuperMartas/iw5
        public async Task <Guid> SaveAsync(RecipeDetailModel data, string culture)
        {
            if (data.Id == Guid.Empty)
            {
                return(await recipeClient.RecipePostAsync(apiVersion, culture, data));
            }
            else
            {
                var recipePutAsync = await recipeClient.RecipePutAsync(apiVersion, culture, data);

                return(recipePutAsync ?? Guid.Empty);
            }
        }
コード例 #25
0
        internal void Update(RecipeDetailModel detail)
        {
            using (var cookBookDbContext = dbContextFactory())
            {
                var entity = cookBookDbContext.Recipes.First(r => r.Id == detail.Id);

                entity.Name        = detail.Name;
                entity.Description = detail.Description;
                entity.Duration    = detail.Duration;
                entity.Type        = detail.Type;

                cookBookDbContext.SaveChanges();
            }
        }
コード例 #26
0
ファイル: RecipeRepositoryTests.cs プロジェクト: lori1998/ICS
 private static void FixIds(RecipeDetailModel returnedModel, RecipeDetailModel model)
 {
     model.Id = returnedModel.Id;
     foreach (var ingredient in returnedModel.Ingredients)
     {
         var ingredientAmountDetailModel = model.Ingredients.FirstOrDefault(i =>
                                                                            IngredientAmountDetailModel.IngredientAmountDetailModelWithoutIdComparer.Equals(i, ingredient));
         if (ingredientAmountDetailModel != null)
         {
             ingredientAmountDetailModel.Id           = ingredient.Id;
             ingredientAmountDetailModel.IngredientId = ingredient.IngredientId;
         }
     }
 }
コード例 #27
0
        public Guid Create(RecipeDetailModel recipeModel)
        {
            var recipeEntity = mapper.Map <RecipeEntity>(recipeModel);

            recipeEntity.Id = Guid.NewGuid();
            recipeRepository.Insert(recipeEntity);

            foreach (var ingredientAmount in recipeEntity.IngredientAmounts)
            {
                ingredientAmount.RecipeId = recipeEntity.Id;
                ingredientAmountRepository.Insert(ingredientAmount);
            }
            return(recipeEntity.Id);
        }
コード例 #28
0
        public static RecipeEntity MapToEntity(RecipeDetailModel detailModel)
        {
            var mapToEntity = new RecipeEntity()
            {
                Id          = detailModel.Id,
                Name        = detailModel.Name,
                Description = detailModel.Description,
                Duration    = detailModel.Duration,
                FoodType    = (CookBook.DAL.Enums.FoodType)detailModel.FoodType,
                Ingredients = detailModel.Ingredients.Select(IngredientAmountMapper.MapEntity).ToList()
            };

            return(mapToEntity);
        }
コード例 #29
0
        public void Update_RemoveIngredients_FromSeeded_CheckUpdated()
        {
            //Arrange
            RecipeDetailModel detailModel = RecipeMapper.MapEntityToDetailModel(DAL.Seeds.RecipeSeeds.RecipeEntity);

            detailModel.Ingredients.Clear();

            //Act
            _repositorySUT.InsertOrUpdate(detailModel);

            //Assert
            RecipeDetailModel returnedModel = _repositorySUT.GetById(detailModel.Id);

            Assert.Equal(detailModel, returnedModel);
        }
コード例 #30
0
        public void Update_Name_FromSeeded_CheckUpdated()
        {
            //Arrange
            RecipeDetailModel detailModel = RecipeMapper.MapEntityToDetailModel(DAL.Seeds.RecipeSeeds.RecipeEntity);

            detailModel.Name = "Changed recipe name 1";

            //Act
            _repositorySUT.InsertOrUpdate(detailModel);

            //Assert
            RecipeDetailModel returnedModel = _repositorySUT.GetById(detailModel.Id);

            Assert.Equal(detailModel, returnedModel);
        }