public void GetAllMeals() { var options = new DbContextOptionsBuilder <CookDbContext>() .UseInMemoryDatabase(databaseName: "CookTest") .Options; // Use a separate instance of the context to verify correct data was saved to database var context = new CookDbContext(options); var service = new EFMealService(context); var meals = service.GetMeals(); Assert.Equal(meals.Count, context.Meal.Count()); }
public void UpdateMeal() { var options = new DbContextOptionsBuilder <CookDbContext>() .UseInMemoryDatabase(databaseName: "CookTest") .Options; // Run the test against one instance of the context using (var context = new CookDbContext(options)) { var service = new EFMealService(context); meal.Dishes.Add(new MealDishes { Meal = meal, Dish = dish }); meal.Dishes.Add(new MealDishes { Meal = meal, Dish = dish2 }); meal.Dishes.Add(new MealDishes { Meal = meal, Dish = dish3 }); Dish[] dishes = new Dish[] { dish, dish2, dish3 }; service.UpdateMeal(meal, dishes); } // Use a separate instance of the context to verify correct data was saved to database using (var context = new CookDbContext(options)) { var service = new EFMealService(context); Meal meall = new Meal(); var meals = service.GetMeals(); foreach (var item in meals) { if (item.DateValid == meal.DateValid) { meall = item; } } bool mealBool = service.GetMealById(meall.Id) != null ? true : false; Assert.True(mealBool); var getMeal = service.GetMealById(meall.Id); var mealDishes = service.GetAllMealDishes().Count(); Assert.NotNull(getMeal); Assert.Equal(3, mealDishes); } }
public void GetMealById() { var options = new DbContextOptionsBuilder <CookDbContext>() .UseInMemoryDatabase(databaseName: "CookTest") .Options; // Use a separate instance of the context to verify correct data was saved to database var context = new CookDbContext(options); var service = new EFMealService(context); Meal meall = new Meal(); var meals = service.GetMeals(); foreach (var item in meals) { if (item.DateValid == meal.DateValid) { meall = item; } } bool mealBool = service.GetMealById(meall.Id) != null ? true : false; Assert.True(mealBool); }