Skip to content

Commit 4a71ce8

Browse files
committed
Migrate xunit v2 to xunit v3 and fix cache test
- Replace xunit 2.9.3 with xunit.v3 3.2.2 - Remove xunit.runner.visualstudio (built into xunit v3) - Remove Microsoft.NET.Test.Sdk (not needed for xunit v3) - Remove XunitXml.TestLogger (version conflict with xunit v3) - Add OutputType Exe (required by xunit v3) - Update coverlet.collector to 8.0.0 - Fix GetPage_Returns_From_Cache_If_Available test: use Arg.Any<object?>() for IMemoryCache.TryGetValue out parameter - Fix xUnit1051 warnings: pass TestContext.Current.CancellationToken - Remove redundant using directives
1 parent 425c324 commit 4a71ce8

5 files changed

Lines changed: 61 additions & 22 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# .NET 10.0 Upgrade Report
2+
3+
## Project target framework modifications
4+
5+
| Project name | Old Target Framework | New Target Framework | Commits |
6+
|:-----------------------------------------------------------|:--------------------:|:--------------------:|:-------------------------------|
7+
| Dove.Blog.Abstractions\Dove.Blog.Abstractions.csproj | net9.0 | net10.0 | 1f25e5bb |
8+
| Dove.Blog.Data\Dove.Blog.Data.csproj | net9.0 | net10.0 | 5b8e68d4 |
9+
| Dove.Blog.Logic\Dove.Blog.Logic.csproj | net9.0 | net10.0 | 763d9cc4 |
10+
| Dove.Blog.WebApp\Dove.Blog.WebApp.csproj | net9.0 | net10.0 | 875103d3 |
11+
| Dove.Blog.Tests\Dove.Blog.Tests.csproj | net9.0 | net10.0 | e10d10b0 |
12+
13+
## NuGet Packages
14+
15+
| Package Name | Old Version | New Version | Commit Id |
16+
|:-------------------------------|:-----------:|:-----------:|:----------|
17+
| Microsoft.AspNetCore.OpenApi | 9.0.4 | 10.0.3 | a53595ae |
18+
19+
## All commits
20+
21+
| Commit ID | Description |
22+
|:----------|:----------------------------------------------------------------------------------------------------|
23+
| ef72b588 | Commit upgrade plan |
24+
| 1f25e5bb | Update Dove.Blog.Abstractions.csproj to net10.0 |
25+
| 5b8e68d4 | Update Dove.Blog.Data.csproj to target net10.0 |
26+
| d5589d05 | Fix IWebHostEnvironment using directive in FileDataProvider.cs |
27+
| a477e420 | Update IWebHostEnvironment using directive for .NET 10.0 |
28+
| faf75b51 | Store final changes for step 'Upgrade Dove.Blog.Data\Dove.Blog.Data.csproj' |
29+
| dc846eb6 | Update IWebHostEnvironment using directive for .NET 10.0 |
30+
| 3cceae52 | Fix IWebHostEnvironment using directive in FileDataProvider.cs |
31+
| 763d9cc4 | Update Dove.Blog.Logic.csproj to target net10.0 |
32+
| 875103d3 | Update Dove.Blog.WebApp.csproj to target .NET 10.0 |
33+
| a53595ae | Update OpenApi package version in Dove.Blog.WebApp.csproj |
34+
| 425c3242 | InitialUpgrade already complete. No feature upgrades needed. Running validation. |
35+
| e10d10b0 | Update Dove.Blog.Tests.csproj to target net10.0 |
36+
37+
## Project feature upgrades
38+
39+
### Dove.Blog.Data
40+
41+
- Replaced `Microsoft.AspNetCore.Hosting.Abstractions` NuGet package (v2.3.0) with a `FrameworkReference` to `Microsoft.AspNetCore.App` to resolve `IWebHostEnvironment` availability on .NET 10.0.
42+
- Updated using directives in `FileDataProvider.cs` to reference the correct namespace for `IWebHostEnvironment`.
43+
44+
## Next steps
45+
46+
- Consider migrating the `xunit` package (v2.9.3) to xUnit.net v3, as v2 is deprecated and will only receive security updates. See: https://xunit.net/docs/getting-started/v3/migration

Source/Dove.Blog.Tests/BlogProviderTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
using Microsoft.Extensions.Caching.Memory;
66
using Microsoft.Extensions.Logging;
77
using NSubstitute;
8-
using System;
9-
using Xunit;
108

119
namespace Dove.Blog.Tests;
1210

Source/Dove.Blog.Tests/Dove.Blog.Tests.csproj

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>net10.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<IsPackable>false</IsPackable>
8+
<OutputType>Exe</OutputType>
89
</PropertyGroup>
910

1011
<ItemGroup>
11-
<PackageReference Include="coverlet.collector" Version="6.0.4">
12+
<PackageReference Include="coverlet.collector" Version="8.0.0">
1213
<PrivateAssets>all</PrivateAssets>
1314
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1415
</PackageReference>
15-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
1616
<PackageReference Include="TestableIO.System.IO.Abstractions.TestingHelpers" Version="22.0.14" />
17-
<PackageReference Include="xunit" Version="2.9.3" />
18-
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
19-
<PrivateAssets>all</PrivateAssets>
20-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
21-
</PackageReference>
17+
<PackageReference Include="xunit.v3" Version="3.2.2" />
2218
<PackageReference Include="FluentAssertions" Version="7.2.0" />
2319
<PackageReference Include="NSubstitute" Version="5.3.0" />
24-
<PackageReference Include="XunitXml.TestLogger" Version="6.1.0" />
2520
</ItemGroup>
2621

2722
<ItemGroup>

Source/Dove.Blog.Tests/FileDataProviderTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using Dove.Blog.Data;
33
using Microsoft.AspNetCore.Hosting;
44
using NSubstitute;
5-
using Xunit;
65
using FluentAssertions;
76
using System.IO.Abstractions;
87
using System.IO.Abstractions.TestingHelpers;
@@ -69,7 +68,7 @@ public async Task ReadPageContent_ReturnsContent_WhenFileExists()
6968
_fileSystem.Directory.CreateDirectory(dataDir);
7069
var filePath = _fileSystem.Path.Combine(dataDir, "mypage.md");
7170
var expected = "Hello, world!";
72-
await _fileSystem.File.WriteAllTextAsync(filePath, expected, Encoding.UTF8);
71+
await _fileSystem.File.WriteAllTextAsync(filePath, expected, Encoding.UTF8, TestContext.Current.CancellationToken);
7372

7473
var content = await _provider.ReadPageContent("mypage");
7574

@@ -93,7 +92,7 @@ public async Task WritePageContent_CreatesFileWithContent()
9392

9493
var filePath = _fileSystem.Path.Combine(dataDir, "newpage.md");
9594
_fileSystem.File.Exists(filePath).Should().BeTrue();
96-
var content = await _fileSystem.File.ReadAllTextAsync(filePath);
95+
var content = await _fileSystem.File.ReadAllTextAsync(filePath, TestContext.Current.CancellationToken);
9796
content.Should().Be("test content");
9897
}
9998

Source/Dove.Blog.Tests/PageDataProviderTests.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,26 +50,27 @@ public async Task GetPage_Throws_ArgumentNullException_When_PageName_Is_Null()
5050
public async Task GetPage_Returns_From_Cache_If_Available()
5151
{
5252
var fileProvider = Substitute.For<IDataProvider>();
53-
var memoryCache = Substitute.For<IMemoryCache>();
5453
var cachedPage = new Page
5554
{
5655
Title = "Cached",
5756
Author = "Author",
5857
Created = DateTimeOffset.UtcNow
5958
};
60-
object outObj = cachedPage;
61-
memoryCache.TryGetValue("Page/Index", out outObj).Returns(x =>
62-
{
63-
x[1] = cachedPage;
64-
return true;
65-
});
59+
60+
var memoryCache = Substitute.For<IMemoryCache>();
61+
memoryCache.TryGetValue(Arg.Is<object>("Page/Index"), out Arg.Any<object?>())
62+
.Returns(ci =>
63+
{
64+
ci[1] = cachedPage;
65+
return true;
66+
});
6667

6768
var provider = new PageDataProvider(fileProvider, memoryCache);
6869

6970
var page = await provider.GetPage("Index");
7071

7172
page.Should().BeSameAs(cachedPage);
72-
fileProvider.DidNotReceive().ReadPageContent(Arg.Any<string>());
73+
await fileProvider.DidNotReceive().ReadPageContent(Arg.Any<string>());
7374
}
7475

7576
[Fact]

0 commit comments

Comments
 (0)