protected override void ConfigureWebHost(IWebHostBuilder builder)
 {
     builder.ConfigureServices(services =>
     {
         services.AddEntityFrameworkInMemoryDatabase();
         var provider = services.AddEntityFrameworkInMemoryDatabase()
                        .BuildServiceProvider();
         services.AddDbContext <AlbumDbContext>(options =>
         {
             options.UseInMemoryDatabase("InMemoryDbForTesting");
             options.UseInternalServiceProvider(provider);
         });
         var sp = services.BuildServiceProvider();
         using (var scope = sp.CreateScope())
         {
             var scopedServices = scope.ServiceProvider;
             var db             = scopedServices.GetRequiredService <AlbumDbContext>();
             db.Database.EnsureCreated();
             try
             {
                 AlbumDbContextSeed.SeedAsync(db).Wait();
             }
             catch (Exception ex)
             {
                 //Log Exception
             }
         }
     });
 }
        public AlbumRepositoryTest(ITestOutputHelper output)
        {
            _output = output;
            var dbOptions = new DbContextOptionsBuilder <AlbumDbContext>()
                            .UseInMemoryDatabase("AlbumDb").Options;

            _albumDbContext  = new AlbumDbContext(dbOptions);
            _albumRepository = new AsyncRepository <Album>(_albumDbContext);
            AlbumDbContextSeed.SeedAsync(_albumDbContext).Wait();
        }
예제 #3
0
        public async static Task Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var albumDbContext = services.GetRequiredService <AlbumDbContext>();
                    await AlbumDbContextSeed.SeedAsync(albumDbContext);
                }
                catch (Exception ex)
                {
                    //log exception
                }
            }
            host.Run();
        }