public static void Split_WhenScriptNotEmpty_ReturnsExpectedResults(string script,
                                                                           string batchSeparator,
                                                                           bool removeComments,
                                                                           IEnumerable <string> expectedBatches)
        {
            // Assert
            var splitter = new DbScriptSplitter();
            // Act
            var batches = splitter.Split(script, batchSeparator, removeComments);

            // Assert
            batches.Should().Equal(expectedBatches);
        }
Exemple #2
0
        public static int[] ExecuteScript(this IDbConnection connection,
                                          string script,
                                          IDbTransaction transaction = null,
                                          int?commandTimeout         = null,
                                          string batchSeparator      = "GO",
                                          bool removeComments        = true)
        {
            Condition.Requires(connection, nameof(connection)).IsNotNull();
            Condition.Requires(script, nameof(script)).IsNotNullOrEmpty();
            Condition.Requires(nameof(batchSeparator), batchSeparator).IsNotNullOrWhiteSpace();
            var scriptSplitter = new DbScriptSplitter();
            var commands       = scriptSplitter.Split(script, batchSeparator, removeComments);
            var result         = new List <int>();

            foreach (var command in commands)
            {
                if (StartsWithUseStatement(command))
                {
                    connection.ExecuteUseStatement(command);
                }
                result.Add(connection.Execute(command, null, transaction, commandTimeout));
            }
            return(result.ToArray());
        }