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); }
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); }
private void GetAssertRecipeDetailModel(RecipeDetailModel recipe) { var detailModel = this._recipeRepository.GetById(recipe.Id); Assert.IsNotNull(detailModel); Assert.AreEqual(detailModel, recipe); }
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 } } }; }
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); }
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 }
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 }
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(); } }
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); }
public void Delete_FromSeeded_DoesNotThrow() { //Arrange RecipeDetailModel detailModel = RecipeMapper.MapEntityToDetailModel(DAL.Seeds.RecipeSeeds.RecipeEntity); //Act & Assert _repositorySUT.Delete(detailModel); }
public void InsertRecipe(RecipeDetailModel recipeDetailModel) { using (var dbx = new CookBookDbContext()) { dbx.Recipes.Add(_mapper.Map(recipeDetailModel)); dbx.SaveChanges(); } }
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()); } }
public async Task <ActionResult <int> > Put(int id, [FromBody] RecipeDetailModel recipeDetailModel) { if (id != recipeDetailModel.Id) { return(BadRequest()); } return(await _recipeDetailService.Update(recipeDetailModel)); }
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(); } }
public RecipeListModel MapDetailModelToListModel(RecipeDetailModel detailModel) { return(new RecipeListModel { Id = detailModel.Id, Duration = detailModel.Duration, Name = detailModel.Name, Type = detailModel.Type }); }
public void Update_FromSeeded_DoesNotThrow() { //Arrange RecipeDetailModel detailModel = RecipeMapper.MapEntityToDetailModel(DAL.Seeds.RecipeSeeds.RecipeEntity); detailModel.Name = "Changed recipe name"; //Act & Assert _repositorySUT.InsertOrUpdate(detailModel); }
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; }
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); }
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)); }
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))); }
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 }); }
public RecipeDetailModel Save(RecipeDetailModel model) { if (model.Id == Guid.Empty) { return(recipeRepository.Insert(model)); } else { recipeRepository.Update(model); return(model); } }
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)); } }
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); } }
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(); } }
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; } } }
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); }
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); }
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); }
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); }