private static void Seed(Recipes_DB1Context context) { //eventueel met if voorwaarden opleggen voor aanmaken fakeCategories //bemerk gestructureerde namen -> mogelijks veel data via een for lus var fakeCategories = new[] { new Category { Id = 901, CategoryName = "FakeCategory1", Recipes = new[] { new Recipe { Id = Guid.NewGuid(), RecipeName = "FakeRecipe1.1" }, new Recipe { Id = Guid.NewGuid(), RecipeName = "FakeRecipe1.2" } } }, new Category { Id = 902, CategoryName = "FakeCategory2", Recipes = new[] { new Recipe { Id = Guid.NewGuid(), RecipeName = "FakeRecipe2.1" }, new Recipe { Id = Guid.NewGuid(), RecipeName = "FakeRecipe2.2" }, new Recipe { Id = Guid.NewGuid(), RecipeName = "FakeRecipe2.3" }, new Recipe { Id = Guid.NewGuid(), RecipeName = "FakeRecipe2.4" }, } }, new Category { Id = 903, CategoryName = "FakeCategory3", Recipes = new[] { new Recipe { Id = Guid.NewGuid(), RecipeName = "FakeRecipe3.1" } } }, }; context.Category.AddRange(fakeCategories); context.SaveChanges(); //TODO: fakeRecipes aanmaken. }
public DatabaseTestDB() { //gebruik van inmemory data voor testdata. //gebruik van de context vh testen project var options = new DbContextOptionsBuilder <Recipes_DB1Context>() .UseInMemoryDatabase(Guid.NewGuid().ToString()).Options; //property dependancy voorbereiden Context = new Recipes_DB1Context(options); Context.Database.EnsureCreated(); //seed vanuit het standaard API project door de SaveChanges uit te voeren bij onmodelcreating //DatabaseInitializer.Initialize(Context); //extra seeding kan voor de test omgeving met FakeData }
public CategoryRepoTests() { context = Context; categoriesList = Context.Category; recipesList = Context.Recipe; fakeNewCategory = new Category { Id = 902, CategoryName = "FakeCategory2", Recipes = new[] { new Recipe { Id = Guid.NewGuid(), RecipeName = "FakeCat2 Recipe1" }, new Recipe { Id = Guid.NewGuid(), RecipeName = "FakeCat2 Recipe2" } } }; }
public static void Initialize(Recipes_DB1Context context) { Seed(context); //testen met (extra) FakeData }
//ctor dependancy van de applicatie context: public GenericRepo(Recipes_DB1Context context) { this._context = context; }
public RecipeRepo(Recipes_DB1Context context) : base(context) { this.context = context; }