Skip to content

Commit 8e76ffc

Browse files
committed
moved away for external dep xunit, added extra tests, ExcludeFromCodeCoverage is removed in smome placed a strat with testing integration test in the action
1 parent 2a131ba commit 8e76ffc

34 files changed

Lines changed: 2267 additions & 511 deletions

.editorconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,17 @@ dotnet_diagnostic.IDE0059.severity = warning
101101
# CA1873: Avoid potentially expensive logging
102102
dotnet_diagnostic.CA1873.severity = warning
103103

104+
# MSTEST0068: Use 'Assert' instead of 'CollectionAssert'
105+
dotnet_diagnostic.MSTEST0068.severity = warning
106+
107+
# MSTEST0037: Use proper 'Assert' methods
108+
dotnet_diagnostic.MSTEST0037.severity = warning
109+
110+
# MSTEST0058: Do not use asserts in catch blocks. The integration tests catch
111+
# everything on purpose so a failure can be reported together with the migrator
112+
# log, and every catch block ends in Assert.Fail, so nothing can pass silently.
113+
dotnet_diagnostic.MSTEST0058.severity = none
114+
104115
[*.vb]
105116
#### Naming styles ####
106117

.github/workflows/BuildRelease.yml

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,27 @@ on:
55
branches: [ '**' ]
66
pull_request:
77
branches: [ '**' ]
8-
8+
99
jobs:
1010
BuildRelease:
1111
name: Release build EasyDBMigrator Package
12-
runs-on: windows-latest
12+
runs-on: ubuntu-latest
1313
timeout-minutes: 15
14-
14+
1515
steps:
1616
- name: Check out the Repository
17-
uses: actions/checkout@v2
18-
19-
- name: Setup .NET Core 8.0.x
20-
uses: actions/setup-dotnet@v1
21-
with:
22-
dotnet-version: 8.0.x
17+
uses: actions/checkout@v5
2318

24-
- name: Setup .NET Core 9.0.x
25-
uses: actions/setup-dotnet@v1
19+
- name: Setup .NET
20+
uses: actions/setup-dotnet@v5
2621
with:
27-
dotnet-version: 9.0.x
22+
dotnet-version: |
23+
8.0.x
24+
9.0.x
25+
10.0.x
2826
29-
- name: Setup .NET Core 10.0.x
30-
uses: actions/setup-dotnet@v1
31-
with:
32-
dotnet-version: 10.0.x
33-
3427
- name: Restore dependencies
3528
run: dotnet restore
36-
29+
3730
- name: Build Release version
3831
run: dotnet build --configuration Release --no-restore

.github/workflows/BuildTestDebug.yml

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,39 @@ on:
55
branches: [ '**' ]
66
pull_request:
77
branches: [ '**' ]
8-
8+
99
jobs:
1010
BuildAndTest:
1111
name: EasyDBMigrator Package
12-
runs-on: windows-latest
13-
timeout-minutes: 15
14-
12+
runs-on: ubuntu-latest
13+
timeout-minutes: 30
14+
1515
steps:
1616
- name: Check out the Repository
17-
uses: actions/checkout@v2
17+
uses: actions/checkout@v5
1818

19-
- name: Setup .NET Core 8.0.x
20-
uses: actions/setup-dotnet@v1
19+
- name: Setup .NET
20+
uses: actions/setup-dotnet@v5
2121
with:
22-
dotnet-version: 8.0.x
22+
dotnet-version: |
23+
8.0.x
24+
9.0.x
25+
10.0.x
2326
24-
- name: Setup .NET Core 9.0.x
25-
uses: actions/setup-dotnet@v1
26-
with:
27-
dotnet-version: 9.0.x
28-
29-
- name: Setup .NET Core 10.0.x
30-
uses: actions/setup-dotnet@v1
31-
with:
32-
dotnet-version: 10.0.x
33-
3427
- name: Restore dependencies
3528
run: dotnet restore
36-
29+
3730
- name: Build debug version all
3831
run: dotnet build --configuration Debug --no-restore
39-
40-
- name: Run unittest with code-coverage
41-
run: dotnet test --no-build --verbosity normal --filter Category!=Integrationtest /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
42-
32+
33+
# Microsoft.Testing.Platform runner, opted in via the "test" section of global.json.
34+
# MTP takes --coverage instead of coverlet.
35+
# The integration tests start their own SQL Server and Postgres containers, which
36+
# is why this job runs on Linux: the Windows runners cannot run Linux containers.
37+
- name: Run all tests with code-coverage
38+
run: dotnet test --no-build --coverage --coverage-output-format cobertura
39+
4340
- name: Upload code coverage to Codecov
44-
uses: codecov/codecov-action@v3
41+
uses: codecov/codecov-action@v5
42+
with:
43+
token: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/PackageAndReleaseMasterToNuGet.yml

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,27 @@ name: Release Master NuGet
33
on:
44
push:
55
branches: [ master ]
6-
6+
77
jobs:
88
Release:
99
name: Release to Nuget
1010
runs-on: ubuntu-latest
1111
timeout-minutes: 10
12-
12+
1313
steps:
1414
- name: Check out Repo
15-
uses: actions/checkout@v2
15+
uses: actions/checkout@v5
1616

17-
- name: Setup .NET Core 8.0.x
18-
uses: actions/setup-dotnet@v1
17+
- name: Setup .NET
18+
uses: actions/setup-dotnet@v5
1919
with:
20-
dotnet-version: 8.0.x
20+
dotnet-version: |
21+
8.0.x
22+
9.0.x
23+
10.0.x
2124
22-
- name: Setup .NET Core 9.0.x
23-
uses: actions/setup-dotnet@v1
24-
with:
25-
dotnet-version: 9.0.x
26-
27-
- name: Setup .NET Core 10.0.x
28-
uses: actions/setup-dotnet@v1
29-
with:
30-
dotnet-version: 10.0.x
31-
3225
- name: Pack
33-
run: dotnet pack EasyDbMigrator\\EasyDbMigrator.csproj -c Release
34-
35-
- name: Publish to Nuget
36-
run: dotnet nuget push /home/runner/work/EasyDbMigrator/EasyDbMigrator/EasyDbMigrator/bin/Release/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
26+
run: dotnet pack EasyDbMigrator/EasyDbMigrator.csproj -c Release -o ./artifacts
3727

28+
- name: Publish to Nuget
29+
run: dotnet nuget push ./artifacts/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate

.vscode/settings.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
"cSpell.words": [
33
"accessibilities",
44
"buildtransitive",
5+
"cobertura",
56
"contentfiles",
67
"datname",
78
"Integrationtest",
89
"msbuild",
10+
"mstest",
911
"netcoreapp",
1012
"Npgsql",
11-
"Retrodad",
12-
"xunit"
13+
"Parallelize",
14+
"Retrodad"
1315
]
14-
}
16+
}

EasyDbMigrator/AssemblyResourceHelper.cs

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Diagnostics.CodeAnalysis;
43
using System.IO;
54
using System.Reflection;
65
using System.Text;
@@ -11,7 +10,6 @@ namespace EasyDbMigrator;
1110
/// <summary>
1211
/// Helps to get script files embedded in an assembly
1312
/// </summary>
14-
[ExcludeFromCodeCoverage] //is tested with integrationTest
1513
public sealed class AssemblyResourceHelper : IAssemblyResourceHelper
1614
{
1715
/// <summary>
@@ -22,21 +20,16 @@ public sealed class AssemblyResourceHelper : IAssemblyResourceHelper
2220
/// <exception cref="InvalidOperationException"></exception>
2321
public async Task<List<Script>> TryGetScriptsFromAssembly(Type typeOfClassWhereScriptsAreLocated)
2422
{
25-
Assembly? assembly = Assembly.GetAssembly(typeOfClassWhereScriptsAreLocated);
23+
ArgumentNullException.ThrowIfNull(argument: typeOfClassWhereScriptsAreLocated);
2624

27-
string[] filenames = TryGetManifestResourceNamesFromAssembly(typeOfClassWhereScriptsAreLocated);
25+
Assembly assembly = typeOfClassWhereScriptsAreLocated.Assembly;
26+
string[] filenames = assembly.GetManifestResourceNames();
2827

2928
List<Script> scripts = new(filenames.Length);
3029
foreach (string filename in filenames)
3130
{
32-
await using Stream? stream = assembly?.GetManifestResourceStream(filename);
33-
if (stream is null)
34-
{
35-
throw new InvalidOperationException(new StringBuilder()
36-
.Append("steam cannot be null for resource name: ")
37-
.Append(filename)
38-
.ToString());
39-
}
31+
await using Stream stream = assembly.GetManifestResourceStream(filename)
32+
?? throw new InvalidOperationException(new StringBuilder().Append("stream cannot be null for resource name: ").Append(filename).ToString());
4033

4134
using StreamReader reader = new(stream);
4235
string filenameWithNoNamespaces = RemoveTheNamespaceFromName(filename);
@@ -49,21 +42,6 @@ public async Task<List<Script>> TryGetScriptsFromAssembly(Type typeOfClassWhereS
4942
return scripts;
5043
}
5144

52-
private static string[] TryGetManifestResourceNamesFromAssembly(Type typeOfClassWhereScriptsAreLocated)
53-
{
54-
Assembly? assembly = Assembly.GetAssembly(typeOfClassWhereScriptsAreLocated);
55-
56-
if (assembly is null)
57-
{
58-
throw new InvalidOperationException(new StringBuilder().Append("assembly is null for custom-class: ")
59-
.Append(typeOfClassWhereScriptsAreLocated)
60-
.ToString());
61-
}
62-
63-
string[] resourceNames = assembly.GetManifestResourceNames();
64-
return resourceNames;
65-
}
66-
6745
private static string RemoveTheNamespaceFromName(string filename)
6846
{
6947
string[] split = filename.Split(".");

EasyDbMigrator/DatabaseConnectors/MicrosoftSqlConnector.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using Polly;
66
using System;
77
using System.Data;
8-
using System.Diagnostics.CodeAnalysis;
98
using System.Threading;
109
using System.Threading.Tasks;
1110

@@ -14,7 +13,6 @@ namespace EasyDbMigrator.DatabaseConnectors;
1413
/// <summary>
1514
/// MicrosoftSqlConnector
1615
/// </summary>
17-
[ExcludeFromCodeCoverage] //is tested with integrationTest that will not be included in code coverage
1816
public sealed class MicrosoftSqlConnector : IDatabaseConnector
1917
{
2018
private readonly AsyncPolicy _sqlDatabasePolicy = Policy.Handle<Exception>()
@@ -41,7 +39,6 @@ ALTER DATABASE {migrationConfiguration.DatabaseName}
4139
";
4240

4341
var result = await TryExecuteSingleScriptAsync(connectionString: migrationConfiguration.ConnectionString
44-
, scriptName: "EasyDbMigrator.Integrationtest_dropDatabase"
4542
, sqlScriptContent: query
4643
, cancellationToken: cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
4744

@@ -70,7 +67,6 @@ Version nvarchar(10) NOT NULL
7067
END";
7168

7269
var result = await TryExecuteSingleScriptAsync(connectionString: migrationConfiguration.ConnectionString
73-
, scriptName: "EasyDbMigrator.SetupDbMigrationsRunTable"
7470
, sqlScriptContent: sqlScriptCreateMigrationTable
7571
, cancellationToken: cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
7672

@@ -93,7 +89,6 @@ CREATE DATABASE {migrationConfiguration.DatabaseName}
9389
END";
9490

9591
var result = await TryExecuteSingleScriptAsync(connectionString: migrationConfiguration.ConnectionString
96-
, scriptName: "SetupEmptyDb"
9792
, sqlScriptContent: sqlScriptCreateDatabase
9893
, cancellationToken: cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
9994

@@ -192,7 +187,6 @@ INSERT INTO DbMigrationsRun (Executed, Filename, version)
192187
}
193188
}
194189
private async Task<Result<bool>> TryExecuteSingleScriptAsync(string connectionString
195-
, string scriptName
196190
, string sqlScriptContent
197191
, CancellationToken cancellationToken)
198192
{
@@ -203,11 +197,6 @@ private async Task<Result<bool>> TryExecuteSingleScriptAsync(string connectionSt
203197

204198
try
205199
{
206-
if (string.IsNullOrWhiteSpace(value: sqlScriptContent))
207-
{
208-
throw new ArgumentException(message: $"{scriptName} script is empty, is there something wrong?");
209-
}
210-
211200
await _sqlDatabasePolicy.ExecuteAsync(action: async () =>
212201
{
213202
await using SqlConnection connection = new(connectionString: connectionString);

0 commit comments

Comments
 (0)