Skip to content

Commit 4b75e5c

Browse files
Ja bist du narrischJa bist du narrisch
authored andcommitted
Refactoring
1 parent a1d1fbb commit 4b75e5c

20 files changed

+163
-99
lines changed

doc/ReleaseNotes.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Release Notes
2+
3+
## 7.0.159 - 7.0.209 (Nuget Version)
4+
### Breaking Changes
5+
+ Minimum SQLite Version: 3.8.2 (2013-12-06)
6+
7+
#### ColumnProperty
8+
+ Removed `ForeignKey` use method `AddForeignKey(...)` instead.
9+
10+
### Other changes
11+
Added `ColumnProperty.Clustered` and `ColumnProperty.NonClustered`

src/Migrator.Tests/Framework/ColumnProperties/ColumnPropertyTests.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
using Migrator.Framework;
22
using NUnit.Framework;
3+
using DotNetProjects.Migrator.Framework;
4+
using System;
5+
using System.Linq;
6+
using System.Diagnostics.CodeAnalysis;
37

48
namespace Migrator.Tests.Framework.ColumnProperties;
59

@@ -9,12 +13,38 @@ public class ColumnPropertyExtensionsTests
913
public void Clear()
1014
{
1115
// Arrange
12-
var columnProperty = ColumnProperty.PrimaryKey | ColumnProperty.Unique;
16+
var columnProperty = ColumnProperty.PrimaryKey | ColumnProperty.NotNull;
1317

1418
// Act
1519
columnProperty = columnProperty.Clear(ColumnProperty.PrimaryKey);
1620

1721
// Assert
1822
Assert.That(columnProperty.HasFlag(ColumnProperty.PrimaryKey), Is.False);
1923
}
24+
25+
[Test]
26+
public void IsSet()
27+
{
28+
// Arrange
29+
var columnProperty = ColumnProperty.PrimaryKey | ColumnProperty.NotNull;
30+
31+
// Act
32+
var isSetInfos = GetAllSingleColumnProperties().Select(x => new
33+
{
34+
ColumnPropertyString = x.ToString(),
35+
IsSet = columnProperty.IsSet(x),
36+
IsNotSet = columnProperty.IsNotSet(x)
37+
}).Where(x => x.ColumnPropertyString != ColumnProperty.None.ToString());
38+
39+
// Assert
40+
string[] expectedSet = [nameof(ColumnProperty.PrimaryKey), nameof(ColumnProperty.NotNull)];
41+
var isSetInfosSet = isSetInfos.Where(x => expectedSet.Any(y => y == x.ColumnPropertyString)).ToList();
42+
43+
Assert.That(isSetInfos.Select(x => x.IsSet), Has.All.True);
44+
}
45+
46+
private ColumnProperty[] GetAllSingleColumnProperties()
47+
{
48+
return [.. Enum.GetValues<ColumnProperty>().Where(x => x == 0 || (x & (x - 1)) == 0)];
49+
}
2050
}

src/Migrator.Tests/Providers/GenericProviderTests.cs

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,39 @@
33
using Migrator.Providers;
44
using NUnit.Framework;
55

6-
namespace Migrator.Tests.Providers
6+
namespace Migrator.Tests.Providers;
7+
8+
[TestFixture]
9+
public class GenericProviderTests
10+
{
11+
[Test]
12+
public void CanJoinColumnsAndValues()
13+
{
14+
var provider = new GenericTransformationProvider();
15+
var result = provider.JoinColumnsAndValues(["foo", "bar"], ["123", "456"]);
16+
17+
Assert.That("foo='123', bar='456'", Is.EqualTo(result));
18+
}
19+
}
20+
21+
internal class GenericTransformationProvider : TransformationProvider
722
{
8-
[TestFixture]
9-
public class GenericProviderTests
23+
public GenericTransformationProvider() : base(null, null as string, null, "default")
24+
{
25+
}
26+
27+
public override bool ConstraintExists(string table, string name)
28+
{
29+
return false;
30+
}
31+
32+
public override List<string> GetDatabases()
1033
{
11-
[Test]
12-
public void CanJoinColumnsAndValues()
13-
{
14-
var provider = new GenericTransformationProvider();
15-
string result = provider.JoinColumnsAndValues(new[] { "foo", "bar" }, new[] { "123", "456" });
16-
17-
Assert.That("foo='123', bar='456'", Is.EqualTo(result));
18-
}
34+
throw new System.NotImplementedException();
1935
}
2036

21-
internal class GenericTransformationProvider : TransformationProvider
37+
public override bool IndexExists(string table, string name)
2238
{
23-
public GenericTransformationProvider() : base(null, null as string, null, "default")
24-
{
25-
}
26-
27-
public override bool ConstraintExists(string table, string name)
28-
{
29-
return false;
30-
}
31-
32-
public override List<string> GetDatabases()
33-
{
34-
throw new System.NotImplementedException();
35-
}
36-
37-
public override bool IndexExists(string table, string name)
38-
{
39-
return false;
40-
}
39+
return false;
4140
}
4241
}

src/Migrator.Tests/Providers/OracleTransformationProviderTest.cs renamed to src/Migrator.Tests/Providers/Oracle/OracleTransformationProviderTest.cs

File renamed without changes.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Migrator.Providers.SqlServer;
2+
using Migrator.Tests.Providers.Base;
3+
using Migrator.Tests.Settings;
4+
using Migrator.Tests.Settings.Config;
5+
using NUnit.Framework;
6+
7+
namespace Migrator.Tests.Providers.SQLServer.Base;
8+
9+
[TestFixture]
10+
[Category("SQLServer")]
11+
public abstract class SQLiteTransformationProviderTestBase : TransformationProviderSimpleBase
12+
{
13+
[SetUp]
14+
public void SetUp()
15+
{
16+
var configReader = new ConfigurationReader();
17+
var connectionString = configReader.GetDatabaseConnectionConfigById(DatabaseConnectionConfigIds.SQLiteConnectionConfigId)
18+
.ConnectionString;
19+
20+
Provider = new SqlServerTransformationProvider(new SqlServerDialect(), connectionString, null, "default", null);
21+
Provider.BeginTransaction();
22+
23+
AddDefaultTable();
24+
}
25+
}

src/Migrator.Tests/Providers/SqlServerTransformationProviderTest.cs renamed to src/Migrator.Tests/Providers/SQLServer/SqlServerTransformationProviderTest.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
using Migrator.Providers.SqlServer;
1919
using NUnit.Framework;
2020

21-
namespace Migrator.Tests.Providers;
21+
namespace Migrator.Tests.Providers.SQLServer;
2222

2323
[TestFixture]
2424
[Category("SqlServer")]
@@ -29,13 +29,7 @@ public class SqlServerTransformationProviderTest : TransformationProviderConstra
2929
[SetUp]
3030
public void SetUp()
3131
{
32-
var constr = ConfigurationManager.AppSettings["SqlServerConnectionString"];
33-
34-
if (constr == null)
35-
{
36-
throw new ArgumentNullException("SqlServerConnectionString", "No config file");
37-
}
38-
32+
var constr = ConfigurationManager.AppSettings["SqlServerConnectionString"] ?? throw new ArgumentNullException("SqlServerConnectionString", "No config file");
3933
Provider = new SqlServerTransformationProvider(new SqlServerDialect(), constr, null, "default", null);
4034
Provider.BeginTransaction();
4135

src/Migrator.Tests/Providers/SqlServer2005TransformationProviderTest.cs renamed to src/Migrator.Tests/Providers/SQLServer2005/SqlServer2005TransformationProviderTest.cs

File renamed without changes.

src/Migrator.Tests/Providers/SqlServerCeTransformationProviderTest.cs renamed to src/Migrator.Tests/Providers/SQLServerCe/SqlServerCeTransformationProviderTest.cs

File renamed without changes.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Migrator.Providers.SQLite;
33
using Migrator.Tests.Providers.Base;
44
using Migrator.Tests.Settings;
5+
using Migrator.Tests.Settings.Config;
56
using NUnit.Framework;
67

78
namespace Migrator.Tests.Providers.SQLite.Base;
@@ -14,7 +15,7 @@ public abstract class SQLiteTransformationProviderTestBase : TransformationProvi
1415
public void SetUp()
1516
{
1617
var configReader = new ConfigurationReader();
17-
var connectionString = configReader.GetDatabaseConnectionConfigById("SQLiteConnectionString")
18+
var connectionString = configReader.GetDatabaseConnectionConfigById(DatabaseConnectionConfigIds.SQLiteConnectionConfigId)
1819
.ConnectionString;
1920

2021
Provider = new SQLiteTransformationProvider(new SQLiteDialect(), connectionString, "default", null);

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

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public void GetColumns_PrimaryAndUnique_ReturnsFalse()
3636

3737
// Assert
3838
Assert.That(columns.Single().ColumnProperty, Is.EqualTo(
39+
ColumnProperty.NotNull |
40+
ColumnProperty.Identity |
3941
ColumnProperty.Unique |
4042
ColumnProperty.PrimaryKey));
4143
}
@@ -52,23 +54,9 @@ public void GetColumns_Primary_ColumnPropertyOk()
5254
var columns = Provider.GetColumns(tableName);
5355

5456
// Assert
55-
Assert.That(columns.Single().ColumnProperty, Is.EqualTo(ColumnProperty.PrimaryKey));
56-
}
57-
58-
[Test]
59-
public void GetColumns_PrimaryKey_ContainsPrimaryKey()
60-
{
61-
// Arrange
62-
const string tableName = "GetColumnsTest";
63-
Provider.AddTable(tableName, new Column("Id", System.Data.DbType.Int32, ColumnProperty.PrimaryKey));
64-
65-
Provider.GetColumns(tableName);
66-
67-
// Act
68-
var columns = Provider.GetColumns(tableName);
69-
70-
// Assert
71-
Assert.That(columns.Single().ColumnProperty, Is.EqualTo(ColumnProperty.PrimaryKey));
57+
Assert.That(columns.Single().ColumnProperty, Is.EqualTo(ColumnProperty.NotNull |
58+
ColumnProperty.Identity |
59+
ColumnProperty.PrimaryKey));
7260
}
7361

7462
[Test]
@@ -88,7 +76,7 @@ public void GetColumns_PrimaryKeyOnTwoColumns_BothColumnsHavePrimaryKeyAndAreNot
8876
var columns = Provider.GetColumns(tableName);
8977

9078
// Assert
91-
Assert.That(columns[0].ColumnProperty, Is.EqualTo(ColumnProperty.PrimaryKey | ColumnProperty.NotNull));
79+
Assert.That(columns[0].ColumnProperty, Is.EqualTo(ColumnProperty.PrimaryKey | ColumnProperty.NotNull | ColumnProperty.Identity));
9280
Assert.That(columns[1].ColumnProperty, Is.EqualTo(ColumnProperty.PrimaryKey | ColumnProperty.NotNull));
9381
}
9482

0 commit comments

Comments
 (0)