Skip to content

Commit 9fcef58

Browse files
authored
Merge pull request #798 from leancodepl/task/use-microsoft-testing-platform
Fully move onto Microsoft Testing Platform v2
2 parents 12929eb + 8715444 commit 9fcef58

18 files changed

Lines changed: 102 additions & 48 deletions

File tree

.config/dotnet-tools.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"rollForward": false
1111
},
1212
"dotnet-coverage": {
13-
"version": "17.13.1",
13+
"version": "18.1.0",
1414
"commands": [
1515
"dotnet-coverage"
1616
],

.github/workflows/core_build_publish.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,12 @@ jobs:
136136
run: |
137137
dotnet restore
138138
dotnet tool restore
139+
- name: Build
140+
run: dotnet build --configuration Release --no-restore
139141
- name: Unit tests
140-
run: dotnet test -- --explicit on --filter-not-trait 'integration=true'
142+
run: dotnet test --no-build --configuration Release -- --explicit on --filter-not-trait 'integration=true'
141143
- name: Azure Test
142-
run: dotnet test -- --explicit on --filter-trait 'service=azure'
144+
run: dotnet test --no-build --configuration Release -- --explicit on --filter-trait 'service=azure'
143145
env:
144146
CORELIB_TESTS_TENANT_ID: ${{ secrets.CORELIB_TESTS_TENANT_ID }}
145147
CORELIB_TESTS_CLIENT_ID: ${{ secrets.CORELIB_TESTS_CLIENT_ID }}
@@ -150,12 +152,12 @@ jobs:
150152
CORELIB_TESTS_AZURE_BLOB_STORAGE_CONTAINER_NAME: ${{ secrets.CORELIB_TESTS_AZURE_BLOB_STORAGE_CONTAINER_NAME }}
151153
CORELIB_TESTS_AZURE_TABLE_STORAGE_TABLE_NAME: ${{ secrets.CORELIB_TESTS_AZURE_TABLE_STORAGE_TABLE_NAME }}
152154
- name: Integration Test - SQL Server
153-
run: dotnet test -- --explicit on --filter-query '/[(category=integration)&(database!=postgres)]'
155+
run: dotnet test --no-build --configuration Release -- --explicit on --filter-query '/[(category=integration)&(database!=postgres)]'
154156
env:
155157
SqlServer__ConnectionStringBase: Server=localhost,1433;User Id=sa;Password=Passw12#;Encrypt=false
156158
LeanCodeIntegrationTests__Database: sqlserver
157159
- name: Integration Test - Postgres
158-
run: dotnet test -- --explicit on --filter-trait 'category=integration'
160+
run: dotnet test --no-build --configuration Release -- --explicit on --filter-trait 'category=integration'
159161
env:
160162
Postgres__ConnectionStringBase: Host=localhost;Username=postgres;Password=Passw12#
161163
LeanCodeIntegrationTests__Database: postgres
@@ -174,7 +176,8 @@ jobs:
174176
if: always()
175177
with:
176178
token: ${{ secrets.CODECOV_TOKEN }}
177-
working-directory: ./TestResults
179+
files: ./TestResults/cobertura.xml
180+
fail_ci_if_error: false
178181
- name: Upload test report
179182
if: always()
180183
run: |

Directory.Packages.props

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,14 @@
119119
</ItemGroup>
120120

121121
<ItemGroup>
122+
<!-- Do not update to v8, as it changed license that is mostly unusable for us -->
122123
<PackageVersion Include="FluentAssertions" Version="7.2.0" />
123-
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
124-
<PackageVersion Include="Microsoft.Testing.Platform" Version="1.9.0" />
125-
<PackageVersion Include="Microsoft.Testing.Extensions.CodeCoverage" Version="17.14.2" />
126124
<PackageVersion Include="NSubstitute" Version="5.3.0" />
127-
<PackageVersion Include="xunit.v3" Version="1.1.0" />
125+
<PackageVersion Include="Microsoft.Testing.Extensions.CodeCoverage" Version="18.1.0" />
128126
<PackageVersion Include="xunit.analyzers" Version="1.25.0" />
127+
<PackageVersion Include="xunit.v3.assert" Version="3.2.0" />
128+
<PackageVersion Include="xunit.v3.extensibility.core" Version="3.2.0" />
129+
<PackageVersion Include="xunit.v3.mtp-v2" Version="3.2.0" />
129130

130131
<PackageVersion Include="Microsoft.NETCore.App.Ref" Version="$(DomainModelsTestsNetCoreAppRefVersion)" />
131132
</ItemGroup>

global.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
"version": "10.0.100",
44
"allowPrerelease": false,
55
"rollForward": "latestMinor"
6+
},
7+
"test": {
8+
"runner": "Microsoft.Testing.Platform"
69
}
710
}

test/Directory.Build.props

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,29 @@
11
<Project>
2+
<Import
3+
Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))"
4+
Condition="Exists($([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../')))"
5+
/>
6+
27
<PropertyGroup>
38
<IsPackable>false</IsPackable>
49
<NoWarn>CA1812</NoWarn>
10+
<OutputType>Exe</OutputType>
511
</PropertyGroup>
612

713
<PropertyGroup>
814
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
915
<UseMicrosoftTestingPlatformRunner>true</UseMicrosoftTestingPlatformRunner>
10-
<!--
11-
The first three parameters must be here in this file on a single line, otherwise the cmdline parsing will fail.
12-
-->
13-
<TestingPlatformCommandLineArguments>
14-
$(TestingPlatformCommandLineArguments)
15-
--report-ctrf --coverage --ignore-exit-code 8
16-
--results-directory $(MSBuildThisFileDirectory)/../TestResults
17-
--coverage-output-format cobertura
18-
--coverage-settings $(MSBuildThisFileDirectory)/coverage.xml
19-
--report-ctrf-filename $(MSBuildProjectName)-$([System.DateTime]::Now.ToString("HH-mm-ss")).json
20-
--coverage-output $(MSBuildProjectName)-$([System.DateTime]::Now.ToString("HH-mm-ss")).xml
21-
</TestingPlatformCommandLineArguments>
16+
<!-- All arguments must be on a single line to avoid parsing issues with newlines -->
17+
<!-- csharpier-ignore -->
18+
<TestingPlatformCommandLineArguments>$(TestingPlatformCommandLineArguments) --report-ctrf --coverage --ignore-exit-code 8 --results-directory $(MSBuildThisFileDirectory)/../TestResults --coverage-output-format cobertura --coverage-settings $(MSBuildThisFileDirectory)/coverage.xml --report-ctrf-filename $(MSBuildProjectName)-$([System.DateTime]::Now.ToString("HH-mm-ss")).json --coverage-output $(MSBuildProjectName)-$([System.DateTime]::Now.ToString("HH-mm-ss")).xml</TestingPlatformCommandLineArguments>
2219
</PropertyGroup>
2320

2421
<ItemGroup>
2522
<PackageReference Include="FluentAssertions" />
26-
27-
<PackageReference Include="NSubstitute" />
28-
<PackageReference Include="Microsoft.Testing.Platform" />
2923
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" />
30-
<PackageReference Include="Microsoft.NET.Test.Sdk" />
24+
<PackageReference Include="NSubstitute" />
3125

32-
<PackageReference Include="xunit.v3" />
3326
<PackageReference Include="xunit.analyzers" />
27+
<PackageReference Include="xunit.v3.mtp-v2" />
3428
</ItemGroup>
35-
36-
<Import
37-
Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))"
38-
Condition="Exists($([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../')))"
39-
/>
4029
</Project>

test/Infrastructure/LeanCode.Azure.Tests/AzureStorageAuditLogIntegrationTests.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Runtime.CompilerServices;
12
using System.Text.Json;
23
using Azure.Data.Tables;
34
using Azure.Storage.Blobs;
@@ -166,7 +167,10 @@ await storage.StoreEventAsync(
166167
}
167168
}
168169

169-
public sealed class AzureStorageFactAttribute : ExternalServiceFactAttribute
170+
public sealed class AzureStorageFactAttribute(
171+
[CallerFilePath] string sourceFilePath = null,
172+
[CallerLineNumber] int sourceLineNumber = 0
173+
) : ExternalServiceFactAttribute(sourceFilePath, sourceLineNumber)
170174
{
171175
protected override string ServiceType => "azure";
172176
protected override IReadOnlyCollection<string> RequiredEnvVariables { get; } =

test/Infrastructure/LeanCode.Azure.Tests/PostgresAD/NpgsqlActiveDirectoryAuthenticationTests.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using FluentAssertions;
1+
using System.Runtime.CompilerServices;
2+
using FluentAssertions;
23
using LeanCode.Npgsql.ActiveDirectory;
34
using LeanCode.Test.Helpers;
45
using Npgsql;
@@ -25,7 +26,10 @@ public async Task Authentication_works()
2526
}
2627
}
2728

28-
public sealed class PostgresFactAttribute : ExternalServiceFactAttribute
29+
public sealed class PostgresFactAttribute(
30+
[CallerFilePath] string sourceFilePath = null,
31+
[CallerLineNumber] int sourceLineNumber = 0
32+
) : ExternalServiceFactAttribute(sourceFilePath, sourceLineNumber)
2933
{
3034
protected override string ServiceType => "npgsql";
3135
protected override IReadOnlyCollection<string> RequiredEnvVariables { get; } =

test/Infrastructure/LeanCode.AzureIdentity.Tests/AzureIdentityFact.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Runtime.CompilerServices;
12
using LeanCode.Test.Helpers;
23

34
namespace LeanCode.AzureIdentity.Tests;
@@ -7,7 +8,12 @@ public sealed class AzureIdentityFact : ExternalServiceFactAttribute
78
protected override string ServiceType => "azure-identity";
89
protected override IReadOnlyCollection<string> RequiredEnvVariables { get; }
910

10-
public AzureIdentityFact(params string[] requiredEnvVariables)
11+
public AzureIdentityFact(
12+
string[] requiredEnvVariables,
13+
[CallerFilePath] string? sourceFilePath = null,
14+
[CallerLineNumber] int sourceLineNumber = 0
15+
)
16+
: base(sourceFilePath, sourceLineNumber)
1117
{
1218
RequiredEnvVariables = requiredEnvVariables.ToHashSet();
1319
}

test/Infrastructure/LeanCode.AzureIdentity.Tests/DefaultLeanCodeCredentialsTests.Authorization.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ namespace LeanCode.AzureIdentity.Tests;
55

66
public class DefaultLeanCodeCredentialsTests_Authorization
77
{
8-
[AzureIdentityFact("Azure__UseAzureCLI")]
8+
[AzureIdentityFact(["Azure__UseAzureCLI"])]
99
public async Task Authorizes_via_cli()
1010
{
1111
var cred = DefaultLeanCodeCredential.Create(new AzureCredentialConfiguration { UseAzureCLI = true });
1212

1313
await AssertGetsTokenAsync(cred);
1414
}
1515

16-
[AzureIdentityFact("Azure__TenantId", "Azure__ClientId", "Azure__ClientSecret")]
16+
[AzureIdentityFact(["Azure__TenantId", "Azure__ClientId", "Azure__ClientSecret"])]
1717
public async Task Authorizes_using_service_principal_secret()
1818
{
1919
var config = new AzureCredentialConfiguration
@@ -29,7 +29,7 @@ public async Task Authorizes_using_service_principal_secret()
2929
}
3030

3131
// this one won't be of much use unless we run tests on Azure VM
32-
[AzureIdentityFact("Azure__UseManagedIdentity")]
32+
[AzureIdentityFact(["Azure__UseManagedIdentity"])]
3333
public async Task Authorizes_via_managed_identity()
3434
{
3535
var cred = DefaultLeanCodeCredential.Create(new AzureCredentialConfiguration { UseManagedIdentity = true });

test/Infrastructure/LeanCode.Firebase.FCM.Tests/FCMFact.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
using System.Runtime.CompilerServices;
12
using LeanCode.Test.Helpers;
23

34
namespace LeanCode.Firebase.FCM.Tests;
45

5-
public sealed class FCMFactAttribute : ExternalServiceFactAttribute
6+
public sealed class FCMFactAttribute(
7+
[CallerFilePath] string? sourceFilePath = null,
8+
[CallerLineNumber] int sourceLineNumber = 0
9+
) : ExternalServiceFactAttribute(sourceFilePath, sourceLineNumber)
610
{
711
protected override string ServiceType => "fcm";
812
protected override IReadOnlyCollection<string> RequiredEnvVariables { get; } = ["FCM_KEY", "FCM_TOKEN"];

0 commit comments

Comments
 (0)