Esempio n. 1
0
        public void DatabaseGenerator_NoTransaction()
        {
            var oldApplications = new List <ConceptApplication> {
                BaseCi.CreateApplication("A", new SimpleConceptImplementation()),
                BaseCi.CreateApplication("B", new NoTransactionConceptImplementation()),
                BaseCi.CreateApplication("C", new SimpleConceptImplementation())
            };
            var newApplications = new List <NewConceptApplication> {
                BaseCi.CreateApplication("D", new SimpleConceptImplementation()),
                BaseCi.CreateApplication("E", new NoTransactionConceptImplementation()),
                BaseCi.CreateApplication("F", new SimpleConceptImplementation())
            };

            var sqlExecuter           = new MockSqlExecuter();
            var sqlTransactionBatches = new SqlTransactionBatches(sqlExecuter, new NullConfiguration(), new ConsoleLogProvider());
            var databaseGenerator     = new DatabaseGenerator_Accessor(sqlTransactionBatches);

            databaseGenerator.ApplyChangesToDatabase(oldApplications, newApplications, oldApplications, newApplications);

            var executedSql = TestUtility.Dump(sqlExecuter.executedScriptsWithTransaction, scripts =>
                                               (scripts.Item2 ? "TRAN" : "NOTRAN") + ": " + string.Join(", ", scripts.Item1));

            executedSql = ClearSqlForReport(executedSql);

            Assert.AreEqual(
                "TRAN: remove C, NOTRAN: remove B, TRAN: remove A, create D, NOTRAN: create E, TRAN: create F",
                executedSql);
        }
Esempio n. 2
0
 public DatabaseGenerator_Accessor(SqlTransactionBatches sqlTransactionBatches)
     : base(sqlTransactionBatches, null, new NullPluginsContainer <IConceptDatabaseDefinition>(),
            new MockConceptApplicationRepository(),
            new ConsoleLogProvider(), new DatabaseGeneratorOptions {
     ShortTransactions = false
 })
 {
 }
Esempio n. 3
0
 public DataMigrationScripts(ISqlExecuter sqlExecuter, ILogProvider logProvider, IDataMigrationScriptsProvider scriptsProvider, IConfiguration configuration, SqlTransactionBatches sqlTransactionBatches)
 {
     _sqlExecuter           = sqlExecuter;
     _logger                = logProvider.GetLogger("DataMigration");
     _deployPackagesLogger  = logProvider.GetLogger("DeployPackages");
     _scriptsProvider       = scriptsProvider;
     _configuration         = configuration;
     _sqlTransactionBatches = sqlTransactionBatches;
 }
Esempio n. 4
0
 public DataMigrationScriptsExecuter(ISqlExecuter sqlExecuter, ILogProvider logProvider, DataMigrationScripts dataMigrationScripts,
                                     DbUpdateOptions dbUpdateOptions, SqlTransactionBatches sqlTransactionBatches)
 {
     _sqlExecuter           = sqlExecuter;
     _logger                = logProvider.GetLogger("DataMigration");
     _dataMigrationScripts  = dataMigrationScripts;
     _sqlTransactionBatches = sqlTransactionBatches;
     _dbUpdateOptions       = dbUpdateOptions;
 }
Esempio n. 5
0
 public ConceptDataMigrationExecuter(
     ILogProvider logProvider,
     SqlTransactionBatches sqlExecuter,
     RhetosAppOptions rhetosAppOptions)
 {
     _logger           = logProvider.GetLogger("ConceptDataMigration");
     _sqlExecuter      = sqlExecuter;
     _scripts          = new Lazy <GeneratedDataMigrationScripts>(LoadScripts);
     _rhetosAppOptions = rhetosAppOptions;
 }
 public ConceptDataMigrationExecuter(
     ILogProvider logProvider,
     SqlTransactionBatches sqlExecuter,
     IDslModel dslModel,
     IPluginsContainer <IConceptDataMigration> plugins)
 {
     _performanceLogger    = logProvider.GetLogger("Performance");
     _logger               = logProvider.GetLogger(GetType().Name);
     _deployPackagesLogger = logProvider.GetLogger("DeployPackages");
     _sqlExecuter          = sqlExecuter;
     _dslModel             = dslModel;
     _plugins              = plugins;
     _scripts              = new Lazy <GeneratedDataMigrationScripts>(ExecutePlugins);
 }
Esempio n. 7
0
 public DatabaseGenerator(
     SqlTransactionBatches sqlTransactionBatches,
     IConceptApplicationRepository conceptApplicationRepository,
     ILogProvider logProvider,
     DbUpdateOptions dbUpdateOptions,
     DatabaseAnalysis databaseAnalysis)
 {
     _sqlTransactionBatches        = sqlTransactionBatches;
     _conceptApplicationRepository = conceptApplicationRepository;
     _logger            = logProvider.GetLogger(GetType().Name);
     _changesLogger     = logProvider.GetLogger("DatabaseGeneratorChanges");
     _performanceLogger = logProvider.GetLogger("Performance." + GetType().Name);
     _dbUpdateOptions   = dbUpdateOptions;
     _databaseAnalysis  = databaseAnalysis;
 }
        DatabaseGeneratorUpdateDatabase(
            IList <DatabaseObject> oldConceptApplications,
            IList <DatabaseObject> newConceptApplications)
        {
            // Update mock database (based on difference between old and new concept applications):

            var conceptApplicationRepository = new MockConceptApplicationRepository(ConceptApplication.FromDatabaseObjects(oldConceptApplications));
            var databaseModel = new DatabaseModel {
                DatabaseObjects = newConceptApplications.ToList()
            };
            var options = new SqlTransactionBatchesOptions {
                MaxJoinedScriptCount = 1
            };
            var sqlExecuter           = new MockSqlExecuter();
            var sqlTransactionBatches = new SqlTransactionBatches(sqlExecuter, options, new ConsoleLogProvider(), new DelayedLogProvider(new LoggingOptions {
                DelayedLogTimout = 0
            }, null));

            var databaseAnalysis = new DatabaseAnalysis(
                conceptApplicationRepository,
                new ConsoleLogProvider(),
                databaseModel);

            IDatabaseGenerator databaseGenerator = new DatabaseGenerator(
                sqlTransactionBatches,
                conceptApplicationRepository,
                new ConsoleLogProvider(),
                new DbUpdateOptions {
                ShortTransactions = false
            },
                databaseAnalysis);

            databaseGenerator.UpdateDatabaseStructure();

            // Report changes in mock database:

            TestUtility.Dump(
                sqlExecuter.ExecutedScriptsWithTransaction,
                script => (script.Item2 ? "tran" : "notran")
                + string.Concat(script.Item1.Select(sql => "\r\n  - " + sql.Replace('\r', ' ').Replace('\n', ' '))));

            return
                (Report : string.Join(", ", sqlExecuter.ExecutedScriptsWithTransaction.SelectMany(script => script.Item1)),
                 SqlExecuter : sqlExecuter,
                 RemovedConcepts : conceptApplicationRepository.DeletedLog,
                 InsertedConcepts : conceptApplicationRepository.InsertedLog.ToList());
        }
Esempio n. 9
0
 public DatabaseGenerator(
     SqlTransactionBatches sqlTransactionBatches,
     IDslModel dslModel,
     IPluginsContainer <IConceptDatabaseDefinition> plugins,
     IConceptApplicationRepository conceptApplicationRepository,
     ILogProvider logProvider,
     DatabaseGeneratorOptions options)
 {
     _sqlTransactionBatches = sqlTransactionBatches;
     _dslModel = dslModel;
     _plugins  = plugins;
     _conceptApplicationRepository = conceptApplicationRepository;
     _logger               = logProvider.GetLogger("DatabaseGenerator");
     _conceptsLogger       = logProvider.GetLogger("DatabaseGenerator Concepts");
     _deployPackagesLogger = logProvider.GetLogger("DeployPackages");
     _performanceLogger    = logProvider.GetLogger("Performance");
     _options              = options;
 }
        public void JoinScriptsTest()
        {
            // input scripts, max count, max size, expected output scripts
            // "//" is a shortcut for "\r\n"
            var tests = new ListOfTuples <string[], int, int, string[]>
            {
                { new string[] { }, 10, 1000, new string[] { } },
                { new string[] { }, 0, 0, new string[] { } },

                { new[] { "a", "b", "c" }, 10, 1000, new[] { "a//b//c" } },

                { new[] { "12345", "12345", "12345" }, 3, 1000, new[] { "12345//12345//12345" } },
                { new[] { "12345", "12345", "12345" }, 2, 1000, new[] { "12345//12345", "12345" } },
                { new[] { "12345", "12345", "12345" }, 1, 1000, new[] { "12345", "12345", "12345" } },
                { new[] { "12345", "12345", "12345" }, 0, 1000, new[] { "12345", "12345", "12345" } },

                { new[] { "12345", "12345", "12345" }, 3, 19, new[] { "12345//12345//12345" } },
                { new[] { "12345", "12345", "12345" }, 3, 18, new[] { "12345//12345", "12345" } },
                { new[] { "12345", "12345", "12345" }, 3, 12, new[] { "12345//12345", "12345" } },
                { new[] { "12345", "12345", "12345" }, 3, 11, new[] { "12345", "12345", "12345" } },
                { new[] { "12345", "12345", "12345" }, 3, 5, new[] { "12345", "12345", "12345" } },
                { new[] { "12345", "12345", "12345" }, 3, 1, new[] { "12345", "12345", "12345" } },
                { new[] { "12345", "12345", "12345" }, 3, 0, new[] { "12345", "12345", "12345" } },
            };

            foreach (var test in tests)
            {
                var options = new SqlTransactionBatchesOptions
                {
                    MaxJoinedScriptCount = test.Item2,
                    MaxJoinedScriptSize  = test.Item3,
                };
                var batches = new SqlTransactionBatches(null, options, new ConsoleLogProvider(), new DelayedLogProvider(new LoggingOptions {
                    DelayedLogTimout = 0
                }, null));
                var joinedScripts = batches.JoinScripts(test.Item1);

                Assert.AreEqual(
                    TestUtility.Dump(test.Item4),
                    TestUtility.Dump(joinedScripts.Select(s => s.Replace("\r\n", "//"))),
                    $"Test: '{TestUtility.Dump(test.Item1)}' - {test.Item2}, {test.Item3} => {joinedScripts.Count}, {joinedScripts.Sum(s => s.Length)}");
            }
        }