コード例 #1
0
        public override void DatabaseSpecificTearDown()
        {
            //legacy API database connection close
            SqlCeContextGuardian.CloseBackgroundConnection();

            TestHelper.ClearDatabase();
        }
コード例 #2
0
 private void CloseDbConnections()
 {
     //Ensure that any database connections from a previous test is disposed.
     //This is really just double safety as its also done in the TearDown.
     if (ApplicationContext != null && DatabaseContext != null && DatabaseContext.Database != null)
     {
         DatabaseContext.Database.Dispose();
     }
     SqlCeContextGuardian.CloseBackgroundConnection();
 }
コード例 #3
0
        private void CloseDbConnections()
        {
            // just to be sure, although it's also done in TearDown
            if (ApplicationContext != null &&
                ApplicationContext.DatabaseContext != null &&
                ApplicationContext.DatabaseContext.ScopeProvider != null)
            {
                ApplicationContext.DatabaseContext.ScopeProvider.Reset();
            }

            SqlCeContextGuardian.CloseBackgroundConnection();
        }
コード例 #4
0
        public override void DatabaseSpecificTearDown()
        {
            //legacy API database connection close
            SqlCeContextGuardian.CloseBackgroundConnection();

            string filePath = string.Concat(Path, "\\UmbracoPetaPocoTests.sdf");

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }
        }
コード例 #5
0
        public virtual void TearDown()
        {
            if (ApplicationContext != null)
            {
                if (DatabaseContext != null && DatabaseContext.Database != null)
                {
                    DatabaseContext.Database.Dispose();
                }
                //reset the app context
                ApplicationContext.ApplicationCache.ClearAllCache();
            }

            SqlSyntaxContext.SqlSyntaxProvider = null;

            //legacy API database connection close - because a unit test using PetaPoco db-layer can trigger the usage of SqlHelper we need to ensure that a possible connection is closed.
            SqlCeContextGuardian.CloseBackgroundConnection();

            ApplicationContext.Current = null;
            Resolution.IsFrozen        = false;
            RepositoryResolver.Reset();
            SqlSyntaxProvidersResolver.Reset();

            TestHelper.CleanContentDirectories();

            string path = TestHelper.CurrentAssemblyDirectory;

            AppDomain.CurrentDomain.SetData("DataDirectory", null);

            SettingsForTests.Reset();
            UmbracoSettings.ResetSetters();

            try
            {
                string filePath = string.Concat(path, "\\UmbracoPetaPocoTests.sdf");
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error <BaseDatabaseFactoryTest>("Could not remove the old database file", ex);

                //We will swallow this exception! That's because a sub class might require further teardown logic.
            }
        }
コード例 #6
0
        public virtual void TearDown()
        {
            SqlSyntaxContext.SqlSyntaxProvider = null;
            Resolution.Reset();

            TestHelper.CleanContentDirectories();

            Path = TestHelper.CurrentAssemblyDirectory;
            AppDomain.CurrentDomain.SetData("DataDirectory", null);

            //legacy API database connection close
            SqlCeContextGuardian.CloseBackgroundConnection();

            string filePath = string.Concat(Path, "\\UmbracoPetaPocoTests.sdf");

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }
        }
コード例 #7
0
        public virtual void Initialize()
        {
            TestHelper.SetupLog4NetForTests();
            TestHelper.InitializeContentDirectories();

            string path = TestHelper.CurrentAssemblyDirectory;

            AppDomain.CurrentDomain.SetData("DataDirectory", path);

            //Ensure that any database connections from a previous test is disposed. This is really just double safety as its also done in the TearDown.
            if (ApplicationContext != null && DatabaseContext != null)
            {
                DatabaseContext.Database.Dispose();
            }
            SqlCeContextGuardian.CloseBackgroundConnection();

            try
            {
                //Delete database file before continueing
                string filePath = string.Concat(path, "\\UmbracoPetaPocoTests.sdf");
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
            }
            catch (Exception)
            {
                //if this doesn't work we have to make sure everything is reset! otherwise
                // well run into issues because we've already set some things up
                TearDown();
                throw;
            }

            RepositoryResolver.Current = new RepositoryResolver(
                new RepositoryFactory());

            SqlSyntaxProvidersResolver.Current = new SqlSyntaxProvidersResolver(
                new List <Type> {
                typeof(MySqlSyntaxProvider), typeof(SqlCeSyntaxProvider), typeof(SqlServerSyntaxProvider)
            })
            {
                CanResolveBeforeFrozen = true
            };

            //Get the connectionstring settings from config
            var settings = ConfigurationManager.ConnectionStrings[Core.Configuration.GlobalSettings.UmbracoConnectionName];

            ConfigurationManager.AppSettings.Set(Core.Configuration.GlobalSettings.UmbracoConnectionName, @"datalayer=SQLCE4Umbraco.SqlCEHelper,SQLCE4Umbraco;data source=|DataDirectory|\UmbracoPetaPocoTests.sdf");

            //Create the Sql CE database
            var engine = new SqlCeEngine(settings.ConnectionString);

            engine.CreateDatabase();

            Resolution.Freeze();
            ApplicationContext.Current = new ApplicationContext(
                //assign the db context
                new DatabaseContext(new DefaultDatabaseFactory()),
                //assign the service context
                new ServiceContext(new PetaPocoUnitOfWorkProvider(), new FileUnitOfWorkProvider(), new PublishingStrategy()))
            {
                IsReady = true
            };

            InitializeDatabase();

            //ensure the configuration matches the current version for tests
            SettingsForTests.ConfigurationStatus = UmbracoVersion.Current.ToString(3);
        }