Пример #1
0
        public void SetUp()
        {
            var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json");

            _configuration = builder.Build();

            _optionsReq   = new DbContextOptionsBuilder <RequirementsContext>().UseLazyLoadingProxies().UseSqlServer(_configuration.GetConnectionString("RequirementsContext")).Options;
            _optionsUser  = new DbContextOptionsBuilder <UsersContext>().UseLazyLoadingProxies().UseSqlServer(_configuration.GetConnectionString("UsersContext")).Options;
            _reqContext   = new RequirementsContext(_optionsReq);
            _usersContext = new UsersContext(_optionsUser);
            _service      = new ScheduleService(_reqContext, _usersContext);

            if (needReset)
            {
                SeedUsersData.reset        = true;
                SeedRequirementsData.reset = true;
                needReset = false;
            }
            else
            {
                SeedUsersData.reset        = false;
                SeedRequirementsData.reset = false;
            }
            SeedRequirementsData.Initialize(_reqContext);
            SeedUsersData.Initialize(_usersContext);
        }
Пример #2
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    RequirementsContext requirementsContext =
                        new RequirementsContext(services.GetRequiredService <DbContextOptions <RequirementsContext> >());
                    UsersContext usersContext =
                        new UsersContext(services.GetRequiredService <DbContextOptions <UsersContext> >());
                    AccountsContext accountsContext =
                        new AccountsContext(services.GetRequiredService <DbContextOptions <AccountsContext> >());
                    SeedRequirementsData.Initialize(requirementsContext);
                    SeedUsersData.Initialize(usersContext);
                    SeedDataAccountsDb.Initialize(accountsContext);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occured seeding the DB.");
                }
            }
            host.Run();
        }
Пример #3
0
 public void CleanUp()
 {
     SeedRequirementsData.Initialize(_reqContext);
     SeedUsersData.Initialize(_usersContext);
 }