public SentRecipe GetRecipeById(int id) { var recipe = _repo.GetRecipeById(id); System.Console.WriteLine("recipe by id: " + recipe.RecipeName); return(SentRecipe.GetFromRecipe(recipe)); }
public void GetRecipeByID() { var recipe = new Recipe() { RecipeId = 4, RecipeAuthor = "Anis" }; var result1 = new Recipe(); var result2 = new Recipe(); using (var context = new InTheKitchenDBContext(testOptions)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); context.Add(recipe); context.SaveChanges(); result2 = context.Recipes.Where(r => r.RecipeId == recipe.RecipeId) .Include(r => r.RecipeIngredients) .ThenInclude(ri => ri.Ingredient) .Include(r => r.RecipeTags) .ThenInclude(rt => rt.Tag) .Include(r => r.Steps) .Include(r => r.Reviews) .FirstOrDefault(); } using (var context = new InTheKitchenDBContext(testOptions)) { context.Database.EnsureCreated(); var msr = new KitchenRepository(context); result1 = msr.GetRecipeById(recipe.RecipeId); } Assert.Equal(result1.RecipeAuthor, result2.RecipeAuthor); }
public async Task TestRecipeSaving() { // var tag = new Recipe() { TagId = 123, TagName = "Cheese" }; var sentrecipe = new SentRecipe(); var date = DateTime.Now; sentrecipe.DateCreated = date; sentrecipe.DateLastPrepared = date; Tag t = new Tag() { TagName = "tag name 2" }; Ingredient i = new Ingredient() { IngredientName = "ing name 2" }; Step s = new Step() { StepDescription = "new description", RecipeStepNo = 1 }; sentrecipe.ingredients = new List <Ingredient>() { new Ingredient() { IngredientName = "ingredient name" } }; sentrecipe.tags = new List <Tag>() { new Tag() { TagName = "tag name" } }; Step s1 = new Step() { StepDescription = "step description" }; sentrecipe.Steps = new List <Step>() { s1 }; User user = new User() { Auth0 = "authcode", Firstname = "fname", Lastname = "lname", DateCreated = date, Email = "email", ImageUrl = "picture" }; AuthModel model = new AuthModel() { Sub = "authcode", FirstName = "fname", LastName = "lname", Email = "email", ProfileImage = "picture", Username = "******" }; Dictionary <string, string> userDictionary = new Dictionary <string, string>(); userDictionary["email"] = "email"; userDictionary["picture"] = "picture"; userDictionary["sub"] = "authcode"; bool result; Recipe recipe = null; using (var context = new InTheKitchenDBContext(testOptions)) { context.Database.EnsureDeletedAsync(); context.Database.EnsureCreatedAsync(); var repo = new KitchenRepository(context); var msr = new KitchenLogic(context, repo); var reviewlogic = new ReviewStepTagLogic(context, repo); var userlogic = new UserLogic(context, repo); userlogic.UpdateUser(model, userDictionary); userlogic.UpdateUser(model, userDictionary); var sr = await msr.saveRecipe(sentrecipe, model.Sub); sentrecipe.tags.Add(t); sentrecipe.ingredients.Add(i); sentrecipe.Steps.Add(s); sentrecipe.Steps.Remove(s1); sr = await msr.saveRecipe(sentrecipe, model.Sub); recipe = repo.GetRecipeById(sr.RecipeId); repo.UpdateUserAuth0Data(user); var rev = new Review() { Recipe = recipe, ReviewDate = date, ReviewDescription = "review description", RecipeId = recipe.RecipeId, }; reviewlogic.addReview(userDictionary["sub"], rev); HistoryModel hmodel = new HistoryModel() { recipeId = recipe.RecipeId, sub = model.Sub }; msr.SaveRecipePrepare(hmodel); } Assert.Equal(recipe.RecipeTags.ToArray()[0].Tag.TagName, "tag name"); }