Skip to content

Commit

Permalink
WIP: Working on fixes to PR :)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikbra committed Dec 17, 2023
1 parent 3169ebf commit bb9fabb
Show file tree
Hide file tree
Showing 17 changed files with 158 additions and 15 deletions.
6 changes: 6 additions & 0 deletions unittests/Basic_tests/Basic_tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@
<ProjectReference Include="..\TestCommon\TestCommon.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="xunit.runner.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Immutable;
using System.Runtime.CompilerServices;
using FluentAssertions;
using grate.Configuration;
using grate.Migration;
Expand Down Expand Up @@ -43,20 +44,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);
});
}

Expand All @@ -82,7 +83,7 @@ TransactionHandling transactionHandling
private static readonly DirectoryInfo Root = TestConfig.CreateRandomTempDirectory();
private static readonly IFoldersConfiguration Folders = FoldersConfiguration.Default(OverriddenFolderNames);

public static IEnumerable<object?[]> ExpectedKnownFolderNames()
public static IEnumerable<object?[]> ExpectedKnownFolderNamez()
{
yield return new object?[] { Folders[BeforeMigration], OverriddenFolderNames.BeforeMigration, EveryTime, Default, TransactionHandling.Autonomous };
yield return new object?[] { Folders[AlterDatabase], OverriddenFolderNames.AlterDatabase, AnyTime, Admin, TransactionHandling.Autonomous };
Expand All @@ -99,4 +100,46 @@ TransactionHandling transactionHandling
yield return new object?[] { Folders[Permissions], OverriddenFolderNames.Permissions, EveryTime, Default, TransactionHandling.Autonomous };
yield return new object?[] { Folders[AfterMigration], OverriddenFolderNames.AfterMigration, EveryTime, Default, TransactionHandling.Autonomous };
}

public static TheoryData<MigrationsFolderWithDescription?, string, MigrationType, ConnectionType, TransactionHandling> ExpectedKnownFolderNames()
{
var data = new TheoryData<MigrationsFolderWithDescription?, string, MigrationType, ConnectionType, TransactionHandling>
{
{ Wrap(Folders[BeforeMigration]), OverriddenFolderNames.BeforeMigration, EveryTime, Default, TransactionHandling.Autonomous },
{ Wrap(Folders[AlterDatabase]), OverriddenFolderNames.AlterDatabase, AnyTime, Admin, TransactionHandling.Autonomous },
{ Wrap(Folders[RunAfterCreateDatabase]), OverriddenFolderNames.RunAfterCreateDatabase, AnyTime, Default, TransactionHandling.Default },
{ Wrap(Folders[RunBeforeUp]), OverriddenFolderNames.RunBeforeUp, AnyTime, Default, TransactionHandling.Default },
{ Wrap(Folders[Up]), OverriddenFolderNames.Up, Once, Default, TransactionHandling.Default },
{ Wrap(Folders[RunFirstAfterUp]), OverriddenFolderNames.RunFirstAfterUp, AnyTime, Default, TransactionHandling.Default },
{ Wrap(Folders[Functions]), OverriddenFolderNames.Functions, AnyTime, Default, TransactionHandling.Default },
{ Wrap(Folders[Views]), OverriddenFolderNames.Views, AnyTime, Default, TransactionHandling.Default },
{ Wrap(Folders[Sprocs]), OverriddenFolderNames.Sprocs, AnyTime, Default, TransactionHandling.Default },
{ Wrap(Folders[Triggers]), OverriddenFolderNames.Triggers, AnyTime, Default, TransactionHandling.Default },
{ Wrap(Folders[Indexes]), OverriddenFolderNames.Indexes, AnyTime, Default, TransactionHandling.Default },
{ Wrap(Folders[RunAfterOtherAnyTimeScripts]), OverriddenFolderNames.RunAfterOtherAnyTimeScripts, AnyTime, Default, TransactionHandling.Default },
{ Wrap(Folders[Permissions]), OverriddenFolderNames.Permissions, EveryTime, Default, TransactionHandling.Autonomous },
{ Wrap(Folders[AfterMigration]), OverriddenFolderNames.AfterMigration, EveryTime, Default, TransactionHandling.Autonomous }
};
return data;
}

private static MigrationsFolderWithDescription? Wrap(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;
}
}
5 changes: 5 additions & 0 deletions unittests/Basic_tests/xunit.runner.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "https://xunit.net/schema/current/xunit.runner.schema.json",
"methodDisplay": "method",
"methodDisplayOptions": "all"
}
6 changes: 6 additions & 0 deletions unittests/MariaDB/MariaDB.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
<ProjectReference Include="..\TestCommon\TestCommon.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="xunit.runner.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>



</Project>
5 changes: 5 additions & 0 deletions unittests/MariaDB/xunit.runner.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "https://xunit.net/schema/current/xunit.runner.schema.json",
"methodDisplay": "method",
"methodDisplayOptions": "all"
}
6 changes: 6 additions & 0 deletions unittests/Oracle/Oracle.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,11 @@
<ProjectReference Include="..\TestCommon\TestCommon.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="xunit.runner.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>


</Project>
5 changes: 5 additions & 0 deletions unittests/Oracle/xunit.runner.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "https://xunit.net/schema/current/xunit.runner.schema.json",
"methodDisplay": "method",
"methodDisplayOptions": "all"
}
6 changes: 6 additions & 0 deletions unittests/PostgreSQL/PostgreSQL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
<ProjectReference Include="..\TestCommon\TestCommon.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="xunit.runner.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>




Expand Down
5 changes: 5 additions & 0 deletions unittests/PostgreSQL/xunit.runner.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "https://xunit.net/schema/current/xunit.runner.schema.json",
"methodDisplay": "method",
"methodDisplayOptions": "all"
}
6 changes: 6 additions & 0 deletions unittests/SqlServer/SqlServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,11 @@
<ProjectReference Include="..\TestCommon\TestCommon.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="xunit.runner.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>


</Project>
16 changes: 10 additions & 6 deletions unittests/SqlServer/TestInfrastructure/SqlServerTestContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@ 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)
};
// 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)
// };

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")
Expand Down
5 changes: 5 additions & 0 deletions unittests/SqlServer/xunit.runner.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "https://xunit.net/schema/current/xunit.runner.schema.json",
"methodDisplay": "method",
"methodDisplayOptions": "all"
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,11 @@
<ProjectReference Include="..\TestCommon\TestCommon.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="xunit.runner.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>


</Project>
5 changes: 5 additions & 0 deletions unittests/SqlServerCaseSensitive/xunit.runner.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "https://xunit.net/schema/current/xunit.runner.schema.json",
"methodDisplay": "method",
"methodDisplayOptions": "all"
}
6 changes: 6 additions & 0 deletions unittests/Sqlite/Sqlite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,11 @@
<ProjectReference Include="..\TestCommon\TestCommon.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="xunit.runner.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>


</Project>
5 changes: 5 additions & 0 deletions unittests/Sqlite/xunit.runner.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "https://xunit.net/schema/current/xunit.runner.schema.json",
"methodDisplay": "method",
"methodDisplayOptions": "all"
}
19 changes: 19 additions & 0 deletions unittests/TestCommon/TestInfrastructure/TheoryData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// using System.Collections;
//
// namespace TestCommon.TestInfrastructure;
//
// public abstract record TheoryData() : IEnumerable<object[]>
// {
// readonly List<object[]> _data = [];
// protected void AddRow(params object[] values) => _data.Add(values);
// public IEnumerator<object[]> GetEnumerator() => _data.GetEnumerator();
// IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
// }
//
// public record TheoryData<T1> : TheoryData;
// public record TheoryData<T1, T2> : TheoryData;
// public record TheoryData<T1, T2, T3> : TheoryData;
// public record TheoryData<T1, T2, T3, T4> : TheoryData;
// public record TheoryData<T1, T2, T3, T4, T5> : TheoryData;
// public record TheoryData<T1, T2, T3, T4, T5, T6> : TheoryData;
// public record TheoryData<T1, T2, T3, T4, T5, T6, T7> : TheoryData;

0 comments on commit bb9fabb

Please sign in to comment.