Skip to content

Commit 450720a

Browse files
Ja bist du narrischJa bist du narrisch
authored andcommitted
Move SQLite generic tests to separate file
1 parent 203e5bf commit 450720a

File tree

5 files changed

+116
-75
lines changed

5 files changed

+116
-75
lines changed

src/Migrator.Tests/Providers/Base/TransformationProviderBase.cs

Lines changed: 11 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,16 @@
11
using System;
22
using System.Data;
33
using Migrator.Framework;
4+
using Migrator.Tests.Providers.Base;
45
using NUnit.Framework;
56

67
namespace Migrator.Tests.Providers;
78

89
/// <summary>
910
/// Base class for Provider tests for all non-constraint oriented tests.
1011
/// </summary>
11-
public class TransformationProviderBase
12+
public abstract class TransformationProviderBase : TransformationProviderSimpleBase
1213
{
13-
protected ITransformationProvider Provider;
14-
15-
[TearDown]
16-
public virtual void TearDown()
17-
{
18-
DropTestTables();
19-
20-
Provider.Rollback();
21-
}
22-
23-
protected void DropTestTables()
24-
{
25-
// Because MySql doesn't support schema transaction
26-
// we got to remove the tables manually... sad...
27-
try
28-
{
29-
Provider.RemoveTable("TestTwo");
30-
}
31-
catch (Exception)
32-
{
33-
}
34-
try
35-
{
36-
Provider.RemoveTable("Test");
37-
}
38-
catch (Exception)
39-
{
40-
}
41-
try
42-
{
43-
Provider.RemoveTable("SchemaInfo");
44-
}
45-
catch (Exception)
46-
{
47-
}
48-
}
49-
50-
public void AddDefaultTable()
51-
{
52-
Provider.AddTable("TestTwo",
53-
new Column("Id", DbType.Int32, ColumnProperty.PrimaryKey),
54-
new Column("TestId", DbType.Int32, ColumnProperty.ForeignKey)
55-
);
56-
}
57-
58-
public void AddTable()
59-
{
60-
Provider.AddTable("Test",
61-
new Column("Id", DbType.Int32, ColumnProperty.NotNull),
62-
new Column("Title", DbType.String, 100, ColumnProperty.Null),
63-
new Column("name", DbType.String, 50, ColumnProperty.Null),
64-
new Column("blobVal", DbType.Binary, ColumnProperty.Null),
65-
new Column("boolVal", DbType.Boolean, ColumnProperty.Null),
66-
new Column("bigstring", DbType.String, 50000, ColumnProperty.Null)
67-
);
68-
}
69-
70-
public void AddTableWithPrimaryKey()
71-
{
72-
Provider.AddTable("Test",
73-
new Column("Id", DbType.Int32, ColumnProperty.PrimaryKeyWithIdentity),
74-
new Column("Title", DbType.String, 100, ColumnProperty.Null),
75-
new Column("name", DbType.String, 50, ColumnProperty.NotNull),
76-
new Column("blobVal", DbType.Binary),
77-
new Column("boolVal", DbType.Boolean),
78-
new Column("bigstring", DbType.String, 50000)
79-
);
80-
}
81-
8214
[Test]
8315
public void TableExistsWorks()
8416
{
@@ -209,7 +141,10 @@ public void RenameColumnToExistingColumn()
209141
[Test]
210142
public void RemoveUnexistingTable()
211143
{
212-
Provider.RemoveTable("abc");
144+
var exception = Assert.Catch(() => Provider.RemoveTable("abc"));
145+
var expectedMessage = "Table with name 'abc' does not exist to rename";
146+
147+
Assert.That(exception.Message, Is.EqualTo(expectedMessage));
213148
}
214149

215150
[Test]
@@ -301,8 +236,11 @@ public void RemoveColumnWithDefault()
301236
[Test]
302237
public void RemoveUnexistingColumn()
303238
{
304-
Provider.RemoveColumn("TestTwo", "abc");
305-
Provider.RemoveColumn("abc", "abc");
239+
var exception1 = Assert.Throws<Exception>(() => Provider.RemoveColumn("TestTwo", "abc"));
240+
var exception2 = Assert.Throws<Exception>(() => Provider.RemoveColumn("abc", "abc"));
241+
242+
Assert.That(exception1.Message, Is.EqualTo("Column does not exist"));
243+
Assert.That(exception2.Message, Is.EqualTo("Table does not exist"));
306244
}
307245

308246
/// <summary>

src/Migrator.Tests/Providers/Base/TransformationProviderConstraintBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Migrator.Tests.Providers
77
/// <summary>
88
/// Base class for Provider tests for all tests including constraint oriented tests.
99
/// </summary>
10-
public class TransformationProviderConstraintBase : TransformationProviderBase
10+
public abstract class TransformationProviderConstraintBase : TransformationProviderBase
1111
{
1212
public void AddForeignKey()
1313
{
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
using System;
2+
using System.Data;
3+
using Migrator.Framework;
4+
using NUnit.Framework;
5+
6+
namespace Migrator.Tests.Providers.Base;
7+
8+
public abstract class TransformationProviderSimpleBase
9+
{
10+
protected ITransformationProvider Provider;
11+
12+
[TearDown]
13+
public virtual void TearDown()
14+
{
15+
DropTestTables();
16+
17+
Provider.Rollback();
18+
}
19+
20+
protected void DropTestTables()
21+
{
22+
// Because MySql doesn't support schema transaction
23+
// we got to remove the tables manually... sad...
24+
try
25+
{
26+
Provider.RemoveTable("TestTwo");
27+
}
28+
catch (Exception)
29+
{
30+
}
31+
try
32+
{
33+
Provider.RemoveTable("Test");
34+
}
35+
catch (Exception)
36+
{
37+
}
38+
try
39+
{
40+
Provider.RemoveTable("SchemaInfo");
41+
}
42+
catch (Exception)
43+
{
44+
}
45+
}
46+
47+
public void AddDefaultTable()
48+
{
49+
Provider.AddTable("TestTwo",
50+
new Column("Id", DbType.Int32, ColumnProperty.PrimaryKey),
51+
new Column("TestId", DbType.Int32, ColumnProperty.ForeignKey)
52+
);
53+
}
54+
55+
public void AddTable()
56+
{
57+
Provider.AddTable("Test",
58+
new Column("Id", DbType.Int32, ColumnProperty.NotNull),
59+
new Column("Title", DbType.String, 100, ColumnProperty.Null),
60+
new Column("name", DbType.String, 50, ColumnProperty.Null),
61+
new Column("blobVal", DbType.Binary, ColumnProperty.Null),
62+
new Column("boolVal", DbType.Boolean, ColumnProperty.Null),
63+
new Column("bigstring", DbType.String, 50000, ColumnProperty.Null)
64+
);
65+
}
66+
67+
public void AddTableWithPrimaryKey()
68+
{
69+
Provider.AddTable("Test",
70+
new Column("Id", DbType.Int32, ColumnProperty.PrimaryKeyWithIdentity),
71+
new Column("Title", DbType.String, 100, ColumnProperty.Null),
72+
new Column("name", DbType.String, 50, ColumnProperty.NotNull),
73+
new Column("blobVal", DbType.Binary),
74+
new Column("boolVal", DbType.Boolean),
75+
new Column("bigstring", DbType.String, 50000)
76+
);
77+
}
78+
}

src/Migrator.Tests/Providers/SQLite/Base/SQLiteTransformationProviderTestBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
using DotNetProjects.Migrator.Providers.Impl.SQLite;
22
using Migrator.Providers.SQLite;
3+
using Migrator.Tests.Providers.Base;
34
using Migrator.Tests.Settings;
45
using NUnit.Framework;
56

67
namespace Migrator.Tests.Providers.SQLite.Base;
78

89
[TestFixture]
910
[Category("SQLite")]
10-
public class SQLiteTransformationProviderTestBase : TransformationProviderBase
11+
public abstract class SQLiteTransformationProviderTestBase : TransformationProviderSimpleBase
1112
{
1213
[SetUp]
1314
public void SetUp()
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using DotNetProjects.Migrator.Providers.Impl.SQLite;
2+
using Migrator.Providers.SQLite;
3+
using Migrator.Tests.Settings;
4+
using NUnit.Framework;
5+
6+
namespace Migrator.Tests.Providers.SQLite.Base;
7+
8+
[TestFixture]
9+
[Category("SQLite")]
10+
public class SQLiteTransformationProviderGenericTests : TransformationProviderBase
11+
{
12+
[SetUp]
13+
public void SetUp()
14+
{
15+
var configReader = new ConfigurationReader();
16+
var connectionString = configReader.GetDatabaseConnectionConfigById("SQLiteConnectionString")
17+
.ConnectionString;
18+
19+
Provider = new SQLiteTransformationProvider(new SQLiteDialect(), connectionString, "default", null);
20+
Provider.BeginTransaction();
21+
22+
AddDefaultTable();
23+
}
24+
}

0 commit comments

Comments
 (0)