public override void Initialize() { InitializeFirstRunFlags(); var path = TestHelper.CurrentAssemblyDirectory; AppDomain.CurrentDomain.SetData("DataDirectory", path); var dbFactory = new DefaultDatabaseFactory( GetDbConnectionString(), GetDbProviderName()); _appContext = new ApplicationContext( //assign the db context new DatabaseContext(dbFactory), //assign the service context new ServiceContext(new PetaPocoUnitOfWorkProvider(dbFactory), new FileUnitOfWorkProvider(), new PublishingStrategy()), //disable cache false) { IsReady = true }; base.Initialize(); DatabaseContext.Initialize(dbFactory.ProviderName, dbFactory.ConnectionString); CreateSqlCeDatabase(); InitializeDatabase(); //ensure the configuration matches the current version for tests SettingsForTests.ConfigurationStatus = UmbracoVersion.Current.ToString(3); }
public void Can_Assert_Created_Database() { string path = TestHelper.CurrentAssemblyDirectory; AppDomain.CurrentDomain.SetData("DataDirectory", path); //Delete database file before continueing //NOTE: we'll use a custom db file for this test since we're re-using the one created with BaseDatabaseFactoryTest string filePath = string.Concat(path, "\\DatabaseContextTests.sdf"); if (File.Exists(filePath)) { File.Delete(filePath); } //Get the connectionstring settings from config var settings = ConfigurationManager.ConnectionStrings[Constants.System.UmbracoConnectionName]; //by default the conn string is: Datasource=|DataDirectory|UmbracoPetaPocoTests.sdf;Flush Interval=1; //we'll just replace the sdf file with our custom one: //Create the Sql CE database var connString = settings.ConnectionString.Replace("UmbracoPetaPocoTests", "DatabaseContextTests"); using (var engine = new SqlCeEngine(connString)) { engine.CreateDatabase(); } var dbFactory = new DefaultDatabaseFactory(connString, Constants.DatabaseProviders.SqlCe, Mock.Of <ILogger>()); var scopeProvider = new ScopeProvider(dbFactory); //re-map the dbcontext to the new conn string _dbContext = new DatabaseContext( scopeProvider, Mock.Of <ILogger>(), new SqlCeSyntaxProvider(), dbFactory.ProviderName); var schemaHelper = new DatabaseSchemaHelper(_dbContext.Database, Mock.Of <ILogger>(), new SqlCeSyntaxProvider()); var appCtx = new ApplicationContext( _dbContext, new ServiceContext(migrationEntryService: Mock.Of <IMigrationEntryService>()), CacheHelper.CreateDisabledCacheHelper(), new ProfilingLogger(Mock.Of <ILogger>(), Mock.Of <IProfiler>())); //Create the umbraco database schemaHelper.CreateDatabaseSchema(false, appCtx); bool umbracoNodeTable = schemaHelper.TableExist("umbracoNode"); bool umbracoUserTable = schemaHelper.TableExist("umbracoUser"); bool cmsTagsTable = schemaHelper.TableExist("cmsTags"); Assert.That(umbracoNodeTable, Is.True); Assert.That(umbracoUserTable, Is.True); Assert.That(cmsTagsTable, Is.True); }
public void PetaPocoConnection_Cant_Connect_To_SqlDatabase_Because_Of_Network() { // Arrange const string providerName = "System.Data.SqlClient"; const string connectionString = @"server=.\SQLEXPRESS;database=EmptyForTest;user id=umbraco;password=umbraco"; var factory = new DefaultDatabaseFactory(connectionString, providerName, Mock.Of <ILogger>()); var database = factory.CreateDatabase(); //Act Assert.Throws <SqlException>( () => database.Fetch <dynamic>("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES")); }
public override void Initialize() { InitializeFirstRunFlags(); var path = TestHelper.CurrentAssemblyDirectory; AppDomain.CurrentDomain.SetData("DataDirectory", path); //disable cache var cacheHelper = CacheHelper.CreateDisabledCacheHelper(); var dbFactory = new DefaultDatabaseFactory( GetDbConnectionString(), GetDbProviderName(), Logger); var repositoryFactory = new RepositoryFactory(cacheHelper, Logger, SqlSyntax, SettingsForTests.GenerateMockSettings()); var evtMsgs = new TransientMessagesFactory(); _appContext = new ApplicationContext( //assign the db context new DatabaseContext(dbFactory, Logger, SqlSyntax, "System.Data.SqlServerCe.4.0"), //assign the service context new ServiceContext(repositoryFactory, new PetaPocoUnitOfWorkProvider(dbFactory), new FileUnitOfWorkProvider(), new PublishingStrategy(evtMsgs, Logger), cacheHelper, Logger, evtMsgs), cacheHelper, ProfilingLogger) { IsReady = true }; base.Initialize(); using (ProfilingLogger.TraceDuration <BaseDatabaseFactoryTest>("init")) { //TODO: Somehow make this faster - takes 5s + DatabaseContext.Initialize(dbFactory.ProviderName, dbFactory.ConnectionString); CreateSqlCeDatabase(); InitializeDatabase(); //ensure the configuration matches the current version for tests SettingsForTests.ConfigurationStatus = UmbracoVersion.GetSemanticVersion().ToSemanticString(); } }
protected virtual ApplicationContext CreateApplicationContext() { var sqlSyntax = new SqlCeSyntaxProvider(); var repoFactory = new RepositoryFactory(CacheHelper, Logger, sqlSyntax, SettingsForTests.GenerateMockSettings()); var dbFactory = new DefaultDatabaseFactory(Constants.System.UmbracoConnectionName, Logger); var scopeProvider = new ScopeProvider(dbFactory); var evtMsgs = new TransientMessagesFactory(); var applicationContext = new ApplicationContext( //assign the db context new DatabaseContext(scopeProvider, Logger, sqlSyntax, Constants.DatabaseProviders.SqlCe), //assign the service context new ServiceContext(repoFactory, new PetaPocoUnitOfWorkProvider(scopeProvider), CacheHelper, Logger, evtMsgs), CacheHelper, ProfilingLogger) { IsReady = true }; return(applicationContext); }
public override void Initialize() { InitializeFirstRunFlags(); var path = TestHelper.CurrentAssemblyDirectory; AppDomain.CurrentDomain.SetData("DataDirectory", path); // we probably don't need this here, as it's done in base.Initialize() already, // but these test classes are all weird, not going to change it now - v8 SafeCallContext.Clear(); _dbFactory = new DefaultDatabaseFactory( GetDbConnectionString(), GetDbProviderName(), Logger); // ensure we start tests in a clean state ie without any scope in context // anything that used a true 'Scope' would have removed it, but there could // be a rogue 'NoScope' there - and we want to make sure it is gone var scopeProvider = new ScopeProvider(null); if (scopeProvider.AmbientScope != null) { scopeProvider.AmbientScope.Dispose(); // removes scope from context } base.Initialize(); using (ProfilingLogger.TraceDuration <BaseDatabaseFactoryTest>("init")) { //TODO: Somehow make this faster - takes 5s + DatabaseContext.Initialize(_dbFactory.ProviderName, _dbFactory.ConnectionString); CreateSqlCeDatabase(); InitializeDatabase(); //ensure the configuration matches the current version for tests SettingsForTests.ConfigurationStatus = UmbracoVersion.GetSemanticVersion().ToSemanticString(); } }
public virtual IBootManager Initialize() { if (_isInitialized) { throw new InvalidOperationException("The boot manager has already been initialized"); } InitializeProfilerResolver(); _timer = DisposableTimer.DebugDuration <CoreBootManager>("Umbraco application starting", "Umbraco application startup complete"); //create database and service contexts for the app context var dbFactory = new DefaultDatabaseFactory(GlobalSettings.UmbracoConnectionName); Database.Mapper = new PetaPocoMapper(); var dbContext = new DatabaseContext(dbFactory); var serviceContext = new ServiceContext( new PetaPocoUnitOfWorkProvider(dbFactory), new FileUnitOfWorkProvider(), new PublishingStrategy()); CreateApplicationContext(dbContext, serviceContext); InitializeApplicationEventsResolver(); InitializeResolvers(); //initialize the DatabaseContext dbContext.Initialize(); //now we need to call the initialize methods ApplicationEventsResolver.Current.ApplicationEventHandlers .ForEach(x => x.OnApplicationInitialized(UmbracoApplication, ApplicationContext)); _isInitialized = true; return(this); }
public virtual void Initialize() { _logger = new Logger(new FileInfo(TestHelper.MapPathForTest("~/unit-test-log4net.config"))); TestHelper.InitializeContentDirectories(); string path = TestHelper.CurrentAssemblyDirectory; AppDomain.CurrentDomain.SetData("DataDirectory", path); //disable cache var cacheHelper = CacheHelper.CreateDisabledCacheHelper(); var dbFactory = new DefaultDatabaseFactory(Constants.System.UmbracoConnectionName, _logger); var scopeProvider = new ScopeProvider(dbFactory); var dbContext = new DatabaseContext( scopeProvider, _logger, SqlSyntaxProvider, Constants.DatabaseProviders.SqlCe); var repositoryFactory = new RepositoryFactory(cacheHelper, _logger, SqlSyntaxProvider, SettingsForTests.GenerateMockSettings()); var evtMsgs = new TransientMessagesFactory(); ApplicationContext.Current = new ApplicationContext( //assign the db context dbContext, //assign the service context new ServiceContext(repositoryFactory, new PetaPocoUnitOfWorkProvider(scopeProvider), cacheHelper, _logger, evtMsgs), cacheHelper, new ProfilingLogger(_logger, Mock.Of <IProfiler>())) { IsReady = true }; Resolution.Freeze(); }
public virtual IBootManager Initialize() { if (_isInitialized) { throw new InvalidOperationException("The boot manager has already been initialized"); } InitializeLoggerResolver(); InitializeProfilerResolver(); ProfilingLogger = ProfilingLogger ?? new ProfilingLogger(LoggerResolver.Current.Logger, ProfilerResolver.Current.Profiler); _timer = ProfilingLogger.TraceDuration <CoreBootManager>( string.Format("Umbraco {0} application starting on {1}", UmbracoVersion.GetSemanticVersion().ToSemanticString(), NetworkHelper.MachineName), "Umbraco application startup complete"); ApplicationCache = CreateApplicationCache(); //create and set the plugin manager (I'd much prefer to not use this singleton anymore but many things are using it unfortunately and // the way that it is setup, there must only ever be one per app so without IoC it would be hard to make this not a singleton) PluginManager = new PluginManager(ServiceProvider, ApplicationCache.RuntimeCache, ProfilingLogger); PluginManager.Current = PluginManager; //Create the legacy prop-eds mapping LegacyPropertyEditorIdToAliasConverter.CreateMappingsForCoreEditors(); LegacyParameterEditorAliasConverter.CreateMappingsForCoreEditors(); //create database and service contexts for the app context var dbFactory = new DefaultDatabaseFactory(Constants.System.UmbracoConnectionName, ProfilingLogger.Logger); Database.Mapper = new PetaPocoMapper(); var scopeProvider = new ScopeProvider(dbFactory); dbFactory.ScopeProvider = scopeProvider; var dbContext = new DatabaseContext( scopeProvider, ProfilingLogger.Logger, SqlSyntaxProviders.CreateDefault(ProfilingLogger.Logger)); //initialize the DatabaseContext dbContext.Initialize(); //get the service context var serviceContext = CreateServiceContext(dbContext, scopeProvider); //set property and singleton from response ApplicationContext.Current = ApplicationContext = CreateApplicationContext(dbContext, serviceContext); InitializeApplicationEventsResolver(); InitializeResolvers(); InitializeModelMappers(); using (ProfilingLogger.DebugDuration <CoreBootManager>( string.Format("Executing {0} IApplicationEventHandler.OnApplicationInitialized", ApplicationEventsResolver.Current.ApplicationEventHandlers.Count()), "Finished executing IApplicationEventHandler.OnApplicationInitialized")) { //now we need to call the initialize methods ApplicationEventsResolver.Current.ApplicationEventHandlers .ForEach(x => { try { using (ProfilingLogger.DebugDuration <CoreBootManager>(string.Format("Executing {0} in ApplicationInitialized", x.GetType()))) { x.OnApplicationInitialized(UmbracoApplication, ApplicationContext); } } catch (Exception ex) { ProfilingLogger.Logger.Error <CoreBootManager>("An error occurred running OnApplicationInitialized for handler " + x.GetType(), ex); throw; } }); } _isInitialized = true; return(this); }