Ejemplo n.º 1
0
        public DatabaseHelper(bool setupData = false, MockConnection solrConnection = null)
        {
            if (solrConnection == null)
            {
                solrConnection = new MockConnection();
            }

            Initialize(solrConnection);
            Ss.SetCurrentUser(Guid.NewGuid());
            CreateUserLists(); // This is done always to support the security system.

            if (setupData)
            {
                SetupData();
            }
        }
Ejemplo n.º 2
0
        public void Initialize(MockConnection solrConnection)
        {
            //if (SolrService.IsInitialized)
            //{
            //    //TODO: Inject the new connection into this current solr thread.
            //}
            //else
            //{
            //    SolrService.ForceInit(solrConnection);
            //}

            SolrService.ForceInit(solrConnection);

            try
            {
                Catfish.Tests.Migrations.Configuration config = new Catfish.Tests.Migrations.Configuration();
                var migrator = new DbMigrator(config);

                foreach (string migName in migrator.GetLocalMigrations())
                {
                    Type        migration = config.MigrationsAssembly.GetType(string.Format("{0}.{1}", config.MigrationsNamespace, migName.Substring(16)));
                    DbMigration m         = (DbMigration)Activator.CreateInstance(migration);
                    m.Up();

                    var prop = m.GetType().GetProperty("Operations", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                    if (prop != null)
                    {
                        IEnumerable <MigrationOperation> operations = prop.GetValue(m) as IEnumerable <MigrationOperation>;
                        var generator  = config.GetSqlGenerator("System.Data.SQLite");
                        var statements = generator.Generate(operations, "2008");
                        foreach (MigrationStatement item in statements)
                        {
                            Db.Database.ExecuteSqlCommand(item.Sql);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }