Skip to content

Several fixes. #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Aug 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
dccadb3
Refactoring test class structure part I
Aug 13, 2025
bac2e3f
Added SQLite begin transaction in base test class
Aug 13, 2025
c3d24ad
Oracle, SQL Server, SQLite and Postgre SQL Begin Transaction moved to…
Aug 13, 2025
69afb8c
GetColumns tests
Aug 13, 2025
2df78f4
Renamings
Aug 13, 2025
ce77eae
Minor changes
Aug 13, 2025
a584a2c
Read data type in GetColumns in SQL Server
Aug 13, 2025
f676552
Extended parser for SQL Server default values. Test is now green for …
Aug 13, 2025
7048961
Added changes to GetColumns in Oracle.
Aug 13, 2025
2e92291
Added changes to GetColumns in Oracle.
Aug 14, 2025
d7ac6ec
Oracle test GetColumns_DefaultValues_Succeeds is green
Aug 14, 2025
b693821
SQLite does not support default BLOB values => throw
Aug 14, 2025
af56450
PostgreSQL GetColumns with default columns are green
Aug 14, 2025
e0f686c
Added RemoveConstraint
Aug 14, 2025
17b4e54
Escape Oracle strings
Aug 14, 2025
93d2986
Create new database for Postgre
Aug 14, 2025
722e1f8
Refactoring test
Aug 14, 2025
5c95ede
Added GetCheckConstraints, RemoveForeignKey and much more...
Aug 15, 2025
03febdd
Added Contains compatible with old .NET version
Aug 18, 2025
3f61417
Added checkConstraint test
Aug 18, 2025
ddf5015
Added check for CheckConstraints in AddTable in TransformationProvider
Aug 18, 2025
4547883
Moved getconstraints test from generic tests to Oracle, SQL Server an…
Aug 18, 2025
e40d34e
Moved AddTable test
Aug 18, 2025
73a4094
Added TableExists and FK exists checks
Aug 18, 2025
e6b8b9d
Adjusted tests due to not supported PrimaryKeyExists in SQLite
Aug 18, 2025
99a623f
override some AddColumn methods in SQLite
Aug 18, 2025
a126f33
Added some more overrides in SQLite
Aug 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
504 changes: 95 additions & 409 deletions src/Migrator.Tests/Providers/Base/TransformationProviderBase.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,8 @@

namespace Migrator.Tests.Providers.Base;

public abstract class TransformationProviderSimpleBase
public abstract class TransformationProviderSimpleBase : TransformationProviderBase
{
protected ITransformationProvider Provider;

[TearDown]
public virtual void TearDown()
{
DropTestTables();

Provider?.Rollback();
}

protected void DropTestTables()
{
// Because MySql doesn't support schema transaction
// we got to remove the tables manually... sad...
try
{
Provider.RemoveTable("TestTwo");
}
catch (Exception)
{
}
try
{
Provider.RemoveTable("Test");
}
catch (Exception)
{
}
try
{
Provider.RemoveTable("SchemaInfo");
}
catch (Exception)
{
}
}

public void AddDefaultTable()
{
Provider.AddTable("TestTwo",
Expand Down Expand Up @@ -75,4 +38,9 @@ public void AddTableWithPrimaryKey()
new Column("bigstring", DbType.String, 50000)
);
}

public void AddPrimaryKey()
{
Provider.AddPrimaryKey("PK_Test", "Test", "Id");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
using System.Data;
using System.Linq;
using DotNetProjects.Migrator.Framework;
using DotNetProjects.Migrator.Providers.Impl.SQLite;
using NUnit.Framework;

namespace Migrator.Tests.Providers;
namespace Migrator.Tests.Providers.Generic;

/// <summary>
/// Base class for Provider tests for all tests including constraint oriented tests.
/// Base class for provider tests for all tests including constraint oriented tests.
/// </summary>
public abstract class TransformationProviderConstraintBase : TransformationProviderBase
public abstract class TransformationProviderGenericMiscConstraintBase : TransformationProviderGenericMiscTests
{
public void AddForeignKey()
{
Expand All @@ -33,7 +34,7 @@ public void AddMultipleUniqueConstraint()
Provider.AddUniqueConstraint("UN_Test_TestTwo", "TestTwo", "Id", "TestId");
}

public void AddCheckConstraint()
public void AddTestCheckConstraint()
{
Provider.AddCheckConstraint("CK_TestTwo_TestId", "TestTwo", "TestId>5");
}
Expand All @@ -42,15 +43,23 @@ public void AddCheckConstraint()
public void CanAddPrimaryKey()
{
AddPrimaryKey();
Assert.That(Provider.PrimaryKeyExists("Test", "PK_Test"), Is.True);
}

[Test]
public void AddIndexedColumn()
{
Provider.AddColumn("TestTwo", "Test", DbType.String, 50, ColumnProperty.Indexed);
if (Provider is SQLiteTransformationProvider)
{
Assert.Throws<NotSupportedException>(() => Provider.PrimaryKeyExists("Test", "PK_Test"));
}
else
{
Assert.That(Provider.PrimaryKeyExists("Test", "PK_Test"), Is.True);
}
}

// [Test]
// public void AddIndexedColumn()
// {
// Provider.AddColumn("TestTwo", "Test", DbType.String, 50, ColumnProperty.Indexed);
// }

[Test]
public void AddUniqueColumn()
{
Expand Down Expand Up @@ -81,8 +90,10 @@ public virtual void CanAddMultipleUniqueConstraint()
[Test]
public virtual void CanAddCheckConstraint()
{
AddCheckConstraint();
Assert.That(Provider.ConstraintExists("TestTwo", "CK_TestTwo_TestId"), Is.True);
AddTestCheckConstraint();
var constraintExists = Provider.ConstraintExists("TestTwo", "CK_TestTwo_TestId");

Assert.That(constraintExists, Is.True);
}

[Test]
Expand All @@ -105,51 +116,52 @@ public void RemoveUniqueConstraint()
[Test]
public virtual void RemoveCheckConstraint()
{
AddCheckConstraint();
AddTestCheckConstraint();
Provider.RemoveConstraint("TestTwo", "CK_TestTwo_TestId");
Assert.That(Provider.ConstraintExists("TestTwo", "CK_TestTwo_TestId"), Is.False);
}

[Test]
public void RemoveUnexistingForeignKey()
{
// Arrange
AddForeignKey();
Provider.RemoveForeignKey("abc", "FK_Test_TestTwo");
Provider.RemoveForeignKey("abc", "abc");
Provider.RemoveForeignKey("Test", "abc");

// Act/Assert
// Table does not exist.
Assert.Throws<MigrationException>(() => Provider.RemoveForeignKey("NotExistingTable", "FK_Test_TestTwo"));

// Table exists but foreign key does not exist.
if (Provider is SQLiteTransformationProvider)
{
Assert.Throws<MigrationException>(() => Provider.RemoveForeignKey("Test", "NotExistingForeignKey"));
}
else
{
Assert.That(() => Provider.RemoveForeignKey("Test", "NotExistingForeignKey"), Throws.Exception);
}
}

[Test]
public void ConstraintExist()
{
AddForeignKey();
Assert.That(Provider.ConstraintExists("TestTwo", "FK_Test_TestTwo"), Is.True);
Assert.That(Provider.ConstraintExists("abc", "abc"), Is.False);
}

[Test]
public void AddTableWithCompoundPrimaryKey()
{
Provider.AddTable("Test",
new Column("PersonId", DbType.Int32, ColumnProperty.PrimaryKey),
new Column("AddressId", DbType.Int32, ColumnProperty.PrimaryKey)
);

Assert.That(Provider.TableExists("Test"), Is.True, "Table doesn't exist");
Assert.That(Provider.PrimaryKeyExists("Test", "PK_Test"), Is.True, "Constraint doesn't exist");
Assert.That(Provider.ConstraintExists("TestTwo", "abc"), Is.False);
}

[Test]
public void AddTableWithCompoundPrimaryKeyShouldKeepNullForOtherProperties()
{
Provider.AddTable("Test",
new Column("PersonId", DbType.Int32, ColumnProperty.PrimaryKey),
new Column("AddressId", DbType.Int32, ColumnProperty.PrimaryKey),
new Column("Name", DbType.String, 30, ColumnProperty.Null)
);
var testTableName = "Test";

Provider.AddTable(testTableName,
new Column("PersonId", DbType.Int32, ColumnProperty.PrimaryKey),
new Column("AddressId", DbType.Int32, ColumnProperty.PrimaryKey),
new Column("Name", DbType.String, 30, ColumnProperty.Null)
);

Assert.That(Provider.TableExists("Test"), Is.True, "Table doesn't exist");
Assert.That(Provider.PrimaryKeyExists("Test", "PK_Test"), Is.True, "Constraint doesn't exist");

var column = Provider.GetColumnByName("Test", "Name");

Expand Down
Loading
Loading