Skip to content

Commit 639a97a

Browse files
committed
work on tests with github
1 parent 824f70e commit 639a97a

File tree

11 files changed

+65
-119
lines changed

11 files changed

+65
-119
lines changed

.github/workflows/dotnetpull.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ jobs:
2222
- name: Build
2323
run: |
2424
dotnet build Migrator.slnx
25+
- name: Test
26+
run: |
27+
dotnet test Migrator.slnx

src/Migrator.Tests/Providers/MySQL/MySqlTransformationProviderTest.cs

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,8 @@
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;
15-
using System.Configuration;
161
using System.Data;
172
using Migrator.Framework;
183
using Migrator.Providers.Mysql;
4+
using Migrator.Tests.Settings;
5+
using Migrator.Tests.Settings.Config;
196
using NUnit.Framework;
207

218
namespace Migrator.Tests.Providers.MySQL;
@@ -27,13 +14,16 @@ public class MySqlTransformationProviderTest : TransformationProviderConstraintB
2714
[SetUp]
2815
public void SetUp()
2916
{
30-
var constr = ConfigurationManager.AppSettings["MySqlConnectionString"];
31-
if (constr == null)
17+
var configReader = new ConfigurationReader();
18+
var connectionString = configReader.GetDatabaseConnectionConfigById(DatabaseConnectionConfigIds.MySQL)
19+
?.ConnectionString;
20+
21+
if (string.IsNullOrEmpty(connectionString))
3222
{
33-
throw new ArgumentNullException("MySqlConnectionString", "No config file");
23+
throw new IgnoreException("No MySQL ConnectionString is Set.");
3424
}
3525

36-
Provider = new MySqlTransformationProvider(new MysqlDialect(), constr, "default", null);
26+
Provider = new MySqlTransformationProvider(new MysqlDialect(), connectionString, "default", null);
3727
// _provider.Logger = new Logger(true, new ConsoleWriter());
3828

3929
AddDefaultTable();
@@ -58,4 +48,4 @@ public void AddTableWithMyISAMEngine()
5848
new Column("name", DbType.String, 50)
5949
);
6050
}
61-
}
51+
}

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
using System;
2-
using System.Configuration;
31
using System.Data;
42
using Migrator.Framework;
53
using Migrator.Providers.Oracle;
4+
using Migrator.Tests.Settings;
5+
using Migrator.Tests.Settings.Config;
66
using NUnit.Framework;
77

88
namespace Migrator.Tests.Providers;
@@ -14,13 +14,16 @@ public class OracleTransformationProviderTest : TransformationProviderConstraint
1414
[SetUp]
1515
public void SetUp()
1616
{
17-
var constr = ConfigurationManager.AppSettings["OracleConnectionString"];
18-
if (constr == null)
17+
var configReader = new ConfigurationReader();
18+
var connectionString = configReader.GetDatabaseConnectionConfigById(DatabaseConnectionConfigIds.Oracle)
19+
?.ConnectionString;
20+
21+
if (string.IsNullOrEmpty(connectionString))
1922
{
20-
throw new ArgumentNullException("OracleConnectionString", "No config file");
23+
throw new IgnoreException("No Oracle ConnectionString is Set.");
2124
}
2225

23-
Provider = new OracleTransformationProvider(new OracleDialect(), constr, null, "default", null);
26+
Provider = new OracleTransformationProvider(new OracleDialect(), connectionString, null, "default", null);
2427
Provider.BeginTransaction();
2528

2629
AddDefaultTable();
@@ -35,4 +38,4 @@ public void ChangeColumn_FromNotNullToNotNull()
3538
Provider.ChangeColumn("TestTwo", new Column("TestId", DbType.String, 50, ColumnProperty.NotNull));
3639
Provider.ChangeColumn("TestTwo", new Column("TestId", DbType.String, 50, ColumnProperty.NotNull));
3740
}
38-
}
41+
}

src/Migrator.Tests/Providers/PostgreSQL/PostgreSQLTransformationProviderTest.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using System;
2-
using System.Configuration;
31
using Migrator.Providers;
42
using Migrator.Providers.PostgreSQL;
53
using Migrator.Tests.Settings;
@@ -17,7 +15,12 @@ public void SetUp()
1715
{
1816
var configReader = new ConfigurationReader();
1917
var connectionString = configReader.GetDatabaseConnectionConfigById(DatabaseConnectionConfigIds.PostgreSQL)
20-
.ConnectionString;
18+
?.ConnectionString;
19+
20+
if (string.IsNullOrEmpty(connectionString))
21+
{
22+
throw new IgnoreException("No Postgre ConnectionString is Set.");
23+
}
2124

2225
DbProviderFactories.RegisterFactory("Npgsql", () => Npgsql.NpgsqlFactory.Instance);
2326

@@ -26,4 +29,4 @@ public void SetUp()
2629

2730
AddDefaultTable();
2831
}
29-
}
32+
}

src/Migrator.Tests/Providers/PostgreSQL/PostgreSQLTransformationProviderTestBase.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ public void SetUp()
1616
{
1717
var configReader = new ConfigurationReader();
1818
var connectionString = configReader.GetDatabaseConnectionConfigById(DatabaseConnectionConfigIds.PostgreSQL)
19-
.ConnectionString;
19+
?.ConnectionString;
20+
21+
if (string.IsNullOrEmpty(connectionString))
22+
{
23+
throw new IgnoreException("No Postgre ConnectionString is Set.");
24+
}
2025

2126
DbProviderFactories.RegisterFactory("Npgsql", () => Npgsql.NpgsqlFactory.Instance);
2227

src/Migrator.Tests/Providers/SQLServer/SqlServerTransformationProviderGenericTests.cs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,6 @@
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-
141
using System.Data;
15-
using DotNetProjects.Migrator.Providers.Impl.SQLite;
162
using Migrator.Providers;
17-
using Migrator.Providers.SQLite;
183
using Migrator.Providers.SqlServer;
19-
using Migrator.Tests.Providers.Base;
204
using Migrator.Tests.Settings;
215
using Migrator.Tests.Settings.Config;
226
using NUnit.Framework;
@@ -32,7 +16,12 @@ public void SetUp()
3216
{
3317
var configReader = new ConfigurationReader();
3418
var connectionString = configReader.GetDatabaseConnectionConfigById(DatabaseConnectionConfigIds.SQLServerConnectionConfigId)
35-
.ConnectionString;
19+
.ConnectionString;
20+
21+
if (string.IsNullOrEmpty(connectionString))
22+
{
23+
throw new IgnoreException("No SqlServer ConnectionString is Set.");
24+
}
3625

3726
DbProviderFactories.RegisterFactory("Microsoft.Data.SqlClient", () => Microsoft.Data.SqlClient.SqlClientFactory.Instance);
3827

@@ -84,4 +73,4 @@ public void TableExistsShouldWorkWithTableNamesWithBracket()
8473
{
8574
Assert.That(Provider.TableExists("[TestTwo]"), Is.True);
8675
}
87-
}
76+
}

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

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/Migrator.Tests/Settings/Config/ConnectionIds.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ namespace Migrator.Tests.Settings.Config;
33
public static class DatabaseConnectionConfigIds
44
{
55
public const string Oracle = "Oracle";
6+
public const string MySQL = "MySQL";
67
public const string PostgreSQL = "PostgreSQL";
78
public const string SQLiteConnectionConfigId = "SQLite";
89
public const string SQLServerConnectionConfigId = "SQLServer";
9-
}
10+
}

src/Migrator.Tests/Settings/ConfigurationReader.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public DatabaseConnectionConfig GetDatabaseConnectionConfigById(string id)
2727
var databaseConnectionConfigs = configurationRoot.GetSection("DatabaseConnectionConfigs")
2828
.Get<List<DatabaseConnectionConfig>>() ?? throw new KeyNotFoundException();
2929

30-
return databaseConnectionConfigs.Single(x => x.Id == id);
30+
return databaseConnectionConfigs.SingleOrDefault(x => x.Id == id);
3131
}
3232

3333
/// <summary>
@@ -37,13 +37,18 @@ public DatabaseConnectionConfig GetDatabaseConnectionConfigById(string id)
3737
/// <returns></returns>
3838
public IConfigurationRoot GetConfigurationRoot()
3939
{
40-
var aspNetCoreVariableName = GetAspNetCoreEnvironmentVariable();
4140

42-
return new ConfigurationBuilder()
41+
var builder = new ConfigurationBuilder()
4342
.SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
44-
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: false)
45-
.AddJsonFile($"appsettings.{aspNetCoreVariableName}.json", optional: true, reloadOnChange: false)
46-
.Build();
43+
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: false);
44+
var aspNetCoreVariableName = GetAspNetCoreEnvironmentVariable();
45+
46+
if (!string.IsNullOrEmpty(aspNetCoreVariableName))
47+
{
48+
builder = builder.AddJsonFile($"appsettings.{aspNetCoreVariableName}.json", optional: true, reloadOnChange: false);
49+
}
50+
51+
return builder.Build();
4752
}
4853

4954
private static string GetAspNetCoreEnvironmentVariable()
@@ -59,11 +64,6 @@ private static string GetAspNetCoreEnvironmentVariable()
5964
aspNetCoreVariable = Environment.GetEnvironmentVariable(AspnetCoreVariableString, EnvironmentVariableTarget.Machine);
6065
}
6166

62-
if (string.IsNullOrWhiteSpace(aspNetCoreVariable))
63-
{
64-
throw new Exception($"The environment variable '{AspnetCoreVariableString}' is not set.");
65-
}
66-
6767
return aspNetCoreVariable;
6868
}
69-
}
69+
}

src/Migrator.Tests/app.config

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)