示例#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);
        }
        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());
        }