コード例 #1
0
        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());
        }
コード例 #2
0
        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)}");
            }
        }