Skip to content

Commit e6b8b9d

Browse files
JaBistDuNarrischJaBistDuNarrisch
authored andcommitted
Adjusted tests due to not supported PrimaryKeyExists in SQLite
1 parent 73a4094 commit e6b8b9d

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

src/Migrator.Tests/Providers/Generic/TransformationProviderGenericMiscConstraintBase.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,15 @@ public void AddCheckConstraint()
4444
public void CanAddPrimaryKey()
4545
{
4646
AddPrimaryKey();
47-
Assert.That(Provider.PrimaryKeyExists("Test", "PK_Test"), Is.True);
47+
48+
if (Provider is SQLiteTransformationProvider)
49+
{
50+
Assert.Throws<NotSupportedException>(() => Provider.PrimaryKeyExists("Test", "PK_Test"));
51+
}
52+
else
53+
{
54+
Assert.That(Provider.PrimaryKeyExists("Test", "PK_Test"), Is.True);
55+
}
4856
}
4957

5058
[Test]
Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
using System.Threading.Tasks;
2-
using DotNetProjects.Migrator.Providers.Impl.SQLite;
32
using Migrator.Tests.Providers.Base;
4-
using Migrator.Tests.Settings;
5-
using Migrator.Tests.Settings.Config;
63
using NUnit.Framework;
74

85
namespace Migrator.Tests.Providers.SQLite.Base;
@@ -14,15 +11,7 @@ public abstract class SQLiteTransformationProviderTestBase : TransformationProvi
1411
[SetUp]
1512
public async Task SetUpAsync()
1613
{
17-
var configReader = new ConfigurationReader();
18-
var connectionString = configReader.GetDatabaseConnectionConfigById(DatabaseConnectionConfigIds.SQLiteId)
19-
.ConnectionString;
20-
21-
Provider = new SQLiteTransformationProvider(new SQLiteDialect(), connectionString, "default", null);
22-
Provider.BeginTransaction();
23-
14+
await BeginSQLiteTransactionAsync();
2415
AddDefaultTable();
25-
26-
await Task.CompletedTask;
2716
}
2817
}

src/Migrator.Tests/Providers/SQLite/SQLiteTransformationProvider_RemoveColumnTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,9 @@ public void RemoveColumn_HavingMultipleSingleUniques_Succeeds()
198198
Provider.RemoveColumn(testTableName, propertyName2);
199199
var tableInfoAfter = ((SQLiteTransformationProvider)Provider).GetSQLiteTableInfo(testTableName);
200200

201-
Assert.That(tableInfoBefore.Uniques.Count, Is.EqualTo(2));
202-
Assert.That(tableInfoAfter.Uniques.Count, Is.EqualTo(1));
201+
// We do not support not named uniques in SQLite any more.
202+
Assert.That(tableInfoBefore.Uniques.Count, Is.EqualTo(0));
203+
Assert.That(tableInfoAfter.Uniques.Count, Is.EqualTo(0));
203204
}
204205

205206
[Test]

src/Migrator.Tests/Providers/SQLite/SQLiteTransformationProvider_RenameColumnTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
using DotNetProjects.Migrator.Framework;
44
using DotNetProjects.Migrator.Providers.Impl.SQLite;
55
using Migrator.Tests.Providers.Base;
6+
using Migrator.Tests.Providers.SQLite.Base;
67
using NUnit.Framework;
78

89
namespace Migrator.Tests.Providers.SQLite;
910

1011
[TestFixture]
1112
[Category("SQLite")]
12-
public class SQLiteTransformationProvider_RenameColumnTests : TransformationProviderBase
13+
public class SQLiteTransformationProvider_RenameColumnTests : SQLiteTransformationProviderTestBase
1314
{
1415
[Test]
1516
public void RenameColumn_HavingASingleForeignKeyPointingToTheTargetColumn_SingleColumnForeignKeyIsRemoved()

src/Migrator/Providers/TransformationProvider.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using DotNetProjects.Migrator.Framework;
1515
using DotNetProjects.Migrator.Framework.Loggers;
1616
using DotNetProjects.Migrator.Framework.SchemaBuilder;
17+
using DotNetProjects.Migrator.Providers.Impl.SQLite;
1718
using DotNetProjects.Migrator.Providers.Models;
1819
using System;
1920
using System.Collections.Generic;
@@ -392,9 +393,9 @@ public virtual void AddView(string name, string tableName, params IViewElement[]
392393
/// </example>
393394
public virtual void AddTable(string name, params IDbField[] columns)
394395
{
395-
if (columns.Any(x => x is CheckConstraint))
396+
if (this is not SQLiteTransformationProvider && columns.Any(x => x is CheckConstraint))
396397
{
397-
throw new MigrationException($"{nameof(CheckConstraint)}s are currently supported in SQLite only.");
398+
throw new MigrationException($"{nameof(CheckConstraint)}s are currently only supported in SQLite.");
398399
}
399400

400401
// Most databases don't have the concept of a storage engine, so default is to not use it.

0 commit comments

Comments
 (0)