public async Task TestSingleIngredient() { var ingredient = new Ingredient() { IngredientId = 3, IngredientName = "Cheese", IngredientDescription = "svsvsvs", IngredientImage = "Some Image", RecipeIngredients = new List <RecipeIngredient>(), ThirdPartyApiId = "Google", }; var result2 = new Ingredient(); using (var context = new InTheKitchenDBContext(testOptions)) { await context.Database.EnsureDeletedAsync(); await context.Database.EnsureCreatedAsync(); context.Add(ingredient); context.SaveChangesAsync(); } await using (var context = new InTheKitchenDBContext(testOptions)) { context.Database.EnsureCreated(); var msr = new ReviewStepTagLogic(context); result2 = await msr.getOneIngredientById(ingredient.IngredientId); } Assert.Equal(ingredient.IngredientDescription, result2.IngredientDescription); }
public async Task TestRecipe() { var recipeResult = new Recipe() { RecipeId = 2377, RecipeName = "Cheese", RecipeAuthor = "Anis" }; var result1 = new Recipe(); var result2 = new Recipe(); using (var context = new InTheKitchenDBContext(testOptions)) { context.Database.EnsureDeletedAsync(); context.Database.EnsureCreatedAsync(); var msr = new KitchenLogic(context); result1 = await msr.addNewRecipe(recipeResult); } using (var context = new InTheKitchenDBContext(testOptions)) { context.Database.EnsureCreatedAsync(); context.Recipes.AddAsync(recipeResult); context.SaveChangesAsync(); result2 = await context.Recipes.Where(r => r.RecipeName == recipeResult.RecipeName).FirstOrDefaultAsync(); } Assert.Equal(result1, result2); }
public async Task <Recipe> addNewRecipe(Recipe recipe) { recipe.RecipeId = getAllRecipe().Result.Count() + 1; recipe.DateCreated = DateTime.Now; recipe.DateLastPrepared = DateTime.Now; await _context.Recipes.AddAsync(recipe); await _context.SaveChangesAsync(); return(recipe); }
public async Task <Recipe> SaveNewRecipe(string sub) { var user = await _context.Users.Where(u => u.Auth0 == sub).FirstOrDefaultAsync(); Recipe r = new Recipe(); r.DateCreated = DateTime.Now; r.DateLastPrepared = DateTime.Now; r.NumTimesPrepared = 0; r.RecipeDescription = ""; r.RecipeName = ""; r.RecipeAuthor = user.Firstname + " " + user.Lastname; var author = new RecipeAuthor(); author.User = user; r.RecipeAuthors.Add(author); var x = await _context.Recipes.AddAsync(r); await _context.SaveChangesAsync(); System.Console.WriteLine("is id here? " + r.RecipeId); return(r); }