public async Task ExecuteQuery_ValidDateSet20501201_OnlyProductsFromDateReturnedForRecipe() { _uut.ValidToDate = "2050"; _uut.SearchRecipe = "Hjemmelavet lasagne"; var recipesList = await _uut.Execute(_context); foreach (var recipe in recipesList) { foreach (var ingredient in recipe.IngredientList.Ingredient) { Assert.That(ingredient.Product.ValidTo.Year, Is.EqualTo(2050)); } } }
public async Task TestNormalPrice(string name) { RecipeQuery recipeQuery = new RecipeQuery { SearchRecipe = name, LoadIngredientList = true, NumberOfRecipes = 1, }; var recipe = await recipeQuery.Execute(_context); string[] empty = new string[8]; double resultTotal = await _uut.TotalPrice(recipe.First(), name, empty, _context); double resultNormal = await _uut.NormalPrice(recipe.First(), name, empty, _context); Assert.That(true, Is.EqualTo(resultNormal >= resultTotal)); }
static void Main(string[] args) { prj4databaseContext context = new prj4databaseContext(); RecipeQuery test = new RecipeQuery { LoadIngredientList = true, LoadSubscriptions = true, SearchRecipe = "vegetar" }; var udskrift = test.Execute(context); foreach (var VARIABLE in udskrift.Result) { Console.WriteLine($"{VARIABLE.Name}"); } //foreach (var VARIABLE in udskrift) //{ // Console.WriteLine($"{VARIABLE}"); //} //Console.WriteLine("Hello World!"); //prj4databaseContext context = new prj4databaseContext(); //VareRepository objekt = new VareRepository(context); //Vare var1 = new Vare(); ////var1.VareId = 50000; //var1.Navn = "Testvare"; //var1.Pris = 2000.0; //var1.Butik = "Netto"; //var1.ValidFra = ""; //var1.ValidTil = ""; //var1.Volumenpris = 100; //var1.Volumen = 200; //var1.Imgsrc = ""; //objekt.InsertVare(var1); //objekt.Save(); /* * prj4databaseContext context = new prj4databaseContext(); * RecipesRepository repo = new RecipesRepository(context); * IngredientList liste = new IngredientList(); * Vare v1 = new Vare(); * v1.Navn = "Kødboller"; * v1.Pris = 45; * v1.Butik = "Rema2000"; * v1.ValidFra = ""; * v1.ValidTil = ""; * v1.Volumenpris = 45; * v1.Volumen = 1000; * v1.Imgsrc = ""; * * Vare v2 = new Vare(); * v1.Navn = "Fiskefillet"; * v1.Pris = 21; * v1.Butik = "Rema23000"; * v1.ValidFra = ""; * v1.ValidTil = ""; * v1.Volumenpris = 30; * v1.Volumen = 450; * v1.Imgsrc = ""; * liste.IngredientId = 2000; * * Recipes recipe = new Recipes(); * * recipe.Category = "Vegetar"; * recipe.Directions = "1. Put ting i en skål. 2. Rør dem sammen. 3. Put det i en spand. 4. Spis med glæde!"; * recipe.IngredientList = new List<IngredientList>(); * recipe.Name = "VegetarMedKød"; * recipe.Price = 45; * recipe.SavingsAbsolute = 20; * recipe.SavingsPercent = 10; * recipe.Servings = 2; * recipe.Subscriptions = new List<Subscriptions>(); * recipe.Timestamp = DateTime.Now; * * repo.InsertRecipe(recipe); * repo.Save(); */ }
public async Task <string> CreateRecipeToDatabase(string name, int prepareTime, string description, string ingridientName, string ingridientAmount, string ingridientUnit, string imgUrl, Prj4databaseContext context) { RecipeQuery recipeQuery = new RecipeQuery { SearchRecipe = name }; var queryResult = await recipeQuery.Execute(context); if (queryResult.Any()) { return("Opskrift findes allerede"); } Recipe recipe = new Recipe { Name = name, CookTime = prepareTime, ImgSrc = imgUrl, Servings = 4 }; RecipeRepository recipeRepository = new RecipeRepository(context); recipeRepository.Insert(recipe); recipeRepository.Save(); string[] descriptionData = description.Split(';', StringSplitOptions.RemoveEmptyEntries); int sizeDescription = descriptionData.Length; var directions = new Directions[sizeDescription]; for (int i = 0; i < sizeDescription; i++) { directions[i] = new Directions { Description = descriptionData[i], RecipeId = recipe.RecipeId }; } DirectionsRepository directionsRepository = new DirectionsRepository(context); foreach (var direc in directions) { directionsRepository.Insert(direc); } directionsRepository.Save(); var ingredientLists = new IngredientList { RecipeId = recipe.RecipeId, }; IngredientListRepository ingredientListRepository = new IngredientListRepository(context); ingredientListRepository.Insert(ingredientLists); ingredientListRepository.Save(); string[] nameSplit = ingridientName.Split(';', StringSplitOptions.RemoveEmptyEntries); string[] amountSplit = ingridientAmount.Split(';', StringSplitOptions.RemoveEmptyEntries); string[] unitSplit = ingridientUnit.Split(';', StringSplitOptions.RemoveEmptyEntries); int sizeIngridient = nameSplit.Length; var ingridients = new Ingredient[sizeIngridient]; var produkt = await context.Set <Product>().Where(p => p.Name.Contains("a")).Take(1).ToListAsync(); for (int i = 0; i < sizeIngridient; i++) { double.TryParse(amountSplit[i], out var amountDouble); ingridients[i] = new Ingredient { Name = nameSplit[i], Amount = amountDouble, AmountUnit = unitSplit[i], ProductId = produkt[0].ProductId, IngredientListId = ingredientLists.IngredientListId }; } IngredientRepository ingredientRepository = new IngredientRepository(context); foreach (var ingridient in ingridients) { ingredientRepository.Insert(ingridient); } ingredientRepository.Save(); return(HtmlToRecipe(name, prepareTime, description, ingridientName, ingridientAmount, ingridientUnit, imgUrl)); }