Ejemplo n.º 1
0
        private void PopulateDatabase(IServiceCollection services)
        {
            string existingDataFilePath = Configuration["Database:ExistingDataPath"];
            string populateOption       = Configuration["Database:PopulateOption"];
            bool   validate             = Configuration.GetValue <bool>("Database:ValidateData");

            if (populateOption == DatabasePrePopulationOptions.None.ToString())
            {
                // Do nothing
            }
            else if (populateOption == DatabasePrePopulationOptions.OnlyStaticData.ToString())
            {
                var serviceProvider = services.BuildServiceProvider();
                var context         = serviceProvider.GetRequiredService <IffleyRoutesRecordContext>();

                var staticDataPopulater = new PopulateDatabaseWithStaticData(context, existingDataFilePath);
                staticDataPopulater.Populate();
            }
            else if (populateOption == DatabasePrePopulationOptions.StaticDataAndExistingProblems.ToString())
            {
                var serviceProvider = services.BuildServiceProvider();
                var context         = serviceProvider.GetRequiredService <IffleyRoutesRecordContext>();

                var staticDataPopulater = new PopulateDatabaseWithStaticData(context, existingDataFilePath);
                staticDataPopulater.Populate();

                var existingProblemsPopulater = new PopulateDatabaseWithExistingProblems(
                    context, existingDataFilePath, serviceProvider.GetRequiredService <ProblemRequestValidator>());
                existingProblemsPopulater.Populate(validate);
            }
            else
            {
                Environment.Exit(0);
            }
        }
Ejemplo n.º 2
0
        public void RunTest()
        {
            var cache = new MockCache();

            var connectionStringBuilder = new SqliteConnectionStringBuilder()
            {
                DataSource = ":memory:"
            };
            string connectionString        = connectionStringBuilder.ToString();
            var    connection              = new SqliteConnection(connectionString);
            var    dbContextOptionsBuilder = new DbContextOptionsBuilder <IffleyRoutesRecordContext>();

            dbContextOptionsBuilder.UseSqlite(connection);
            var repository = new IffleyRoutesRecordContext(dbContextOptionsBuilder.Options);

            repository.Database.OpenConnection();
            repository.Database.EnsureCreated();

            var styleSymbolManager = new StyleSymbolManager(repository, cache);
            var ruleManager        = new RuleManager(repository, cache);
            var holdManager        = new HoldManager(repository, cache, ruleManager);
            var gradeManager       = new GradeManager(repository, cache);
            var problemReader      = new ProblemReader(repository, cache, styleSymbolManager, ruleManager, holdManager, gradeManager);
            var validator          = new ProblemRequestValidator(repository);

            var staticDataPopulater = new PopulateDatabaseWithStaticData(repository, existingDataFilePath);

            staticDataPopulater.Populate();

            var populator = new PopulateDatabaseWithExistingProblems(repository, existingDataFilePath, validator);

            populator.Populate(false);
        }