Skip to content

Commit bb2a49d

Browse files
authored
feat: add support for .NET 5 (#672)
Resolves #633
1 parent d5f052a commit bb2a49d

20 files changed

Lines changed: 169 additions & 42 deletions

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "C# (.NET Core)",
3-
"image": "mcr.microsoft.com/vscode/devcontainers/dotnetcore:3.1",
3+
"image": "mcr.microsoft.com/vscode/devcontainers/dotnet:5.0",
44
"settings": {
55
"terminal.integrated.shell.linux": "/bin/bash"
66
},

.github/workflows/ci.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,18 @@ jobs:
1717
uses: actions/checkout@v2
1818
with:
1919
fetch-depth: 0
20+
- name: Setup .NET Core 2.1
21+
uses: actions/setup-dotnet@v1
22+
with:
23+
dotnet-version: "2.1.x"
24+
- name: Setup .NET Core 3.1
25+
uses: actions/setup-dotnet@v1
26+
with:
27+
dotnet-version: "3.1.x"
28+
- name: Setup .NET
29+
uses: actions/setup-dotnet@v1
2030
- name: Run tests
21-
run: dotnet test --collect:"XPlat Code Coverage"
31+
run: dotnet test --collect:"XPlat Code Coverage" --logger "GitHubActions"
2232
- name: Upload coverage
2333
uses: actions/upload-artifact@v2
2434
with:
@@ -31,6 +41,8 @@ jobs:
3141
steps:
3242
- name: Checkout sources
3343
uses: actions/checkout@v2
44+
- name: Setup .NET
45+
uses: actions/setup-dotnet@v1
3446
- uses: actions/download-artifact@v2
3547
with:
3648
name: Code coverage ubuntu-latest
@@ -64,6 +76,8 @@ jobs:
6476
uses: actions/checkout@v2
6577
with:
6678
fetch-depth: 0
79+
- name: Setup .NET
80+
uses: actions/setup-dotnet@v1
6781
- name: Create packages
6882
run: dotnet pack --configuration Release --output ./packages
6983
- name: Upload a Build Artifact
@@ -81,6 +95,8 @@ jobs:
8195
uses: actions/checkout@v2
8296
with:
8397
fetch-depth: 0
98+
- name: Setup .NET
99+
uses: actions/setup-dotnet@v1
84100
- uses: actions/download-artifact@v2
85101
with:
86102
name: NuGet packages

Directory.Build.props

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)StrongName.snk</AssemblyOriginatorKeyFile>
88
<IncludeSymbols>true</IncludeSymbols>
99
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
10-
<LangVersion>8.0</LangVersion>
11-
<DefineConstants Condition="'$(TargetFramework)' == 'netcoreapp3.0' OR '$(TargetFramework)' == 'netstandard2.1'">$(DefineConstants);FEATURE_ASYNC_FILE;FEATURE_ENUMERATION_OPTIONS;FEATURE_ADVANCED_PATH_OPERATIONS</DefineConstants>
10+
<LangVersion>9.0</LangVersion>
11+
<PackageTags>testing</PackageTags>
12+
<PackageProjectUrl>https://github.com/System-IO-Abstractions/System.IO.Abstractions</PackageProjectUrl>
13+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
14+
<DefineConstants Condition="'$(TargetFramework)' == 'net5.0' OR '$(TargetFramework)' == 'netcoreapp3.1' OR '$(TargetFramework)' == 'netstandard2.1'">$(DefineConstants);FEATURE_ASYNC_FILE;FEATURE_ENUMERATION_OPTIONS;FEATURE_ADVANCED_PATH_OPERATIONSFEATURE_PATH_JOIN_WITH_SPAN</DefineConstants>
1215
</PropertyGroup>
1316
<ItemGroup>
1417
<PackageReference Include="Nerdbank.GitVersioning" Version="3.3.37">

benchmarks/System.IO.Abstractions.Benchmarks/System.IO.Abstractions.Benchmarks.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<AssemblyName>System.IO.Abstractions.Benchmarks</AssemblyName>
44
<RootNamespace>System.IO.Abstractions.Benchmarks</RootNamespace>
55
<Description>Bencharmks comparisons.</Description>
6-
<TargetFrameworks>netcoreapp3.1;net461</TargetFrameworks>
6+
<TargetFrameworks>net5.0;netcoreapp3.1;net461</TargetFrameworks>
77
<PackageProjectUrl>https://github.com/System-IO-Abstractions/System.IO.Abstractions</PackageProjectUrl>
88
<PackageLicenseExpression>MIT</PackageLicenseExpression>
99
<PackageTags>testing</PackageTags>

global.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "3.1.300",
4-
"rollForward": "latestMinor"
3+
"version": "5.0.100",
4+
"rollForward": "latestFeature"
55
}
66
}

src/System.IO.Abstractions.TestingHelpers/MockFile.cs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,14 @@ public MockFile(IMockFileDataAccessor mockFileDataAccessor) : base(mockFileDataA
2020

2121
public override void AppendAllLines(string path, IEnumerable<string> contents)
2222
{
23-
mockFileDataAccessor.PathVerifier.IsLegalAbsoluteOrRelative(path, "path");
24-
VerifyValueIsNotNull(contents, "contents");
25-
2623
AppendAllLines(path, contents, MockFileData.DefaultEncoding);
2724
}
2825

2926
public override void AppendAllLines(string path, IEnumerable<string> contents, Encoding encoding)
3027
{
31-
if (encoding == null)
32-
{
33-
throw new ArgumentNullException(nameof(encoding));
34-
}
35-
3628
mockFileDataAccessor.PathVerifier.IsLegalAbsoluteOrRelative(path, "path");
29+
VerifyValueIsNotNull(contents, nameof(contents));
30+
VerifyValueIsNotNull(encoding, nameof(encoding));
3731

3832
var concatContents = contents.Aggregate("", (a, b) => a + b + Environment.NewLine);
3933
AppendAllText(path, concatContents, encoding);
@@ -492,20 +486,18 @@ public override string[] ReadAllLines(string path, Encoding encoding)
492486

493487
public override string ReadAllText(string path)
494488
{
495-
mockFileDataAccessor.PathVerifier.IsLegalAbsoluteOrRelative(path, "path");
496-
497-
if (!mockFileDataAccessor.FileExists(path))
498-
{
499-
throw CommonExceptions.FileNotFound(path);
500-
}
501-
502489
return ReadAllText(path, MockFileData.DefaultEncoding);
503490
}
504491

505492
public override string ReadAllText(string path, Encoding encoding)
506493
{
507494
mockFileDataAccessor.PathVerifier.IsLegalAbsoluteOrRelative(path, "path");
508495

496+
if (!mockFileDataAccessor.FileExists(path))
497+
{
498+
throw CommonExceptions.FileNotFound(path);
499+
}
500+
509501
if (encoding == null)
510502
{
511503
throw new ArgumentNullException(nameof(encoding));

src/System.IO.Abstractions.TestingHelpers/System.IO.Abstractions.TestingHelpers.csproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
<AssemblyName>System.IO.Abstractions.TestingHelpers</AssemblyName>
44
<RootNamespace>System.IO.Abstractions.TestingHelpers</RootNamespace>
55
<Description>A set of pre-built mocks to help when testing file system interactions.</Description>
6-
<TargetFrameworks>netstandard2.1;netstandard2.0;net461</TargetFrameworks>
7-
<PackageProjectUrl>https://github.com/System-IO-Abstractions/System.IO.Abstractions</PackageProjectUrl>
8-
<PackageLicenseExpression>MIT</PackageLicenseExpression>
9-
<PackageTags>testing</PackageTags>
6+
<TargetFrameworks>net5.0;netstandard2.1;netstandard2.0;net461</TargetFrameworks>
107
</PropertyGroup>
118
<ItemGroup>
129
<ProjectReference Include="../System.IO.Abstractions/System.IO.Abstractions.csproj" />

src/System.IO.Abstractions/System.IO.Abstractions.csproj

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
<AssemblyName>System.IO.Abstractions</AssemblyName>
44
<RootNamespace>System.IO.Abstractions</RootNamespace>
55
<Description>A set of abstractions to help make file system interactions testable.</Description>
6-
<TargetFrameworks>netstandard2.1;netstandard2.0;net461</TargetFrameworks>
7-
<PackageProjectUrl>https://github.com/System-IO-Abstractions/System.IO.Abstractions</PackageProjectUrl>
8-
<PackageLicenseExpression>MIT</PackageLicenseExpression>
9-
<PackageTags>testing</PackageTags>
10-
<DefineConstants Condition="'$(TargetFramework)' == 'netstandard2.1'">$(DefineConstants);FEATURE_ASYNC_FILE;FEATURE_ENUMERATION_OPTIONS;FEATURE_ADVANCED_PATH_OPERATIONS;FEATURE_PATH_JOIN_WITH_SPAN</DefineConstants>
6+
<TargetFrameworks>net5.0;netstandard2.1;netstandard2.0;net461</TargetFrameworks>
117
</PropertyGroup>
12-
<ItemGroup Condition="'$(TargetFramework)' != 'net461'">
8+
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1' OR '$(TargetFramework)' == 'netstandard2.0'">
139
<PackageReference Include="System.IO.FileSystem.AccessControl" Version="4.7.0"/>
1410
</ItemGroup>
11+
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
12+
<PackageReference Include="System.IO.FileSystem.AccessControl" Version="5.0.0"/>
13+
</ItemGroup>
1514
<ItemGroup>
1615
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies.net461" Version="1.0.0">
1716
<PrivateAssets>all</PrivateAssets>

tests/System.IO.Abstractions.TestingHelpers.Tests/MockFileReadAllLinesTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ public void MockFile_ReadAllLinesAsync_NotExistingFile_ThrowsCorrectFileNotFound
148148
var absentFileNameFullPath = XFS.Path(@"c:\you surely don't have such file.hope-so");
149149
var mockFileSystem = new MockFileSystem();
150150

151-
var act = new AsyncTestDelegate(() =>
152-
mockFileSystem.File.ReadAllTextAsync(absentFileNameFullPath)
151+
var act = new AsyncTestDelegate(async() =>
152+
await mockFileSystem.File.ReadAllTextAsync(absentFileNameFullPath)
153153
);
154154

155155
var exception = Assert.CatchAsync<FileNotFoundException>(act);

tests/System.IO.Abstractions.TestingHelpers.Tests/System.IO.Abstractions.TestingHelpers.Tests.csproj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>netcoreapp3.1;netcoreapp2.1</TargetFrameworks>
3+
<TargetFrameworks>net5.0;netcoreapp3.1;netcoreapp2.1</TargetFrameworks>
44
<TargetFrameworks Condition="!$([MSBuild]::IsOsUnixLike())">$(TargetFrameworks);net461</TargetFrameworks>
55
<Description>The unit tests for our pre-built mocks</Description>
66
<AssemblyName>System.IO.Abstractions.TestingHelpers.Tests</AssemblyName>
77
<RootNamespace>System.IO.Abstractions.TestingHelpers.Tests</RootNamespace>
88
<IsPackable>false</IsPackable>
99
<IsTestable>true</IsTestable>
1010
</PropertyGroup>
11+
<PropertyGroup>
12+
<!--
13+
Ensure that test logger is copied to output directory, see
14+
https://github.com/Tyrrrz/GitHubActionsTestLogger/issues/5
15+
-->
16+
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
17+
</PropertyGroup>
1118
<ItemGroup>
1219
<None Remove="TestFiles\SecondTestFile.txt" />
1320
<None Remove="TestFiles\TestFile.txt" />
@@ -25,6 +32,7 @@
2532
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2633
<PrivateAssets>all</PrivateAssets>
2734
</PackageReference>
35+
<PackageReference Include="GitHubActionsTestLogger" Version="1.1.2" />
2836
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
2937
<PackageReference Include="Moq" Version="4.14.5" />
3038
<PackageReference Include="nunit" Version="3.12.0" />

0 commit comments

Comments
 (0)