public void SeedDatabase() { var options = new DbContextOptionsBuilder <GorilaDbContext>().UseInMemoryDatabase(databaseName: "koko-in-memory").Options; using (var context = new GorilaDbContext(options)) { context.Database.EnsureCreated(); var jsonString = File.ReadAllText("MockDB/products.json"); var products = JsonSerializer.Deserialize <List <Product> >(jsonString); context.AddRange(products); jsonString = File.ReadAllText("MockDB/clients.json"); var clients = JsonSerializer.Deserialize <List <Client> >(jsonString); for (int i = 0; i < products.Count(); i++) { clients[i % clients.Count].Products.Add(products[i]); products[i].Client = clients[i % clients.Count]; products[i].ClientId = products[i].Id; clients[i % clients.Count].HeritageAmount += products[i].ValueAmount; } context.Clients.AddRange(clients); jsonString = File.ReadAllText("MockDB/advisors.json"); var advisors = JsonSerializer.Deserialize <List <Advisor> >(jsonString); for (int i = 0; i < clients.Count(); i++) { advisors[i % advisors.Count].ClientAmount++; advisors[i % advisors.Count].Clients.Add(clients[i]); advisors[i % advisors.Count].HeritageAmount += clients[i].HeritageAmount; clients[i].Advisor = advisors[i % advisors.Count]; clients[i].AdvisorId = advisors[i % advisors.Count].Id; } context.Advisors.AddRange(advisors); context.SaveChanges(); } }