|
| 1 | +using System.IO; |
| 2 | +using System.Linq; |
| 3 | +using System.Threading.Tasks; |
| 4 | +using Dapper; |
| 5 | +using FluentAssertions; |
| 6 | +using grate.Configuration; |
| 7 | +using grate.Migration; |
| 8 | +using grate.unittests.TestInfrastructure; |
| 9 | +using NUnit.Framework; |
| 10 | +using static grate.Configuration.KnownFolderKeys; |
| 11 | + |
| 12 | +namespace grate.unittests.Oracle.Running_MigrationScripts; |
| 13 | + |
| 14 | +[TestFixture] |
| 15 | +[Category("Oracle")] |
| 16 | +// ReSharper disable once InconsistentNaming |
| 17 | +public class With_batch_separator: Generic.Running_MigrationScripts.MigrationsScriptsBase |
| 18 | +{ |
| 19 | + protected override IGrateTestContext Context => GrateTestContext.Oracle; |
| 20 | + |
| 21 | + [Test()] |
| 22 | + public async Task Separates_multiple_statements() |
| 23 | + { |
| 24 | + var db = TestConfig.RandomDatabase(); |
| 25 | + |
| 26 | + var parent = TestConfig.CreateRandomTempDirectory(); |
| 27 | + var knownFolders = FoldersConfiguration.Default(null); |
| 28 | + GrateMigrator? migrator; |
| 29 | + |
| 30 | + |
| 31 | + var path = new DirectoryInfo(Path.Combine(parent.ToString(), knownFolders[Up]!.Path)); |
| 32 | + const string filename = "multiple_statements.sql"; |
| 33 | + |
| 34 | + const string fileContent = @" |
| 35 | +create table table_one ( |
| 36 | + col number |
| 37 | +); |
| 38 | +/ |
| 39 | +
|
| 40 | +create table table_two ( |
| 41 | + col number |
| 42 | +) |
| 43 | +"; |
| 44 | + |
| 45 | + WriteSql(path, filename, fileContent); |
| 46 | + |
| 47 | + await using (migrator = Context.GetMigrator(db, parent, knownFolders)) |
| 48 | + { |
| 49 | + await migrator.Migrate(); |
| 50 | + } |
| 51 | + |
| 52 | + string[] scripts; |
| 53 | + string sql = $"SELECT text_of_script FROM {Context.Syntax.TableWithSchema("grate", "ScriptsRun")}"; |
| 54 | + |
| 55 | + await using (var conn = Context.CreateDbConnection(db)) |
| 56 | + { |
| 57 | + scripts = (await conn.QueryAsync<string>(sql)).ToArray(); |
| 58 | + } |
| 59 | + |
| 60 | + scripts.Should().HaveCount(2); |
| 61 | + } |
| 62 | + |
| 63 | +} |
0 commit comments