Esempio n. 1
0
        public async Task Create(bool dropExisting = false)
        {
            try
            {
                var generator = new TestDatabaseGenerator(DatabaseManager)
                {
                    DropExisting = dropExisting
                };

                if (generator.Process())
                {
                    try { await ReferenceData.Create(); }
                    catch (Exception ex)
                    {
                        throw new Exception("Failed to run the reference data.", ex);
                    }
                }

                Status = TempDatabaseCreationStatus.Created;
            }
            catch
            {
                Status = TempDatabaseCreationStatus.Failed;
                throw;
            }
            finally
            {
                DatabaseChangeWatcher.Restart();
            }
        }
Esempio n. 2
0
        public static async Task Create(bool enforceRestart, bool mustRenew)
        {
            if (!WebTestConfig.IsActive())
            {
                Debug.WriteLine("Creating temp database aborted. Test mode is not active.");
                return;
            }

            IsDatabaseBeingCreated = true;
            var createdNew = false;

            try
            {
                SqlConnection.ClearAllPools();
                if (enforceRestart)
                {
                    TempDatabaseInitiated = null;
                }
                if (TempDatabaseInitiated.HasValue)
                {
                    return;
                }

                var generator = new TestDatabaseGenerator(isTempDatabaseOptional: true, mustRenew: mustRenew);
                TempDatabaseInitiated = generator.Process();
                createdNew            = generator.CreatedNewDatabase;

                await Database.Instance.Refresh();

                SqlConnection.ClearAllPools();
            }
            finally { IsDatabaseBeingCreated = false; }

            if (createdNew)
            {
                // A new database is created. Add the reference data
                try
                {
                    await(WebTestConfig.ReferenceDataCreator?.Invoke() ?? Task.CompletedTask);
                }
                catch (Exception ex)
                {
                    throw new Exception("Failed to run the reference data.", ex);
                }
            }
        }
Esempio n. 3
0
        static string CreateSnapshotName(string name)
        {
            var schemaHash = new TestDatabaseGenerator(false, false).GetCurrentDatabaseCreationHash();

            return("{0}_{1}".FormatWith(name, schemaHash).Except(Path.GetInvalidFileNameChars()).ToString(""));
        }