Skip to content

Commit f1f07cb

Browse files
authored
Merge pull request #51 from dotnetprojects/Sqlite
Updates RemoveColumn and RenameColumn
2 parents acaf01d + 392be10 commit f1f07cb

23 files changed

+1341
-873
lines changed

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

Lines changed: 478 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,147 +7,147 @@ 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
{
1414
AddTableWithPrimaryKey();
15-
_provider.AddForeignKey("FK_Test_TestTwo", "TestTwo", "TestId", "Test", "Id");
15+
Provider.AddForeignKey("FK_Test_TestTwo", "TestTwo", "TestId", "Test", "Id");
1616
}
1717

1818
public void AddPrimaryKey()
1919
{
2020
AddTable();
21-
_provider.AddPrimaryKey("PK_Test", "Test", "Id");
21+
Provider.AddPrimaryKey("PK_Test", "Test", "Id");
2222
}
2323

2424
public void AddUniqueConstraint()
2525
{
26-
_provider.AddUniqueConstraint("UN_Test_TestTwo", "TestTwo", "TestId");
26+
Provider.AddUniqueConstraint("UN_Test_TestTwo", "TestTwo", "TestId");
2727
}
2828

2929
public void AddMultipleUniqueConstraint()
3030
{
31-
_provider.AddUniqueConstraint("UN_Test_TestTwo", "TestTwo", "Id", "TestId");
31+
Provider.AddUniqueConstraint("UN_Test_TestTwo", "TestTwo", "Id", "TestId");
3232
}
3333

3434
public void AddCheckConstraint()
3535
{
36-
_provider.AddCheckConstraint("CK_TestTwo_TestId", "TestTwo", "TestId>5");
36+
Provider.AddCheckConstraint("CK_TestTwo_TestId", "TestTwo", "TestId>5");
3737
}
3838

3939
[Test]
4040
public void CanAddPrimaryKey()
4141
{
4242
AddPrimaryKey();
43-
Assert.That(_provider.PrimaryKeyExists("Test", "PK_Test"), Is.True);
43+
Assert.That(Provider.PrimaryKeyExists("Test", "PK_Test"), Is.True);
4444
}
4545

4646
[Test]
4747
public void AddIndexedColumn()
4848
{
49-
_provider.AddColumn("TestTwo", "Test", DbType.String, 50, ColumnProperty.Indexed);
49+
Provider.AddColumn("TestTwo", "Test", DbType.String, 50, ColumnProperty.Indexed);
5050
}
5151

5252
[Test]
5353
public void AddUniqueColumn()
5454
{
55-
_provider.AddColumn("TestTwo", "Test", DbType.String, 50, ColumnProperty.Unique);
55+
Provider.AddColumn("TestTwo", "Test", DbType.String, 50, ColumnProperty.Unique);
5656
}
5757

5858
[Test]
5959
public void CanAddForeignKey()
6060
{
6161
AddForeignKey();
62-
Assert.That(_provider.ConstraintExists("TestTwo", "FK_Test_TestTwo"), Is.True);
62+
Assert.That(Provider.ConstraintExists("TestTwo", "FK_Test_TestTwo"), Is.True);
6363
}
6464

6565
[Test]
6666
public virtual void CanAddUniqueConstraint()
6767
{
6868
AddUniqueConstraint();
69-
Assert.That(_provider.ConstraintExists("TestTwo", "UN_Test_TestTwo"), Is.True);
69+
Assert.That(Provider.ConstraintExists("TestTwo", "UN_Test_TestTwo"), Is.True);
7070
}
7171

7272
[Test]
7373
public virtual void CanAddMultipleUniqueConstraint()
7474
{
7575
AddMultipleUniqueConstraint();
76-
Assert.That(_provider.ConstraintExists("TestTwo", "UN_Test_TestTwo"), Is.True);
76+
Assert.That(Provider.ConstraintExists("TestTwo", "UN_Test_TestTwo"), Is.True);
7777
}
7878

7979
[Test]
8080
public virtual void CanAddCheckConstraint()
8181
{
8282
AddCheckConstraint();
83-
Assert.That(_provider.ConstraintExists("TestTwo", "CK_TestTwo_TestId"), Is.True);
83+
Assert.That(Provider.ConstraintExists("TestTwo", "CK_TestTwo_TestId"), Is.True);
8484
}
8585

8686
[Test]
8787
public void RemoveForeignKey()
8888
{
8989
AddForeignKey();
90-
_provider.RemoveForeignKey("TestTwo", "FK_Test_TestTwo");
91-
Assert.That(_provider.ConstraintExists("TestTwo", "FK_Test_TestTwo"), Is.False);
90+
Provider.RemoveForeignKey("TestTwo", "FK_Test_TestTwo");
91+
Assert.That(Provider.ConstraintExists("TestTwo", "FK_Test_TestTwo"), Is.False);
9292
}
9393

9494
[Test]
9595
public void RemoveUniqueConstraint()
9696
{
9797
AddUniqueConstraint();
98-
_provider.RemoveConstraint("TestTwo", "UN_Test_TestTwo");
99-
Assert.That(_provider.ConstraintExists("TestTwo", "UN_Test_TestTwo"), Is.False);
98+
Provider.RemoveConstraint("TestTwo", "UN_Test_TestTwo");
99+
Assert.That(Provider.ConstraintExists("TestTwo", "UN_Test_TestTwo"), Is.False);
100100
}
101101

102102
[Test]
103103
public virtual void RemoveCheckConstraint()
104104
{
105105
AddCheckConstraint();
106-
_provider.RemoveConstraint("TestTwo", "CK_TestTwo_TestId");
107-
Assert.That(_provider.ConstraintExists("TestTwo", "CK_TestTwo_TestId"), Is.False);
106+
Provider.RemoveConstraint("TestTwo", "CK_TestTwo_TestId");
107+
Assert.That(Provider.ConstraintExists("TestTwo", "CK_TestTwo_TestId"), Is.False);
108108
}
109109

110110
[Test]
111111
public void RemoveUnexistingForeignKey()
112112
{
113113
AddForeignKey();
114-
_provider.RemoveForeignKey("abc", "FK_Test_TestTwo");
115-
_provider.RemoveForeignKey("abc", "abc");
116-
_provider.RemoveForeignKey("Test", "abc");
114+
Provider.RemoveForeignKey("abc", "FK_Test_TestTwo");
115+
Provider.RemoveForeignKey("abc", "abc");
116+
Provider.RemoveForeignKey("Test", "abc");
117117
}
118118

119119
[Test]
120120
public void ConstraintExist()
121121
{
122122
AddForeignKey();
123-
Assert.That(_provider.ConstraintExists("TestTwo", "FK_Test_TestTwo"), Is.True);
124-
Assert.That(_provider.ConstraintExists("abc", "abc"), Is.False);
123+
Assert.That(Provider.ConstraintExists("TestTwo", "FK_Test_TestTwo"), Is.True);
124+
Assert.That(Provider.ConstraintExists("abc", "abc"), Is.False);
125125
}
126126

127127
[Test]
128128
public void AddTableWithCompoundPrimaryKey()
129129
{
130-
_provider.AddTable("Test",
130+
Provider.AddTable("Test",
131131
new Column("PersonId", DbType.Int32, ColumnProperty.PrimaryKey),
132132
new Column("AddressId", DbType.Int32, ColumnProperty.PrimaryKey)
133133
);
134134

135-
Assert.That(_provider.TableExists("Test"), Is.True, "Table doesn't exist");
136-
Assert.That(_provider.PrimaryKeyExists("Test", "PK_Test"), Is.True, "Constraint doesn't exist");
135+
Assert.That(Provider.TableExists("Test"), Is.True, "Table doesn't exist");
136+
Assert.That(Provider.PrimaryKeyExists("Test", "PK_Test"), Is.True, "Constraint doesn't exist");
137137
}
138138

139139
[Test]
140140
public void AddTableWithCompoundPrimaryKeyShouldKeepNullForOtherProperties()
141141
{
142-
_provider.AddTable("Test",
142+
Provider.AddTable("Test",
143143
new Column("PersonId", DbType.Int32, ColumnProperty.PrimaryKey),
144144
new Column("AddressId", DbType.Int32, ColumnProperty.PrimaryKey),
145145
new Column("Name", DbType.String, 30, ColumnProperty.Null)
146146
);
147-
Assert.That(_provider.TableExists("Test"), Is.True, "Table doesn't exist");
148-
Assert.That(_provider.PrimaryKeyExists("Test", "PK_Test"), Is.True, "Constraint doesn't exist");
147+
Assert.That(Provider.TableExists("Test"), Is.True, "Table doesn't exist");
148+
Assert.That(Provider.PrimaryKeyExists("Test", "PK_Test"), Is.True, "Constraint doesn't exist");
149149

150-
Column column = _provider.GetColumnByName("Test", "Name");
150+
Column column = Provider.GetColumnByName("Test", "Name");
151151
Assert.That(column, Is.Not.Null);
152152
Assert.That((column.ColumnProperty & ColumnProperty.Null) == ColumnProperty.Null, Is.True);
153153
}
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/MySqlTransformationProviderTest.cs

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,46 +18,45 @@
1818
using Migrator.Providers.Mysql;
1919
using NUnit.Framework;
2020

21-
namespace Migrator.Tests.Providers
21+
namespace Migrator.Tests.Providers;
22+
23+
[TestFixture]
24+
[Category("MySql")]
25+
public class MySqlTransformationProviderTest : TransformationProviderConstraintBase
2226
{
23-
[TestFixture]
24-
[Category("MySql")]
25-
public class MySqlTransformationProviderTest : TransformationProviderConstraintBase
27+
#region Setup/Teardown
28+
29+
[SetUp]
30+
public void SetUp()
31+
{
32+
var constr = ConfigurationManager.AppSettings["MySqlConnectionString"];
33+
if (constr == null)
34+
throw new ArgumentNullException("MySqlConnectionString", "No config file");
35+
Provider = new MySqlTransformationProvider(new MysqlDialect(), constr, "default", null);
36+
// _provider.Logger = new Logger(true, new ConsoleWriter());
37+
38+
AddDefaultTable();
39+
}
40+
41+
[TearDown]
42+
public override void TearDown()
43+
{
44+
DropTestTables();
45+
}
46+
47+
#endregion
48+
49+
// [Test,Ignore("MySql doesn't support check constraints")]
50+
public override void CanAddCheckConstraint()
51+
{
52+
}
53+
54+
[Test]
55+
public void AddTableWithMyISAMEngine()
2656
{
27-
#region Setup/Teardown
28-
29-
[SetUp]
30-
public void SetUp()
31-
{
32-
string constr = ConfigurationManager.AppSettings["MySqlConnectionString"];
33-
if (constr == null)
34-
throw new ArgumentNullException("MySqlConnectionString", "No config file");
35-
_provider = new MySqlTransformationProvider(new MysqlDialect(), constr, "default", null);
36-
// _provider.Logger = new Logger(true, new ConsoleWriter());
37-
38-
AddDefaultTable();
39-
}
40-
41-
[TearDown]
42-
public override void TearDown()
43-
{
44-
DropTestTables();
45-
}
46-
47-
#endregion
48-
49-
// [Test,Ignore("MySql doesn't support check constraints")]
50-
public override void CanAddCheckConstraint()
51-
{
52-
}
53-
54-
[Test]
55-
public void AddTableWithMyISAMEngine()
56-
{
57-
_provider.AddTable("Test", "MyISAM",
58-
new Column("Id", DbType.Int32, ColumnProperty.NotNull),
59-
new Column("name", DbType.String, 50)
60-
);
61-
}
57+
Provider.AddTable("Test", "MyISAM",
58+
new Column("Id", DbType.Int32, ColumnProperty.NotNull),
59+
new Column("name", DbType.String, 50)
60+
);
6261
}
6362
}

0 commit comments

Comments
 (0)