From 99666bdc8ab40679b338fcc5034dcc1e97cf6225 Mon Sep 17 00:00:00 2001 From: "Erik A. Brandstadmoen" Date: Sun, 17 Dec 2023 21:16:06 +0100 Subject: [PATCH] Some fixes after PR 405 --- unittests/Basic_tests/Basic_tests.csproj | 6 ++ .../FolderConfiguration_.cs | 67 ++++++++++--------- .../KnownFolders_CustomNames.cs | 54 ++++++++------- unittests/Basic_tests/xunit.runner.json | 5 ++ unittests/MariaDB/MariaDB.csproj | 6 ++ unittests/MariaDB/xunit.runner.json | 5 ++ unittests/Oracle/Oracle.csproj | 6 ++ unittests/Oracle/xunit.runner.json | 5 ++ unittests/PostgreSQL/PostgreSQL.csproj | 6 ++ unittests/PostgreSQL/xunit.runner.json | 5 ++ unittests/SqlServer/SqlServer.csproj | 6 ++ .../SqlServerTestContainer.cs | 12 ++-- unittests/SqlServer/xunit.runner.json | 5 ++ .../SqlServerCaseSensitive.csproj | 6 ++ .../SqlServerCaseSensitive/xunit.runner.json | 5 ++ unittests/Sqlite/Sqlite.csproj | 6 ++ unittests/Sqlite/xunit.runner.json | 5 ++ .../Generic/GenericMigrationTables.cs | 41 +++++++----- .../Failing_Scripts.cs | 62 +++++++++-------- .../DescriptiveTestObjects.cs | 29 ++++++++ .../TestInfrastructure/TheoryData.cs | 19 ++++++ 21 files changed, 249 insertions(+), 112 deletions(-) create mode 100644 unittests/Basic_tests/xunit.runner.json create mode 100644 unittests/MariaDB/xunit.runner.json create mode 100644 unittests/Oracle/xunit.runner.json create mode 100644 unittests/PostgreSQL/xunit.runner.json create mode 100644 unittests/SqlServer/xunit.runner.json create mode 100644 unittests/SqlServerCaseSensitive/xunit.runner.json create mode 100644 unittests/Sqlite/xunit.runner.json create mode 100644 unittests/TestCommon/TestInfrastructure/DescriptiveTestObjects.cs create mode 100644 unittests/TestCommon/TestInfrastructure/TheoryData.cs diff --git a/unittests/Basic_tests/Basic_tests.csproj b/unittests/Basic_tests/Basic_tests.csproj index d843d078..be8e567f 100644 --- a/unittests/Basic_tests/Basic_tests.csproj +++ b/unittests/Basic_tests/Basic_tests.csproj @@ -24,4 +24,10 @@ + + + PreserveNewest + + + diff --git a/unittests/Basic_tests/CommandLineParsing/FolderConfiguration_.cs b/unittests/Basic_tests/CommandLineParsing/FolderConfiguration_.cs index 9d6a6a4d..30c33764 100644 --- a/unittests/Basic_tests/CommandLineParsing/FolderConfiguration_.cs +++ b/unittests/Basic_tests/CommandLineParsing/FolderConfiguration_.cs @@ -2,10 +2,10 @@ using System.CommandLine.Invocation; using System.CommandLine.NamingConventionBinder; using System.CommandLine.Parsing; +using System.Runtime.CompilerServices; using FluentAssertions; using grate.Commands; using grate.Configuration; -using Xunit; namespace Basic_tests.CommandLineParsing; @@ -39,45 +39,38 @@ public async Task Default_With_Overrides(string commandLine, KnownFolderNames fo [Theory] [MemberData(nameof(FullyCustomFoldersCommandLines))] - public async Task Fully_Customised(string root, string foldersArgument, IFoldersConfiguration expected) + public async Task Fully_Customised(string name, string root, string foldersArgument, IFoldersConfiguration expected) { + var s = name; var cfg = await ParseGrateConfiguration("--sqlfilesdirectory=" + root, foldersArgument); var actual = cfg?.Folders; AssertEquivalent(expected.Values, actual?.Values); } - public static IEnumerable FoldersCommandLines() - { - yield return new object?[] { "--folders=up=tables", KnownFolderNames.Default with { Up = "tables" } }; - yield return new object?[] { "--folders=up=tables;views=projections", KnownFolderNames.Default with { Up = "tables", Views = "projections" } }; - } - + public static TheoryData FoldersCommandLines() => + new() + { + { "--folders=up=tables", Wrap(KnownFolderNames.Default with { Up = "tables" }) }, + { "--folders=up=tables;views=projections", Wrap(KnownFolderNames.Default with { Up = "tables", Views = "projections" }) }, + }; - public static IEnumerable FullyCustomFoldersCommandLines() - { - yield return new object?[]{ - "/tmp/jalla", -@"--folders=folder1=type:Once;folder2=type:EveryTime;folder3=type:AnyTime", - new FoldersConfiguration( - new MigrationsFolder("folder1", MigrationType.Once), - new MigrationsFolder("folder2", MigrationType.EveryTime), - new MigrationsFolder("folder3", MigrationType.AnyTime) - )}; - } - // private static TestCaseData GetTestCase( - // string folderArg, - // Func expectedOverrides, - // [CallerArgumentExpression(nameof(expectedOverrides))] string overridesText = "" - // ) => new TestCaseData(folderArg, expectedOverrides).SetArgDisplayNames(folderArg, overridesText); + public static TheoryData FullyCustomFoldersCommandLines() => + new() + { + { + "Mostly defaults", + "/tmp/jalla", + @"--folders=folder1=type:Once;folder2=type:EveryTime;folder3=type:AnyTime", + new FoldersConfiguration( + new MigrationsFolder("folder1", MigrationType.Once), + new MigrationsFolder("folder2", MigrationType.EveryTime), + new MigrationsFolder("folder3", MigrationType.AnyTime) + ) + } + }; - // private static TestCaseData GetCustomisedTestCase( - // string caseName, - // string root, - // string folderArg, - // IFoldersConfiguration expected - // ) => new TestCaseData(root, folderArg, expected).SetArgDisplayNames(caseName, folderArg); private static void AssertEquivalent( IEnumerable expected, @@ -120,4 +113,18 @@ private static void AssertEquivalent(MigrationsFolder? expected, MigrationsFolde return cfg; } + + private static KnownFolderNamesWithDescription? Wrap(KnownFolderNames? names, [CallerArgumentExpression(nameof(names))] string description = "") => + names is { } ? new KnownFolderNamesWithDescription(names) { Description = description} : null; + + public record KnownFolderNamesWithDescription : KnownFolderNames + { + public KnownFolderNamesWithDescription(KnownFolderNames folder) : base(folder) + { + } + + public string Description { get; init; } = null!; + public override string ToString() => Description; + } + } diff --git a/unittests/Basic_tests/Infrastructure/FolderConfiguration/KnownFolders_CustomNames.cs b/unittests/Basic_tests/Infrastructure/FolderConfiguration/KnownFolders_CustomNames.cs index b5266f90..9f949a7a 100644 --- a/unittests/Basic_tests/Infrastructure/FolderConfiguration/KnownFolders_CustomNames.cs +++ b/unittests/Basic_tests/Infrastructure/FolderConfiguration/KnownFolders_CustomNames.cs @@ -3,10 +3,10 @@ using grate.Configuration; using grate.Migration; using TestCommon.TestInfrastructure; -using Xunit; using static grate.Configuration.KnownFolderKeys; using static grate.Configuration.MigrationType; using static grate.Migration.ConnectionType; +using static TestCommon.TestInfrastructure.DescriptiveTestObjects; namespace Basic_tests.Infrastructure.FolderConfiguration; @@ -43,20 +43,20 @@ public void Returns_folders_in_same_order_as_default() [MemberData(nameof(ExpectedKnownFolderNames))] public void Has_expected_folder_configuration( MigrationsFolder folder, - string expectedName, - MigrationType expectedType, - ConnectionType expectedConnectionType, - TransactionHandling transactionHandling + string name, + MigrationType type, + ConnectionType conn, + TransactionHandling tran ) { var root = Root.ToString(); Assert.Multiple(() => { - folder.Path.Should().Be(expectedName); - folder.Type.Should().Be(expectedType); - folder.ConnectionType.Should().Be(expectedConnectionType); - folder.TransactionHandling.Should().Be(transactionHandling); + folder.Path.Should().Be(name); + folder.Type.Should().Be(type); + folder.ConnectionType.Should().Be(conn); + folder.TransactionHandling.Should().Be(tran); }); } @@ -81,22 +81,26 @@ TransactionHandling transactionHandling private static readonly DirectoryInfo Root = TestConfig.CreateRandomTempDirectory(); private static readonly IFoldersConfiguration Folders = FoldersConfiguration.Default(OverriddenFolderNames); - - public static IEnumerable ExpectedKnownFolderNames() + + public static TheoryData ExpectedKnownFolderNames() { - yield return new object?[] { Folders[BeforeMigration], OverriddenFolderNames.BeforeMigration, EveryTime, Default, TransactionHandling.Autonomous }; - yield return new object?[] { Folders[AlterDatabase], OverriddenFolderNames.AlterDatabase, AnyTime, Admin, TransactionHandling.Autonomous }; - yield return new object?[] { Folders[RunAfterCreateDatabase], OverriddenFolderNames.RunAfterCreateDatabase, AnyTime, Default, TransactionHandling.Default }; - yield return new object?[] { Folders[RunBeforeUp], OverriddenFolderNames.RunBeforeUp, AnyTime, Default, TransactionHandling.Default }; - yield return new object?[] { Folders[Up], OverriddenFolderNames.Up, Once, Default, TransactionHandling.Default }; - yield return new object?[] { Folders[RunFirstAfterUp], OverriddenFolderNames.RunFirstAfterUp, AnyTime, Default, TransactionHandling.Default }; - yield return new object?[] { Folders[Functions], OverriddenFolderNames.Functions, AnyTime, Default, TransactionHandling.Default }; - yield return new object?[] { Folders[Views], OverriddenFolderNames.Views, AnyTime, Default, TransactionHandling.Default }; - yield return new object?[] { Folders[Sprocs], OverriddenFolderNames.Sprocs, AnyTime, Default, TransactionHandling.Default }; - yield return new object?[] { Folders[Triggers], OverriddenFolderNames.Triggers, AnyTime, Default, TransactionHandling.Default }; - yield return new object?[] { Folders[Indexes], OverriddenFolderNames.Indexes, AnyTime, Default, TransactionHandling.Default }; - yield return new object?[] { Folders[RunAfterOtherAnyTimeScripts], OverriddenFolderNames.RunAfterOtherAnyTimeScripts, AnyTime, Default, TransactionHandling.Default }; - yield return new object?[] { Folders[Permissions], OverriddenFolderNames.Permissions, EveryTime, Default, TransactionHandling.Autonomous }; - yield return new object?[] { Folders[AfterMigration], OverriddenFolderNames.AfterMigration, EveryTime, Default, TransactionHandling.Autonomous }; + var data = new TheoryData + { + { Describe(Folders[BeforeMigration]), OverriddenFolderNames.BeforeMigration, EveryTime, Default, TransactionHandling.Autonomous }, + { Describe(Folders[AlterDatabase]), OverriddenFolderNames.AlterDatabase, AnyTime, Admin, TransactionHandling.Autonomous }, + { Describe(Folders[RunAfterCreateDatabase]), OverriddenFolderNames.RunAfterCreateDatabase, AnyTime, Default, TransactionHandling.Default }, + { Describe(Folders[RunBeforeUp]), OverriddenFolderNames.RunBeforeUp, AnyTime, Default, TransactionHandling.Default }, + { Describe(Folders[Up]), OverriddenFolderNames.Up, Once, Default, TransactionHandling.Default }, + { Describe(Folders[RunFirstAfterUp]), OverriddenFolderNames.RunFirstAfterUp, AnyTime, Default, TransactionHandling.Default }, + { Describe(Folders[Functions]), OverriddenFolderNames.Functions, AnyTime, Default, TransactionHandling.Default }, + { Describe(Folders[Views]), OverriddenFolderNames.Views, AnyTime, Default, TransactionHandling.Default }, + { Describe(Folders[Sprocs]), OverriddenFolderNames.Sprocs, AnyTime, Default, TransactionHandling.Default }, + { Describe(Folders[Triggers]), OverriddenFolderNames.Triggers, AnyTime, Default, TransactionHandling.Default }, + { Describe(Folders[Indexes]), OverriddenFolderNames.Indexes, AnyTime, Default, TransactionHandling.Default }, + { Describe(Folders[RunAfterOtherAnyTimeScripts]), OverriddenFolderNames.RunAfterOtherAnyTimeScripts, AnyTime, Default, TransactionHandling.Default }, + { Describe(Folders[Permissions]), OverriddenFolderNames.Permissions, EveryTime, Default, TransactionHandling.Autonomous }, + { Describe(Folders[AfterMigration]), OverriddenFolderNames.AfterMigration, EveryTime, Default, TransactionHandling.Autonomous } + }; + return data; } } diff --git a/unittests/Basic_tests/xunit.runner.json b/unittests/Basic_tests/xunit.runner.json new file mode 100644 index 00000000..6f222d39 --- /dev/null +++ b/unittests/Basic_tests/xunit.runner.json @@ -0,0 +1,5 @@ +{ + "$schema": "https://xunit.net/schema/current/xunit.runner.schema.json", + "methodDisplay": "method", + "methodDisplayOptions": "all" +} \ No newline at end of file diff --git a/unittests/MariaDB/MariaDB.csproj b/unittests/MariaDB/MariaDB.csproj index e1bc48a0..d72d7d75 100644 --- a/unittests/MariaDB/MariaDB.csproj +++ b/unittests/MariaDB/MariaDB.csproj @@ -21,6 +21,12 @@ + + + PreserveNewest + + + diff --git a/unittests/MariaDB/xunit.runner.json b/unittests/MariaDB/xunit.runner.json new file mode 100644 index 00000000..6f222d39 --- /dev/null +++ b/unittests/MariaDB/xunit.runner.json @@ -0,0 +1,5 @@ +{ + "$schema": "https://xunit.net/schema/current/xunit.runner.schema.json", + "methodDisplay": "method", + "methodDisplayOptions": "all" +} \ No newline at end of file diff --git a/unittests/Oracle/Oracle.csproj b/unittests/Oracle/Oracle.csproj index fdc753dc..7cb7f928 100644 --- a/unittests/Oracle/Oracle.csproj +++ b/unittests/Oracle/Oracle.csproj @@ -22,5 +22,11 @@ + + + PreserveNewest + + + diff --git a/unittests/Oracle/xunit.runner.json b/unittests/Oracle/xunit.runner.json new file mode 100644 index 00000000..6f222d39 --- /dev/null +++ b/unittests/Oracle/xunit.runner.json @@ -0,0 +1,5 @@ +{ + "$schema": "https://xunit.net/schema/current/xunit.runner.schema.json", + "methodDisplay": "method", + "methodDisplayOptions": "all" +} \ No newline at end of file diff --git a/unittests/PostgreSQL/PostgreSQL.csproj b/unittests/PostgreSQL/PostgreSQL.csproj index 0d5d34d1..2533b81d 100644 --- a/unittests/PostgreSQL/PostgreSQL.csproj +++ b/unittests/PostgreSQL/PostgreSQL.csproj @@ -22,6 +22,12 @@ + + + PreserveNewest + + + diff --git a/unittests/PostgreSQL/xunit.runner.json b/unittests/PostgreSQL/xunit.runner.json new file mode 100644 index 00000000..6f222d39 --- /dev/null +++ b/unittests/PostgreSQL/xunit.runner.json @@ -0,0 +1,5 @@ +{ + "$schema": "https://xunit.net/schema/current/xunit.runner.schema.json", + "methodDisplay": "method", + "methodDisplayOptions": "all" +} \ No newline at end of file diff --git a/unittests/SqlServer/SqlServer.csproj b/unittests/SqlServer/SqlServer.csproj index 3c4b9155..78bcbb5e 100644 --- a/unittests/SqlServer/SqlServer.csproj +++ b/unittests/SqlServer/SqlServer.csproj @@ -22,5 +22,11 @@ + + + PreserveNewest + + + diff --git a/unittests/SqlServer/TestInfrastructure/SqlServerTestContainer.cs b/unittests/SqlServer/TestInfrastructure/SqlServerTestContainer.cs index 0f92fa1b..aa9b6ae4 100644 --- a/unittests/SqlServer/TestInfrastructure/SqlServerTestContainer.cs +++ b/unittests/SqlServer/TestInfrastructure/SqlServerTestContainer.cs @@ -4,18 +4,16 @@ namespace TestCommon.TestInfrastructure; public class SqlServerTestContainer : ContainerFixture { - // on arm64 (M1), the standard mssql/server image is not available - public string? DockerImage => RuntimeInformation.ProcessArchitecture switch - { - Arm64 => "mcr.microsoft.com/azure-sql-edge:latest", - X64 => "mcr.microsoft.com/mssql/server:2019-latest", - var other => throw new PlatformNotSupportedException("Unsupported platform for running tests: " + other) - }; + + // Run with linux/amd86 on ARM architectures too, the docker emulation is good enough + public string? DockerImage => "mcr.microsoft.com/mssql/server:2019-latest"; + public int Port = 1433; public SqlServerTestContainer() { TestContainer = new MsSqlBuilder() .WithImage(DockerImage) + .WithEnvironment("DOCKER_DEFAULT_PLATFORM", "linux/amd64") .WithPassword(AdminPassword) .WithPortBinding(Port, true) .WithEnvironment("MSSQL_COLLATION", "Danish_Norwegian_CI_AS") diff --git a/unittests/SqlServer/xunit.runner.json b/unittests/SqlServer/xunit.runner.json new file mode 100644 index 00000000..6f222d39 --- /dev/null +++ b/unittests/SqlServer/xunit.runner.json @@ -0,0 +1,5 @@ +{ + "$schema": "https://xunit.net/schema/current/xunit.runner.schema.json", + "methodDisplay": "method", + "methodDisplayOptions": "all" +} \ No newline at end of file diff --git a/unittests/SqlServerCaseSensitive/SqlServerCaseSensitive.csproj b/unittests/SqlServerCaseSensitive/SqlServerCaseSensitive.csproj index 3c4b9155..78bcbb5e 100644 --- a/unittests/SqlServerCaseSensitive/SqlServerCaseSensitive.csproj +++ b/unittests/SqlServerCaseSensitive/SqlServerCaseSensitive.csproj @@ -22,5 +22,11 @@ + + + PreserveNewest + + + diff --git a/unittests/SqlServerCaseSensitive/xunit.runner.json b/unittests/SqlServerCaseSensitive/xunit.runner.json new file mode 100644 index 00000000..6f222d39 --- /dev/null +++ b/unittests/SqlServerCaseSensitive/xunit.runner.json @@ -0,0 +1,5 @@ +{ + "$schema": "https://xunit.net/schema/current/xunit.runner.schema.json", + "methodDisplay": "method", + "methodDisplayOptions": "all" +} \ No newline at end of file diff --git a/unittests/Sqlite/Sqlite.csproj b/unittests/Sqlite/Sqlite.csproj index 4cac57bf..7b4a655d 100644 --- a/unittests/Sqlite/Sqlite.csproj +++ b/unittests/Sqlite/Sqlite.csproj @@ -21,5 +21,11 @@ + + + PreserveNewest + + + diff --git a/unittests/Sqlite/xunit.runner.json b/unittests/Sqlite/xunit.runner.json new file mode 100644 index 00000000..6f222d39 --- /dev/null +++ b/unittests/Sqlite/xunit.runner.json @@ -0,0 +1,5 @@ +{ + "$schema": "https://xunit.net/schema/current/xunit.runner.schema.json", + "methodDisplay": "method", + "methodDisplayOptions": "all" +} \ No newline at end of file diff --git a/unittests/TestCommon/Generic/GenericMigrationTables.cs b/unittests/TestCommon/Generic/GenericMigrationTables.cs index 7acb2607..8eb0a3a6 100644 --- a/unittests/TestCommon/Generic/GenericMigrationTables.cs +++ b/unittests/TestCommon/Generic/GenericMigrationTables.cs @@ -76,28 +76,33 @@ public async Task Is_created_even_if_scripts_fail(string tableName) } scripts.Should().NotBeNull(); } + // [Theory] // [InlineData("ScriptsRun")] // [InlineData("ScriptsRunErrors")] // [InlineData("Version")] - // public async Task Migration_does_not_fail_if_table_already_exists(string tableName) - // { - // var db = "MonoBonoJono"; - - // var parent = TestConfig.CreateRandomTempDirectory(); - // var knownFolders = FoldersConfiguration.Default(null); - - // await using (var migrator = Context.GetMigrator(db, parent, knownFolders)) - // { - // await migrator.Migrate(); - // } - - // // Run migration again - make sure it does not throw an exception - // await using (var migrator = Context.GetMigrator(db, parent, knownFolders)) - // { - // Assert.DoesNotThrowAsync(() => migrator.Migrate()); - // } - // } + //public async Task Migration_does_not_fail_if_table_already_exists(string tableName) + [Fact] + public async Task Migration_does_not_fail_if_table_already_exists() + { + var db = "MonoBonoJono"; + + var parent = TestConfig.CreateRandomTempDirectory(); + var knownFolders = FoldersConfiguration.Default(null); + + await using (var migrator = Context.GetMigrator(db, parent, knownFolders)) + { + await migrator.Migrate(); + } + + // Run migration again - make sure it does not throw an exception + await using (var migrator = Context.GetMigrator(db, parent, knownFolders)) + { + var exception = await Record.ExceptionAsync(() => migrator.Migrate()); + Assert.Null(exception); + } + } + [Theory] [InlineData("version")] [InlineData("vErSiON")] diff --git a/unittests/TestCommon/Generic/Running_MigrationScripts/Failing_Scripts.cs b/unittests/TestCommon/Generic/Running_MigrationScripts/Failing_Scripts.cs index 21532e1c..c431fa15 100644 --- a/unittests/TestCommon/Generic/Running_MigrationScripts/Failing_Scripts.cs +++ b/unittests/TestCommon/Generic/Running_MigrationScripts/Failing_Scripts.cs @@ -1,5 +1,4 @@ -using System.Runtime.CompilerServices; -using System.Transactions; +using System.Transactions; using Dapper; using FluentAssertions; using grate.Configuration; @@ -7,6 +6,7 @@ using grate.Migration; using TestCommon.TestInfrastructure; using static grate.Configuration.KnownFolderKeys; +using static TestCommon.TestInfrastructure.DescriptiveTestObjects; namespace TestCommon.Generic.Running_MigrationScripts; @@ -127,12 +127,14 @@ public void Ensure_Command_Timeout_Fires() CommandTimeout = 1, // shorter than the script runs for }; - Record.ExceptionAsync(async () => + var exception = Record.ExceptionAsync(async () => { await using var migrator = Context.GetMigrator(config); await migrator.Migrate(); Assert.Fail("Should have thrown a timeout exception prior to this!"); }); + + exception.Should().NotBeNull(); } [Fact] @@ -158,12 +160,14 @@ public void Ensure_AdminCommand_Timeout_Fires() AdminCommandTimeout = 1, // shorter than the script runs for }; - Record.ExceptionAsync(async () => + var exception = Record.ExceptionAsync(async () => { await using var migrator = Context.GetMigrator(config); await migrator.Migrate(); Assert.Fail("Should have thrown a timeout exception prior to this!"); }); + + exception.Should().NotBeNull(); } [Theory] @@ -283,34 +287,28 @@ protected void CreateLongInvalidSql(DirectoryInfo root, MigrationsFolder? folder //private static readonly DirectoryInfo Root = TestConfig.CreateRandomTempDirectory(); private static readonly IFoldersConfiguration Folders = FoldersConfiguration.Default(null); - public static IEnumerable ShouldStillBeRunOnRollback() - { - yield return new object?[] { Folders[BeforeMigration] }; - yield return new object?[] { Folders[AlterDatabase] }; - yield return new object?[] { Folders[Permissions] }; - yield return new object?[] { Folders[AfterMigration] }; - } + public static TheoryData ShouldStillBeRunOnRollback() => + new() + { + { Describe(Folders[BeforeMigration]) }, + { Describe(Folders[AlterDatabase]) }, + { Describe(Folders[Permissions]) }, + { Describe(Folders[AfterMigration]) } + }; - public static IEnumerable ShouldNotBeRunOnRollback() - { - yield return new object?[] { Folders[RunAfterCreateDatabase] }; - yield return new object?[] { Folders[RunBeforeUp] }; - yield return new object?[] { Folders[Up] }; - yield return new object?[] { Folders[RunFirstAfterUp] }; - yield return new object?[] { Folders[Functions] }; - yield return new object?[] { Folders[Views] }; - yield return new object?[] { Folders[Sprocs] }; - yield return new object?[] { Folders[Triggers] }; - yield return new object?[] { Folders[Indexes] }; - yield return new object?[] { Folders[RunAfterOtherAnyTimeScripts] }; - } + public static TheoryData ShouldNotBeRunOnRollback() => + new() + { + { Describe(Folders[RunAfterCreateDatabase]) }, + { Describe(Folders[RunBeforeUp]) }, + { Describe(Folders[Up]) }, + { Describe(Folders[RunFirstAfterUp]) }, + { Describe(Folders[Functions]) }, + { Describe(Folders[Views]) }, + { Describe(Folders[Sprocs]) }, + { Describe(Folders[Triggers]) }, + { Describe(Folders[Indexes]) }, + { Describe(Folders[RunAfterOtherAnyTimeScripts]) } + }; - // private static TestCaseData GetTestCase( - // MigrationsFolder? folder, - // [CallerArgumentExpression(nameof(folder))] string migrationsFolderDefinitionName = "" - // ) => - // new TestCaseData(folder) - // .SetArgDisplayNames( - // migrationsFolderDefinitionName - // ); } diff --git a/unittests/TestCommon/TestInfrastructure/DescriptiveTestObjects.cs b/unittests/TestCommon/TestInfrastructure/DescriptiveTestObjects.cs new file mode 100644 index 00000000..4ec81814 --- /dev/null +++ b/unittests/TestCommon/TestInfrastructure/DescriptiveTestObjects.cs @@ -0,0 +1,29 @@ +using System.Runtime.CompilerServices; +using grate.Configuration; + +namespace TestCommon.TestInfrastructure; + +public static class DescriptiveTestObjects +{ + public static MigrationsFolderWithDescription? Describe(MigrationsFolder? folder, + [CallerArgumentExpression(nameof(folder))] string description = "") => + folder is { } ? new MigrationsFolderWithDescription(folder, description) : null; +} + +public record MigrationsFolderWithDescription: MigrationsFolder + { + public MigrationsFolderWithDescription(MigrationsFolder baseFolder, string description) : base( + baseFolder.Name, + baseFolder.Path, + baseFolder.Type, + baseFolder.ConnectionType, + baseFolder.TransactionHandling + ) + { + Description = description; + } + + private string Description { get; } = null!; + public override string ToString() => Description; + } + diff --git a/unittests/TestCommon/TestInfrastructure/TheoryData.cs b/unittests/TestCommon/TestInfrastructure/TheoryData.cs new file mode 100644 index 00000000..d20fc0b6 --- /dev/null +++ b/unittests/TestCommon/TestInfrastructure/TheoryData.cs @@ -0,0 +1,19 @@ +// using System.Collections; +// +// namespace TestCommon.TestInfrastructure; +// +// public abstract record TheoryData() : IEnumerable +// { +// readonly List _data = []; +// protected void AddRow(params object[] values) => _data.Add(values); +// public IEnumerator GetEnumerator() => _data.GetEnumerator(); +// IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); +// } +// +// public record TheoryData : TheoryData; +// public record TheoryData : TheoryData; +// public record TheoryData : TheoryData; +// public record TheoryData : TheoryData; +// public record TheoryData : TheoryData; +// public record TheoryData : TheoryData; +// public record TheoryData : TheoryData;