protected override void ConfigureWebHost(IWebHostBuilder builder)
        {
            builder.ConfigureServices(services =>
            {
                var descriptor = services.SingleOrDefault(d => d.ServiceType ==
                                                          typeof(DbContextOptions <GoodFoodIncDBContext>));

                services.Remove(descriptor);

                services.AddDbContext <GoodFoodIncDBContext>(options =>
                {
                    options.UseInMemoryDatabase("InMemoryDbForTesting");
                });

                var sp = services.BuildServiceProvider();

                using (var scope = sp.CreateScope())
                {
                    var scopedServices = scope.ServiceProvider;
                    Context            = scopedServices.GetRequiredService <GoodFoodIncDBContext>();
                    var logger         = scopedServices
                                         .GetRequiredService <ILogger <CustomWebApplicationFactory <TStartup> > >();

                    Context.Database.EnsureCreated();
                }
            });
        }
 public static void InitializeIngredientTestData(GoodFoodIncDBContext db)
 {
     db.Ingredients.Add(new Ingredient()
     {
         Title = "milk", Description = "Sød Milk"
     });
     db.Ingredients.Add(new Ingredient()
     {
         Title = "egg", Description = "white egg"
     });
     db.SaveChanges();
 }
Ejemplo n.º 3
0
        public IntegrationTest(CustomWebApplicationFactory <Startup> factory)
        {
            Factory = factory;
            Client  = Factory.CreateClient(new WebApplicationFactoryClientOptions
            {
                AllowAutoRedirect = true
            });
            var scopeFactory = Factory.Server.Host.Services.GetService <IServiceScopeFactory>();
            var scope        = scopeFactory.CreateScope();

            Context = scope.ServiceProvider.GetService <GoodFoodIncDBContext>();
        }
 public static void InitializeUserAndCatagoryTestData(GoodFoodIncDBContext db)
 {
     db.Users.Add(new User()
     {
         UserName = "******", Password = "******"
     });
     db.Catagories.Add(new Catagory()
     {
         Name = CatagoryTypes.starters.ToString()
     });
     db.Catagories.Add(new Catagory()
     {
         Name = CatagoryTypes.maincourse.ToString()
     });
     db.Catagories.Add(new Catagory()
     {
         Name = CatagoryTypes.dessert.ToString()
     });
     db.SaveChanges();
 }
Ejemplo n.º 5
0
 public RecipesController(GoodFoodIncDBContext context)
 {
     _context = context;
 }
 public IngredientsController(GoodFoodIncDBContext context)
 {
     _context = context;
 }