Skip to content

Commit ca81037

Browse files
committed
feature(cop#97): XUnit v3 support
1 parent 70092f7 commit ca81037

File tree

58 files changed

+428
-429
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+428
-429
lines changed

.github/workflows/pipeline.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
jobs:
1010
build:
1111
runs-on: ubuntu-latest
12-
container: mcr.microsoft.com/dotnet/sdk:8.0
12+
container: mcr.microsoft.com/dotnet/sdk:9.0
1313
steps:
1414
- uses: actions/checkout@v2
1515
- name: Restore dependencies

.gitlab-ci.yml

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
include:
2-
- project: 'fusonic/devops/images/gitlab-ci-tools'
3-
file: 'dotnet_test.yml'
4-
ref: '5.10'
2+
- component: $CI_SERVER_FQDN/fusonic/devops/components/dotnet-test/dotnet-test@1.0.0
3+
inputs:
4+
sln-path: Extensions.sln
5+
- component: $CI_SERVER_FQDN/fusonic/devops/components/dotnet-test/dotnet-check-warnings@1.0.0
6+
inputs:
7+
sln-path: Extensions.sln
58
- project: "fusonic/devops/images/gitlab-ci-tools"
69
file: "release_tool.yml"
710
ref: "5.10"
@@ -12,7 +15,7 @@ stages:
1215
- publish
1316

1417
variables:
15-
BUILD_IMAGE: mcr.microsoft.com/dotnet/sdk:8.0
18+
BUILD_IMAGE: mcr.microsoft.com/dotnet/sdk:9.0
1619

1720
default:
1821
interruptible: true
@@ -38,28 +41,14 @@ build:
3841
rules:
3942
- when: always
4043

41-
test:
42-
stage: test
43-
image: ${BUILD_IMAGE}
44-
extends: .dotnet-test
44+
dotnet:test:
4545
services:
46-
- name: postgres:15.4
46+
- name: postgres:17
4747
alias: postgres
4848
variables:
4949
POSTGRES_PASSWORD: admin
50-
BACKEND_SRC_DIR: src/**
51-
SLN_PATH: Extensions.sln
5250
ConnectionStrings__Npgsql: Host=postgres;Database=test_npgsql;Username=postgres;Password=admin
5351
ConnectionStrings__Hangfire: Host=postgres;Database=test_hangfire;Username=postgres;Password=admin
54-
rules:
55-
- when: always
56-
57-
dotnet:check-warnings:
58-
stage: test
59-
extends: .dotnet:check-warnings
60-
image: ${BUILD_IMAGE}
61-
variables:
62-
SLN_PATH: Extensions.sln
6352

6453
release:lint-merge-request:
6554
stage: test

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The project on Github.com is updated on a daily basis, but does not include any
1010
If we see broader community engagement in the future, we may consider switching our primary development to Github.
1111

1212
Fusonic Extensions follows the official yearly .NET release cycle.
13-
Latest Fusonic Extensions main branch targets .NET 8.0.
13+
Latest Fusonic Extensions main branch targets .NET 9.0.
1414

1515

1616
Packages

docs/UnitTests/README.md

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,10 @@ The basic idea behind those is that every test gets its own database copy. This
122122

123123
A test base for your database tests is available called `DatabaseUnitTest`. Type parameters are the test fixture optionally the `DbContext`. Example base classes in your test lib:
124124
```cs
125-
public abstract class TestBase : TestBase<TestFixture>
126-
{
127-
protected TestBase(TestFixture fixture) : base(fixture)
128-
{ }
129-
}
125+
public abstract class TestBase(TestFixture fixture) : TestBase<TestFixture>(fixture);
130126

131-
public abstract class TestBase<TFixture> : DatabaseUnitTest<AppDbContext, TFixture>
132-
where TFixture : TestFixture
133-
{
134-
protected TestBase(TFixture fixture) : base(fixture)
135-
{ }
136-
}
127+
public abstract class TestBase<TFixture>(TFixture fixture) : DatabaseUnitTest<AppDbContext, TFixture>(fixture)
128+
where TFixture : TestFixture;
137129
```
138130

139131
The `DatabaseUnitTest` provides the methods `Query` and `QueryAsync`. This is basically shortcut to resolving the `DbContext` and using it. So instead of writing
@@ -323,8 +315,8 @@ To solve this, you can either throttle your tests, or increase the max. connecti
323315
To increase the max. connections of your postgres test instance, just pass the parameter max_connections. Example for a docker compose file:
324316
```yaml
325317
postgres_test:
326-
image: postgres:14
327-
command: -c max_connections=300
318+
image: postgres:17
319+
command: -c max_connections=500
328320
ports:
329321
- "5433:5432"
330322
volumes:
@@ -339,15 +331,15 @@ postgres_test:
339331
Alternatively, if you want to throttle your tests instead, you can to this easily with a semaphore in your test base:
340332
341333
```cs
342-
public class TestBase : IAsyncLifetime
343-
334+
public class TestBase : IAsyncDisposable
335+
{
344336
private static readonly SemaphoreSlim Throttle = new(64);
345337
public async Task InitializeAsync() => await Throttle.WaitAsync();
346338

347-
public virtual Task DisposeAsync()
339+
public ValueTask DisposeAsync()
348340
{
349341
_ = Throttle.Release();
350-
return Task.CompletedTask;
342+
return ValueTask.CompletedTask;
351343
}
352344
}
353345
```

src/AspNetCore/src/OpenTelemetry/MediatorTracer.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the MIT License. See LICENSE file in the project root for license information.
33

44
using System.Diagnostics;
5-
using OpenTelemetry.Trace;
65

76
namespace Fusonic.Extensions.AspNetCore.OpenTelemetry;
87

@@ -30,7 +29,7 @@ public static async Task<T> TraceRequest<T>(Type handlerType, string displayName
3029
if (activity != null)
3130
{
3231
activity.SetStatus(ActivityStatusCode.Error, ex.Message);
33-
activity.RecordException(ex);
32+
activity.AddException(ex);
3433
}
3534

3635
throw;

src/AspNetCore/test/AspNetCore.Tests.csproj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Razor">
1+
<Project Sdk="Microsoft.NET.Sdk.Razor">
22
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
34
<IsPackable>false</IsPackable>
45
<AssemblyName>Fusonic.Extensions.AspNetCore.Tests</AssemblyName>
56
<RootNamespace>Fusonic.Extensions.AspNetCore.Tests</RootNamespace>
@@ -11,14 +12,17 @@
1112
</ItemGroup>
1213

1314
<ItemGroup>
14-
<PackageReference Include="coverlet.collector">
15+
<PackageReference Include="FluentAssertions" />
16+
<PackageReference Include="FluentAssertions.Analyzers">
1517
<PrivateAssets>all</PrivateAssets>
1618
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1719
</PackageReference>
18-
<PackageReference Include="FluentAssertions" />
20+
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" />
21+
<PackageReference Include="Microsoft.Testing.Extensions.TrxReport" />
1922
<PackageReference Include="NSubstitute" />
2023
<PackageReference Include="Microsoft.NET.Test.Sdk" />
21-
<PackageReference Include="xunit" />
24+
<PackageReference Include="xunit.v3.core" />
25+
<PackageReference Include="xunit.analyzers" />
2226
<PackageReference Include="xunit.runner.visualstudio">
2327
<PrivateAssets>all</PrivateAssets>
2428
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

src/AspNetCore/test/Blazor/BlazorRenderingServiceTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
using System.Globalization;
55
using System.Text.RegularExpressions;
66
using System.Web;
7-
using FluentAssertions;
87
using Fusonic.Extensions.AspNetCore.Blazor;
9-
using Xunit;
108

119
namespace Fusonic.Extensions.AspNetCore.Tests.Blazor;
1210

src/AspNetCore/test/Blazor/TestComponent.razor

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
@using Fusonic.Extensions.AspNetCore.Blazor
2-
@using Fusonic.Extensions.AspNetCore.Razor
32

43
<body>@Model.Name</body>
54

src/AspNetCore/test/Blazor/TestCultureComponent.razor

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
@using Fusonic.Extensions.AspNetCore.Blazor
2-
@using Fusonic.Extensions.AspNetCore.Razor
32

43
<html>
54
<head>

src/AspNetCore/test/Http/CacheHeaderMiddlewareTests.cs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using Fusonic.Extensions.AspNetCore.Http.Middlewares;
55
using Microsoft.AspNetCore.Http;
66
using Microsoft.Net.Http.Headers;
7-
using Xunit;
87

98
namespace Fusonic.Extensions.AspNetCore.Tests.Http;
109

@@ -17,25 +16,25 @@ public async Task SetDefaultHeaderIfNoSpecificRouteIsSet()
1716
var httpContext = new DefaultHttpContext();
1817
var nextCalled = false;
1918

20-
var middleware = new CacheHeaderMiddleware(new RequestDelegate(_ =>
19+
var middleware = new CacheHeaderMiddleware(_ =>
2120
{
2221
nextCalled = true;
2322
return Task.CompletedTask;
24-
}), new CacheHeaderOptions()
23+
}, new CacheHeaderOptions
2524
{
2625
DefaultHeader = defaultHeader
2726
});
2827

2928
await middleware.Invoke(httpContext);
30-
Assert.Equal(defaultHeader, httpContext.Response.GetTypedHeaders().CacheControl);
31-
Assert.True(nextCalled);
29+
httpContext.Response.GetTypedHeaders().CacheControl.Should().Be(defaultHeader);
30+
nextCalled.Should().BeTrue();
3231

3332
// Does not override existing header
3433
nextCalled = false;
35-
var newHeader = new CacheControlHeaderValue { NoCache = false, MaxAge = TimeSpan.FromDays(10) };
34+
3635
await middleware.Invoke(httpContext);
37-
Assert.Equal(defaultHeader, httpContext.Response.GetTypedHeaders().CacheControl);
38-
Assert.True(nextCalled);
36+
httpContext.Response.GetTypedHeaders().CacheControl.Should().Be(defaultHeader);
37+
nextCalled.Should().BeTrue();
3938
}
4039

4140
[Fact]
@@ -56,21 +55,21 @@ public async Task SetRouteHeaderIfRouteMatches()
5655
});
5756

5857
await middleware.Invoke(httpContext);
59-
Assert.Equal(defaultHeader, httpContext.Response.GetTypedHeaders().CacheControl);
60-
Assert.True(nextCalled);
58+
httpContext.Response.GetTypedHeaders().CacheControl.Should().Be(defaultHeader);
59+
nextCalled.Should().BeTrue();
6160

6261
nextCalled = false;
6362
httpContext = new DefaultHttpContext();
6463
httpContext.Request.Path = "/MyFancyRoute/xyz/random";
6564
await middleware.Invoke(httpContext);
66-
Assert.Equal(routeHeader, httpContext.Response.GetTypedHeaders().CacheControl);
67-
Assert.True(nextCalled);
65+
httpContext.Response.GetTypedHeaders().CacheControl.Should().Be(routeHeader);
66+
nextCalled.Should().BeTrue();
6867

6968
// Check route matching ignores case (Ordinal ignore case)
7069
httpContext = new DefaultHttpContext();
7170
httpContext.Request.Path = "/myFancyRoute/xyz/random";
7271
await middleware.Invoke(httpContext);
73-
Assert.Equal(routeHeader, httpContext.Response.GetTypedHeaders().CacheControl);
72+
httpContext.Response.GetTypedHeaders().CacheControl.Should().Be(routeHeader);
7473
}
7574

7675
[Fact]
@@ -80,10 +79,10 @@ public void ConfigureValueForRoutes()
8079
var value = new CacheControlHeaderValue();
8180
options.ConfigureValueForRoutes(value, ["/a", "/b"]);
8281

83-
Assert.Equal(2, options.Routes.Count);
84-
Assert.Equal(options.Routes["/a"], value);
85-
Assert.Equal(options.Routes["/b"], value);
86-
Assert.Null(options.DefaultHeader);
82+
options.Routes.Should().HaveCount(2);
83+
options.Routes["/a"].Should().Be(value);
84+
options.Routes["/b"].Should().Be(value);
85+
options.DefaultHeader.Should().BeNull();
8786
}
8887

8988
[Fact]
@@ -93,9 +92,9 @@ public void ConfigureNoCacheForRoutes()
9392
options.ConfigureNoCacheForRoutes(["/a", "/b"]);
9493

9594
var noCache = new CacheControlHeaderValue { NoStore = true, NoCache = true };
96-
Assert.Equal(2, options.Routes.Count);
97-
Assert.Equal(noCache, options.Routes["/a"]);
98-
Assert.Equal(noCache, options.Routes["/b"]);
99-
Assert.Null(options.DefaultHeader);
95+
options.Routes.Should().HaveCount(2);
96+
options.Routes["/a"].Should().Be(noCache);
97+
options.Routes["/b"].Should().Be(noCache);
98+
options.DefaultHeader.Should().BeNull();
10099
}
101100
}

0 commit comments

Comments
 (0)