public void UpdateRecipeTest() { // Arrange var repoMock = new Mock <IRecipeRepo>(); var id = 1; var after = new RecipePatchDto() { creatorId = 1, name = "test", description = "test", rating = 6.7F, tag = "test" }; var returned = new RecipeDto() { id = 1, creatorId = 1, name = "test", description = "test", rating = 6.7F, tag = "test" }; repoMock.Setup(p => p.UpdateRecipeById(id, after)).Returns(returned); var service = new AdminManageRecipeServices(repoMock.Object); var ctl = new AdminManageRecipeController(service); // Act var result = ctl.updateRecipe(id, after).Result as OkObjectResult; // Assert result.Value.Should().BeEquivalentTo(returned, options => options.ComparingByMembers <Recipe>()); }
public void updateRecipe_Test() { var listitemup = new RecipePatchDto { creatorId = 1, name = "Bulgur", description = "Boiled Bulgur fried with butter", rating = 9.8F, tag = "Turkish Cuisine" }; var listitem = new RecipeDto { id = 1, creatorId = 1, name = "Bulgur", description = "Boiled Bulgur fried with butter", rating = 9.8F, tag = "Turkish Cuisine" }; var tobereturned = new List <RecipeDto> { listitem }; _recipeRepository.Setup(x => x.UpdateRecipeById(1, listitemup)).Returns(listitem); _recipeRepository.Setup(x => x.GetRecipeById(1)).Returns(listitem); _recipeRepository.Setup(x => x.GetRecipes()).Returns(tobereturned); var tmp = _sut.ServiceUpdateRecipeById(1, listitemup); tmp.Should().BeEquivalentTo(listitem, options => options.ComparingByMembers <RecipeDto>());; }
public ActionResult <RecipeDto> updateRecipe(int id, RecipePatchDto recipe) { //recipe json passed from front-end //find object from recipe.id //set all other fields of found object to recipe fields var result = _recipeService.ServiceUpdateRecipeById(id, recipe); if (result == null) { return(NotFound()); } return(Ok(result)); }
public RecipeDto UpdateRecipeById(int id, RecipePatchDto recipe) { var recipeToUpdate = _context.Recipes.Where(x => x.Id == id).FirstOrDefault(); recipeToUpdate.Name = recipe.name; recipeToUpdate.Description = recipe.description; recipeToUpdate.Tag = recipe.tag; recipeToUpdate.Rating = (decimal)recipe.rating; recipeToUpdate.CreatorId = recipe.creatorId; //let's not allow Update of ingredient lists _context.Recipes.Update(recipeToUpdate); _context.SaveChanges(); return(_context.Recipes.Where(x => x.Id == id).FirstOrDefault().AsDto()); }
public RecipeDto UpdateRecipeById(int id, RecipePatchDto r) { var recipe = _recipeRepository.UpdateRecipeById(id, r); return(recipe); }
public RecipeDto ServiceUpdateRecipeById(int id, RecipePatchDto recipe) { var toReturn = _recipeRepository.UpdateRecipeById(id, recipe); return(ServiceGetRecipeById(toReturn.id)); }
public ActionResult <RecipeDto> updateRecipe(int id, RecipePatchDto _recipe) { var recipe = _recipeService.UpdateRecipeById(id, _recipe); return(Ok(recipe)); }