Skip to content

Commit 605fda2

Browse files
Ja bist du narrischJa bist du narrisch
authored andcommitted
Sql server - start to make the sql server run
1 parent e17d8f3 commit 605fda2

File tree

6 files changed

+100
-20
lines changed

6 files changed

+100
-20
lines changed

src/Migrator.Tests/Migrator.Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9+
<PackageReference Include="Microsoft.Data.SqlClient" Version="6.1.0" />
10+
<PackageReference Include="System.Data.SqlClient" Version="4.9.0" />
911
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.119" />
1012
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.5" />
1113
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.5" />

src/Migrator.Tests/Providers/SQLServer/Base/SQLServerTestBase.cs renamed to src/Migrator.Tests/Providers/SQLServer/Base/SQLServerTransformationProviderTestBase.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.Data.SqlClient;
2+
using Migrator.Providers;
13
using Migrator.Providers.SqlServer;
24
using Migrator.Tests.Providers.Base;
35
using Migrator.Tests.Settings;
@@ -8,7 +10,7 @@ namespace Migrator.Tests.Providers.SQLServer.Base;
810

911
[TestFixture]
1012
[Category("SQLServer")]
11-
public abstract class SQLiteTransformationProviderTestBase : TransformationProviderSimpleBase
13+
public abstract class SQLServerTransformationProviderTestBase : TransformationProviderSimpleBase
1214
{
1315
[SetUp]
1416
public void SetUp()
@@ -17,6 +19,8 @@ public void SetUp()
1719
var connectionString = configReader.GetDatabaseConnectionConfigById(DatabaseConnectionConfigIds.SQLiteConnectionConfigId)
1820
.ConnectionString;
1921

22+
DbProviderFactories.RegisterFactory("Microsoft.Data.SqlClient", () => Microsoft.Data.SqlClient.SqlClientFactory.Instance);
23+
2024
Provider = new SqlServerTransformationProvider(new SqlServerDialect(), connectionString, null, "default", null);
2125
Provider.BeginTransaction();
2226

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#region License
2+
3+
//The contents of this file are subject to the Mozilla Public License
4+
//Version 1.1 (the "License"); you may not use this file except in
5+
//compliance with the License. You may obtain a copy of the License at
6+
//http://www.mozilla.org/MPL/
7+
//Software distributed under the License is distributed on an "AS IS"
8+
//basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
9+
//License for the specific language governing rights and limitations
10+
//under the License.
11+
12+
#endregion
13+
14+
using System.Data;
15+
using DotNetProjects.Migrator.Providers.Impl.SQLite;
16+
using Migrator.Providers;
17+
using Migrator.Providers.SQLite;
18+
using Migrator.Providers.SqlServer;
19+
using Migrator.Tests.Providers.Base;
20+
using Migrator.Tests.Settings;
21+
using Migrator.Tests.Settings.Config;
22+
using NUnit.Framework;
23+
24+
namespace Migrator.Tests.Providers.SQLServer;
25+
26+
[TestFixture]
27+
[Category("SqlServer")]
28+
public class SqlServerTransformationProviderGenericTests : TransformationProviderConstraintBase
29+
{
30+
[SetUp]
31+
public void SetUp()
32+
{
33+
var configReader = new ConfigurationReader();
34+
var connectionString = configReader.GetDatabaseConnectionConfigById(DatabaseConnectionConfigIds.SQLServerConnectionConfigId)
35+
.ConnectionString;
36+
37+
DbProviderFactories.RegisterFactory("Microsoft.Data.SqlClient", () => Microsoft.Data.SqlClient.SqlClientFactory.Instance);
38+
39+
Provider = new SqlServerTransformationProvider(new SqlServerDialect(), connectionString, "dbo", "default", "Microsoft.Data.SqlClient");
40+
Provider.BeginTransaction();
41+
42+
AddDefaultTable();
43+
}
44+
45+
[Test]
46+
public void ByteColumnWillBeCreatedAsBlob()
47+
{
48+
Provider.AddColumn("TestTwo", "BlobColumn", DbType.Byte);
49+
Assert.That(Provider.ColumnExists("TestTwo", "BlobColumn"), Is.True);
50+
}
51+
52+
[Test]
53+
public void InstanceForProvider()
54+
{
55+
var localProv = Provider["sqlserver"];
56+
Assert.That(localProv is SqlServerTransformationProvider, Is.True);
57+
58+
var localProv2 = Provider["foo"];
59+
Assert.That(localProv2 is NoOpTransformationProvider, Is.True);
60+
}
61+
62+
[Test]
63+
public void QuoteCreatesProperFormat()
64+
{
65+
var dialect = new SqlServerDialect();
66+
67+
Assert.That("[foo]", Is.EqualTo(dialect.Quote("foo")));
68+
}
69+
70+
[Test]
71+
public void TableExistsShouldWorkWithBracketsAndSchemaNameAndTableName()
72+
{
73+
Assert.That(Provider.TableExists("[dbo].[TestTwo]"), Is.True);
74+
}
75+
76+
[Test]
77+
public void TableExistsShouldWorkWithSchemaNameAndTableName()
78+
{
79+
Assert.That(Provider.TableExists("dbo.TestTwo"), Is.True);
80+
}
81+
82+
[Test]
83+
public void TableExistsShouldWorkWithTableNamesWithBracket()
84+
{
85+
Assert.That(Provider.TableExists("[TestTwo]"), Is.True);
86+
}
87+
}

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

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,15 @@
1616
using System.Data;
1717
using Migrator.Providers;
1818
using Migrator.Providers.SqlServer;
19+
using Migrator.Tests.Providers.SQLServer.Base;
1920
using NUnit.Framework;
2021

2122
namespace Migrator.Tests.Providers.SQLServer;
2223

2324
[TestFixture]
2425
[Category("SqlServer")]
25-
public class SqlServerTransformationProviderTest : TransformationProviderConstraintBase
26+
public class SqlServerTransformationProviderTests : SQLServerTransformationProviderTestBase
2627
{
27-
#region Setup/Teardown
28-
29-
[SetUp]
30-
public void SetUp()
31-
{
32-
var constr = ConfigurationManager.AppSettings["SqlServerConnectionString"] ?? throw new ArgumentNullException("SqlServerConnectionString", "No config file");
33-
Provider = new SqlServerTransformationProvider(new SqlServerDialect(), constr, null, "default", null);
34-
Provider.BeginTransaction();
35-
36-
AddDefaultTable();
37-
}
38-
39-
#endregion
40-
4128
[Test]
4229
public void ByteColumnWillBeCreatedAsBlob()
4330
{

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ namespace Migrator.Tests.Providers;
2222
[Category("SqlServer2005")]
2323
public class SqlServer2005TransformationProviderTest : TransformationProviderConstraintBase
2424
{
25-
#region Setup/Teardown
26-
2725
[SetUp]
2826
public void SetUp()
2927
{
@@ -38,6 +36,4 @@ public void SetUp()
3836

3937
AddDefaultTable();
4038
}
41-
42-
#endregion
4339
}

src/Migrator/Providers/Impl/SqlServer/SqlServerTransformationProvider.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using System;
1717
using System.Collections.Generic;
1818
using System.Data;
19+
using System.Data.Common;
1920
using System.Globalization;
2021
using Index = Migrator.Framework.Index;
2122

@@ -41,7 +42,10 @@ public SqlServerTransformationProvider(Dialect dialect, IDbConnection connection
4142
protected virtual void CreateConnection(string providerName)
4243
{
4344
if (string.IsNullOrEmpty(providerName))
45+
{
4446
providerName = "System.Data.SqlClient";
47+
}
48+
4549
var fac = DbProviderFactoriesHelper.GetFactory(providerName, null, null);
4650
_connection = fac.CreateConnection(); // new SqlConnection();
4751
_connection.ConnectionString = _connectionString;

0 commit comments

Comments
 (0)