public override void Initialize()
        {
            base.Initialize();

            //we need to use our own custom IDatabaseFactory for the DatabaseContext because we MUST ensure that
            //a Database instance is created per thread, whereas the default implementation which will work in an HttpContext
            //threading environment, or a single apartment threading environment will not work for this test because
            //it is multi-threaded.
            _dbFactory = new PerThreadDatabaseFactory(Logger);
            //overwrite the local object
            ApplicationContext.DatabaseContext = new DatabaseContext(_dbFactory, Logger, new SqlCeSyntaxProvider(), "System.Data.SqlServerCe.4.0");

            //disable cache
            var cacheHelper = CacheHelper.CreateDisabledCacheHelper();

            //here we are going to override the ServiceContext because normally with our test cases we use a
            //global Database object but this is NOT how it should work in the web world or in any multi threaded scenario.
            //we need a new Database object for each thread.
            var repositoryFactory = new RepositoryFactory(cacheHelper, Logger, SqlSyntax, SettingsForTests.GenerateMockSettings());

            _uowProvider = new PerThreadPetaPocoUnitOfWorkProvider(_dbFactory);
            var evtMsgs = new TransientMessagesFactory();

            ApplicationContext.Services = new ServiceContext(
                repositoryFactory,
                _uowProvider,
                new FileUnitOfWorkProvider(),
                new PublishingStrategy(evtMsgs, Logger),
                cacheHelper,
                Logger,
                evtMsgs);

            CreateTestData();
        }
Exemple #2
0
        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 dbContext = new DatabaseContext(
                new DefaultDatabaseFactory(GlobalSettings.UmbracoConnectionName, _logger),
                _logger, SqlSyntaxProvider, "System.Data.SqlServerCe.4.0");

            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(_logger), new FileUnitOfWorkProvider(), new PublishingStrategy(evtMsgs, _logger), cacheHelper, _logger, evtMsgs),
                cacheHelper,
                new ProfilingLogger(_logger, Mock.Of <IProfiler>()))
            {
                IsReady = true
            };

            Resolution.Freeze();
        }
Exemple #3
0
        /// <summary>
        /// Creates and returns the service context for the app
        /// </summary>
        /// <param name="dbContext"></param>
        /// <param name="scopeProvider"></param>
        /// <returns></returns>
        protected virtual ServiceContext CreateServiceContext(DatabaseContext dbContext, IScopeProvider scopeProvider)
        {
            //default transient factory
            var msgFactory = new TransientMessagesFactory();

            return(new ServiceContext(
                       new RepositoryFactory(ApplicationCache, ProfilingLogger.Logger, dbContext.SqlSyntax, UmbracoConfig.For.UmbracoSettings()),
                       new PetaPocoUnitOfWorkProvider(scopeProvider),
                       ApplicationCache,
                       ProfilingLogger.Logger,
                       msgFactory));
        }
        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 override ApplicationContext CreateApplicationContext()
        {
            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, GetDbProviderName()),
                //assign the service context
                new ServiceContext(repositoryFactory, new PetaPocoUnitOfWorkProvider(_dbFactory), new FileUnitOfWorkProvider(), new PublishingStrategy(evtMsgs, Logger), CacheHelper, Logger, evtMsgs),
                CacheHelper,
                ProfilingLogger)
            {
                IsReady = true
            };
            return(_appContext);
        }
Exemple #6
0
        /// <summary>
        /// Inheritors can override this if they wish to create a custom application context
        /// </summary>
        protected virtual void SetupApplicationContext()
        {
            var sqlSyntax   = new SqlCeSyntaxProvider();
            var repoFactory = new RepositoryFactory(CacheHelper.CreateDisabledCacheHelper(), Logger, sqlSyntax, SettingsForTests.GenerateMockSettings());

            var evtMsgs = new TransientMessagesFactory();

            ApplicationContext.Current = new ApplicationContext(
                //assign the db context
                new DatabaseContext(new DefaultDatabaseFactory(Core.Configuration.GlobalSettings.UmbracoConnectionName, Logger),
                                    Logger, sqlSyntax, "System.Data.SqlServerCe.4.0"),
                //assign the service context
                new ServiceContext(repoFactory, new PetaPocoUnitOfWorkProvider(Logger), new FileUnitOfWorkProvider(), new PublishingStrategy(evtMsgs, Logger), CacheHelper, Logger, evtMsgs),
                CacheHelper,
                ProfilingLogger)
            {
                IsReady = true
            };
        }
        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);
        }