Exemple #1
0
        private void Initialize()
        {
            // Create InMemory Database for testing
            var options = new DbContextOptionsBuilder <EmployeeProfileDbContext>()
                          .UseInMemoryDatabase(databaseName: "EmployeeProfileDb")
                          .Options;
            var context = new EmployeeProfileDbContext(options);

            // Seed data
            SeedEmployeeProfiles.Initialize(context);

            // Create the repository
            _repository = new EmployeeProfileRepository(context);

            // create the controller
            _controller = new EmployeeProfileController(new HostingEnvironment(), _repository);
        }
Exemple #2
0
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;

                try
                {
                    var context = services.GetRequiredService <EmployeeProfileDbContext>();
                    context.Database.Migrate();
                    SeedEmployeeProfiles.Initialize(services);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred seeding the DB.");
                }
            }

            host.Run();
        }