Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
carl-berg committed Jun 20, 2024
1 parent 49411c9 commit ff3d80b
Show file tree
Hide file tree
Showing 15 changed files with 131 additions and 125 deletions.
36 changes: 6 additions & 30 deletions DataDude.Tests/Core/DatabaseFixture.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,13 @@
using System.Collections.Generic;
using System.Reflection;
using ADatabaseFixture;
using ADatabaseFixture.GalacticWasteManagement;
using GalacticWasteManagement;
using GalacticWasteManagement.Scripts;
using GalacticWasteManagement.Scripts.EmbeddedScripts;
using GalacticWasteManagement.Scripts.ScriptProviders;
using ADatabaseFixture;
using Microsoft.Data.SqlClient;
using Xunit;

namespace DataDude.Tests.Core
{
public class DatabaseFixture : DatabaseFixtureBase, IAsyncLifetime
public class DatabaseFixture() : DatabaseFixtureBase(
new SqlServerDatabaseAdapter(ConnectionFactory),
new FixtureMigrator()), IAsyncLifetime
{
public DatabaseFixture()
: base(
new SqlServerDatabaseAdapter(),
GalacticWasteManagementMigrator.Create(new DefaultProjectSettings()))
{
}

private class DefaultProjectSettings : ProjectSettings
{
public DefaultProjectSettings()
: base(
new DefaultMigrationVersioning(),
new GalacticWasteManagement.SqlServer.MsSql150ScriptParser(),
new List<IScriptProvider>
{
new BuiltInScriptsScriptProvider(),
new EmbeddedScriptProvider(Assembly.GetAssembly(typeof(DatabaseFixture)), "Core.Scripts"),
})
{
}
}
public static SqlConnection ConnectionFactory(string connectionString) => new(connectionString);
}
}
11 changes: 3 additions & 8 deletions DataDude.Tests/Core/DatabaseTest.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
using System;
using System.Threading.Tasks;
using ADatabaseFixture.GalacticWasteManagement;
using System.Threading.Tasks;
using Respawn;
using Xunit;
using Xunit.Abstractions;

namespace DataDude.Tests.Core
{
[Collection("DatabaseIntegrationTest")]
public abstract class DatabaseTest : IAsyncLifetime
public abstract class DatabaseTest(DatabaseFixture fixture) : IAsyncLifetime
{
public DatabaseTest(DatabaseFixture fixture) => Fixture = fixture;

public DatabaseFixture Fixture { get; }
public DatabaseFixture Fixture { get; } = fixture;

private static Respawner Checkpoint { get; set; }

Expand Down
31 changes: 31 additions & 0 deletions DataDude.Tests/Core/FixtureMigrator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using ADatabaseMigrator.Hashing;
using ADatabaseMigrator.Journaling;
using ADatabaseMigrator.ScriptLoading.EmbeddedResources;
using ADatabaseMigrator;
using ADatabaseMigrator.ScriptLoading.EmbeddedResources.Versioning;
using System.Data.Common;
using Microsoft.Data.SqlClient;
using System.Threading.Tasks;
using System.Threading;
using ADatabaseMigrator.SqlServer;

namespace DataDude.Tests.Core
{
public class FixtureMigrator : ADatabaseFixture.IMigrator
{
public const string VersioningTable = MigrationScriptJournalManager.JournalTableName;

public async Task MigrateUp(string connectionString, CancellationToken? cancellationToken)
{
using var connection = new SqlConnection(connectionString);
connection.Open();
await new Migrator(
scriptLoader: new EmbeddedResourceScriptLoader(new MD5ScriptHasher(), config => config
.UsingAssemblyFromType<FixtureMigrator>()
.AddNamespaces<VersionFromPathVersionLoader>(MigrationScriptRunType.RunOnce, "Core.Scripts.Migrations")),
journalManager: new MigrationScriptJournalManager(connection),
scriptRunner: new SqlServerMigrationScriptRunner(connection))
.Migrate(cancellationToken);
}
}
}
10 changes: 2 additions & 8 deletions DataDude.Tests/Core/TestSchema.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
using System.Data;
using System.Data.Common;
using System.Data.Common;
using System.Threading.Tasks;
using DataDude.Schema;

namespace DataDude.Tests.Core
{
public class TestSchema : SchemaInformation, ISchemaLoader
public class TestSchema() : SchemaInformation([]), ISchemaLoader
{
public TestSchema()
: base(System.Array.Empty<TableInformation>())
{
}

public bool CacheSchema { get; set; }

public TestTable AddTable(string name) => AddTable(new TestTable(name));
Expand Down
2 changes: 1 addition & 1 deletion DataDude.Tests/Core/TestTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class TestTable : TableInformation
public TestTable(string name)
: this(name, c => c.AddIntegerColumn("Id", true))
{
AddIndex(new IndexInformation(this, $"PK_{name}", new[] { this["Id"] ! }, true, false, false, false));
AddIndex(new IndexInformation(this, $"PK_{name}", [this["Id"] !], true, false, false, false));
}

public TestTable(string name, Action<TestTableColumnBuilder> configureColumns)
Expand Down
21 changes: 12 additions & 9 deletions DataDude.Tests/DataDude.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ADatabaseFixture.GalacticWasteManagement" Version="0.4.0" />
<PackageReference Include="ADatabaseFixture.SqlServer" Version="0.4.0" />
<PackageReference Include="FakeItEasy" Version="7.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="ADatabaseFixture" Version="0.5.1" />
<PackageReference Include="ADatabaseMigrator" Version="0.2.2" />
<PackageReference Include="ADatabaseMigrator.SqlServer" Version="0.1.0" />
<PackageReference Include="Dapper" Version="2.1.35" />
<PackageReference Include="FakeItEasy" Version="8.3.0" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="Microsoft.SqlServer.Types" Version="160.1000.6" />
<PackageReference Include="Respawn" Version="6.0.0" />
<PackageReference Include="Shouldly" Version="4.1.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="Respawn" Version="6.2.1" />
<PackageReference Include="Shouldly" Version="4.2.1" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
7 changes: 1 addition & 6 deletions DataDude.Tests/ExecutionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@

namespace DataDude.Tests
{
public class ExecutionTests : DatabaseTest
public class ExecutionTests(DatabaseFixture fixture) : DatabaseTest(fixture)
{
public ExecutionTests(DatabaseFixture fixture)
: base(fixture)
{
}

[Fact]
public async Task Can_Execute_Instruction()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace DataDude.Tests.Inserts
{
public class AutoInsertFKTableTestscs
public class AutoInsertFKTableTests
{
[Fact]
public async Task Chain()
Expand Down
Loading

0 comments on commit ff3d80b

Please sign in to comment.