Skip to content

Commit

Permalink
feat: add support for .NET 5 (#672)
Browse files Browse the repository at this point in the history
Resolves #633
  • Loading branch information
fgreinacher committed Nov 21, 2020
1 parent d5f052a commit bb2a49d
Show file tree
Hide file tree
Showing 20 changed files with 169 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
@@ -1,6 +1,6 @@
{
"name": "C# (.NET Core)",
"image": "mcr.microsoft.com/vscode/devcontainers/dotnetcore:3.1",
"image": "mcr.microsoft.com/vscode/devcontainers/dotnet:5.0",
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
},
Expand Down
18 changes: 17 additions & 1 deletion .github/workflows/ci.yml
Expand Up @@ -17,8 +17,18 @@ jobs:
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup .NET Core 2.1
uses: actions/setup-dotnet@v1
with:
dotnet-version: "2.1.x"
- name: Setup .NET Core 3.1
uses: actions/setup-dotnet@v1
with:
dotnet-version: "3.1.x"
- name: Setup .NET
uses: actions/setup-dotnet@v1
- name: Run tests
run: dotnet test --collect:"XPlat Code Coverage"
run: dotnet test --collect:"XPlat Code Coverage" --logger "GitHubActions"
- name: Upload coverage
uses: actions/upload-artifact@v2
with:
Expand All @@ -31,6 +41,8 @@ jobs:
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v1
- uses: actions/download-artifact@v2
with:
name: Code coverage ubuntu-latest
Expand Down Expand Up @@ -64,6 +76,8 @@ jobs:
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v1
- name: Create packages
run: dotnet pack --configuration Release --output ./packages
- name: Upload a Build Artifact
Expand All @@ -81,6 +95,8 @@ jobs:
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v1
- uses: actions/download-artifact@v2
with:
name: NuGet packages
Expand Down
7 changes: 5 additions & 2 deletions Directory.Build.props
Expand Up @@ -7,8 +7,11 @@
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)StrongName.snk</AssemblyOriginatorKeyFile>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<LangVersion>8.0</LangVersion>
<DefineConstants Condition="'$(TargetFramework)' == 'netcoreapp3.0' OR '$(TargetFramework)' == 'netstandard2.1'">$(DefineConstants);FEATURE_ASYNC_FILE;FEATURE_ENUMERATION_OPTIONS;FEATURE_ADVANCED_PATH_OPERATIONS</DefineConstants>
<LangVersion>9.0</LangVersion>
<PackageTags>testing</PackageTags>
<PackageProjectUrl>https://github.com/System-IO-Abstractions/System.IO.Abstractions</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<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>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" Version="3.3.37">
Expand Down
Expand Up @@ -3,7 +3,7 @@
<AssemblyName>System.IO.Abstractions.Benchmarks</AssemblyName>
<RootNamespace>System.IO.Abstractions.Benchmarks</RootNamespace>
<Description>Bencharmks comparisons.</Description>
<TargetFrameworks>netcoreapp3.1;net461</TargetFrameworks>
<TargetFrameworks>net5.0;netcoreapp3.1;net461</TargetFrameworks>
<PackageProjectUrl>https://github.com/System-IO-Abstractions/System.IO.Abstractions</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageTags>testing</PackageTags>
Expand Down
4 changes: 2 additions & 2 deletions global.json
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "3.1.300",
"rollForward": "latestMinor"
"version": "5.0.100",
"rollForward": "latestFeature"
}
}
22 changes: 7 additions & 15 deletions src/System.IO.Abstractions.TestingHelpers/MockFile.cs
Expand Up @@ -20,20 +20,14 @@ public MockFile(IMockFileDataAccessor mockFileDataAccessor) : base(mockFileDataA

public override void AppendAllLines(string path, IEnumerable<string> contents)
{
mockFileDataAccessor.PathVerifier.IsLegalAbsoluteOrRelative(path, "path");
VerifyValueIsNotNull(contents, "contents");

AppendAllLines(path, contents, MockFileData.DefaultEncoding);
}

public override void AppendAllLines(string path, IEnumerable<string> contents, Encoding encoding)
{
if (encoding == null)
{
throw new ArgumentNullException(nameof(encoding));
}

mockFileDataAccessor.PathVerifier.IsLegalAbsoluteOrRelative(path, "path");
VerifyValueIsNotNull(contents, nameof(contents));
VerifyValueIsNotNull(encoding, nameof(encoding));

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

public override string ReadAllText(string path)
{
mockFileDataAccessor.PathVerifier.IsLegalAbsoluteOrRelative(path, "path");

if (!mockFileDataAccessor.FileExists(path))
{
throw CommonExceptions.FileNotFound(path);
}

return ReadAllText(path, MockFileData.DefaultEncoding);
}

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

if (!mockFileDataAccessor.FileExists(path))
{
throw CommonExceptions.FileNotFound(path);
}

if (encoding == null)
{
throw new ArgumentNullException(nameof(encoding));
Expand Down
Expand Up @@ -3,10 +3,7 @@
<AssemblyName>System.IO.Abstractions.TestingHelpers</AssemblyName>
<RootNamespace>System.IO.Abstractions.TestingHelpers</RootNamespace>
<Description>A set of pre-built mocks to help when testing file system interactions.</Description>
<TargetFrameworks>netstandard2.1;netstandard2.0;net461</TargetFrameworks>
<PackageProjectUrl>https://github.com/System-IO-Abstractions/System.IO.Abstractions</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageTags>testing</PackageTags>
<TargetFrameworks>net5.0;netstandard2.1;netstandard2.0;net461</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../System.IO.Abstractions/System.IO.Abstractions.csproj" />
Expand Down
11 changes: 5 additions & 6 deletions src/System.IO.Abstractions/System.IO.Abstractions.csproj
Expand Up @@ -3,15 +3,14 @@
<AssemblyName>System.IO.Abstractions</AssemblyName>
<RootNamespace>System.IO.Abstractions</RootNamespace>
<Description>A set of abstractions to help make file system interactions testable.</Description>
<TargetFrameworks>netstandard2.1;netstandard2.0;net461</TargetFrameworks>
<PackageProjectUrl>https://github.com/System-IO-Abstractions/System.IO.Abstractions</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageTags>testing</PackageTags>
<DefineConstants Condition="'$(TargetFramework)' == 'netstandard2.1'">$(DefineConstants);FEATURE_ASYNC_FILE;FEATURE_ENUMERATION_OPTIONS;FEATURE_ADVANCED_PATH_OPERATIONS;FEATURE_PATH_JOIN_WITH_SPAN</DefineConstants>
<TargetFrameworks>net5.0;netstandard2.1;netstandard2.0;net461</TargetFrameworks>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'net461'">
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1' OR '$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.IO.FileSystem.AccessControl" Version="4.7.0"/>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
<PackageReference Include="System.IO.FileSystem.AccessControl" Version="5.0.0"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies.net461" Version="1.0.0">
<PrivateAssets>all</PrivateAssets>
Expand Down
Expand Up @@ -148,8 +148,8 @@ public void MockFile_ReadAllLinesAsync_NotExistingFile_ThrowsCorrectFileNotFound
var absentFileNameFullPath = XFS.Path(@"c:\you surely don't have such file.hope-so");
var mockFileSystem = new MockFileSystem();

var act = new AsyncTestDelegate(() =>
mockFileSystem.File.ReadAllTextAsync(absentFileNameFullPath)
var act = new AsyncTestDelegate(async() =>
await mockFileSystem.File.ReadAllTextAsync(absentFileNameFullPath)
);

var exception = Assert.CatchAsync<FileNotFoundException>(act);
Expand Down
@@ -1,13 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;netcoreapp2.1</TargetFrameworks>
<TargetFrameworks>net5.0;netcoreapp3.1;netcoreapp2.1</TargetFrameworks>
<TargetFrameworks Condition="!$([MSBuild]::IsOsUnixLike())">$(TargetFrameworks);net461</TargetFrameworks>
<Description>The unit tests for our pre-built mocks</Description>
<AssemblyName>System.IO.Abstractions.TestingHelpers.Tests</AssemblyName>
<RootNamespace>System.IO.Abstractions.TestingHelpers.Tests</RootNamespace>
<IsPackable>false</IsPackable>
<IsTestable>true</IsTestable>
</PropertyGroup>
<PropertyGroup>
<!--
Ensure that test logger is copied to output directory, see
https://github.com/Tyrrrz/GitHubActionsTestLogger/issues/5
-->
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<None Remove="TestFiles\SecondTestFile.txt" />
<None Remove="TestFiles\TestFile.txt" />
Expand All @@ -25,6 +32,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="GitHubActionsTestLogger" Version="1.1.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="Moq" Version="4.14.5" />
<PackageReference Include="nunit" Version="3.12.0" />
Expand Down
7 changes: 4 additions & 3 deletions tests/System.IO.Abstractions.Tests/ApiParityTests.cs
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using NUnit.Framework;
using Snapshooter;
using Snapshooter.NUnit;
Expand Down Expand Up @@ -92,9 +91,11 @@ public ApiDiff(IEnumerable<string> extraMembers, IEnumerable<string> missingMemb
#if NETCOREAPP3_1
private const string snapshotSuffix = ".NET Core 3.1";
#elif NETCOREAPP2_1
private const string snapshotSuffix = ".NET Core 2.1";
private const string snapshotSuffix = ".NET Core 2.1";
#elif NET461
private const string snapshotSuffix = ".NET Framework 4.6.1";
private const string snapshotSuffix = ".NET Framework 4.6.1";
#elif NET5_0
private const string snapshotSuffix = ".NET 5.0";
#else
#error Unknown target framework.
#endif
Expand Down
@@ -1,13 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;netcoreapp2.1</TargetFrameworks>
<TargetFrameworks>net5.0;netcoreapp3.1;netcoreapp2.1</TargetFrameworks>
<TargetFrameworks Condition="!$([MSBuild]::IsOsUnixLike())">$(TargetFrameworks);net461</TargetFrameworks>
<Description>The unit tests for our the core abstractions</Description>
<AssemblyName>System.IO.Abstractions.Tests</AssemblyName>
<RootNamespace>System.IO.Abstractions.Tests</RootNamespace>
<IsPackable>false</IsPackable>
<IsTestable>true</IsTestable>
</PropertyGroup>
<PropertyGroup>
<!--
Ensure that test logger is copied to output directory, see
https://github.com/Tyrrrz/GitHubActionsTestLogger/issues/5
-->
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../../src/System.IO.Abstractions/System.IO.Abstractions.csproj" />
</ItemGroup>
Expand All @@ -16,6 +23,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="GitHubActionsTestLogger" Version="1.1.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="Moq" Version="4.14.5" />
<PackageReference Include="nunit" Version="3.12.0" />
Expand Down
@@ -0,0 +1,14 @@
{
"ExtraMembers": [
"System.Security.AccessControl.DirectorySecurity GetAccessControl()",
"System.Security.AccessControl.DirectorySecurity GetAccessControl(System.Security.AccessControl.AccessControlSections)",
"Void Create(System.Security.AccessControl.DirectorySecurity)",
"Void SetAccessControl(System.Security.AccessControl.DirectorySecurity)"
],
"MissingMembers": [
"System.Object GetLifetimeService()",
"System.Object InitializeLifetimeService()",
"Void .ctor(System.String)",
"Void GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)"
]
}
@@ -0,0 +1,12 @@
{
"ExtraMembers": [
"System.IO.Abstractions.IDirectoryInfo CreateDirectory(System.String, System.Security.AccessControl.DirectorySecurity)",
"System.Security.AccessControl.DirectorySecurity GetAccessControl(System.String)",
"System.Security.AccessControl.DirectorySecurity GetAccessControl(System.String, System.Security.AccessControl.AccessControlSections)",
"Void SetAccessControl(System.String, System.Security.AccessControl.DirectorySecurity)"
],
"MissingMembers": [
"System.String[] GetFileSystemEntries(System.String, System.String, System.IO.EnumerationOptions)",
"System.String[] GetFileSystemEntries(System.String, System.String, System.IO.SearchOption)"
]
}
@@ -0,0 +1,7 @@
{
"ExtraMembers": [],
"MissingMembers": [
"System.IO.Abstractions.IDriveInfo[] GetDrives()",
"Void .ctor(System.String)"
]
}
@@ -0,0 +1,14 @@
{
"ExtraMembers": [
"System.Security.AccessControl.FileSecurity GetAccessControl()",
"System.Security.AccessControl.FileSecurity GetAccessControl(System.Security.AccessControl.AccessControlSections)",
"Void SetAccessControl(System.Security.AccessControl.FileSecurity)"
],
"MissingMembers": [
"System.Object GetLifetimeService()",
"System.Object InitializeLifetimeService()",
"Void .ctor(System.String)",
"Void GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)",
"Void MoveTo(System.String, Boolean)"
]
}
@@ -0,0 +1,12 @@
{
"ExtraMembers": [
"System.Security.AccessControl.FileSecurity GetAccessControl(System.String)",
"System.Security.AccessControl.FileSecurity GetAccessControl(System.String, System.Security.AccessControl.AccessControlSections)",
"System.Threading.Tasks.Task WriteAllLinesAsync(System.String, System.String[], System.Text.Encoding, System.Threading.CancellationToken)",
"System.Threading.Tasks.Task WriteAllLinesAsync(System.String, System.String[], System.Threading.CancellationToken)",
"Void SetAccessControl(System.String, System.Security.AccessControl.FileSecurity)"
],
"MissingMembers": [
"Void Move(System.String, System.String, Boolean)"
]
}
@@ -0,0 +1,35 @@
{
"ExtraMembers": [
"Char get_AltDirectorySeparatorChar()",
"Char get_DirectorySeparatorChar()",
"Char get_PathSeparator()",
"Char get_VolumeSeparatorChar()",
"Char[] get_InvalidPathChars()"
],
"MissingMembers": [
"Boolean EndsInDirectorySeparator(System.ReadOnlySpan`1[System.Char])",
"Boolean EndsInDirectorySeparator(System.String)",
"Boolean HasExtension(System.ReadOnlySpan`1[System.Char])",
"Boolean IsPathFullyQualified(System.ReadOnlySpan`1[System.Char])",
"Boolean IsPathFullyQualified(System.String)",
"Boolean IsPathRooted(System.ReadOnlySpan`1[System.Char])",
"Boolean TryJoin(System.ReadOnlySpan`1[System.Char], System.ReadOnlySpan`1[System.Char], System.ReadOnlySpan`1[System.Char], System.Span`1[System.Char], Int32 ByRef)",
"Boolean TryJoin(System.ReadOnlySpan`1[System.Char], System.ReadOnlySpan`1[System.Char], System.Span`1[System.Char], Int32 ByRef)",
"System.ReadOnlySpan`1[System.Char] GetDirectoryName(System.ReadOnlySpan`1[System.Char])",
"System.ReadOnlySpan`1[System.Char] GetExtension(System.ReadOnlySpan`1[System.Char])",
"System.ReadOnlySpan`1[System.Char] GetFileName(System.ReadOnlySpan`1[System.Char])",
"System.ReadOnlySpan`1[System.Char] GetFileNameWithoutExtension(System.ReadOnlySpan`1[System.Char])",
"System.ReadOnlySpan`1[System.Char] GetPathRoot(System.ReadOnlySpan`1[System.Char])",
"System.ReadOnlySpan`1[System.Char] TrimEndingDirectorySeparator(System.ReadOnlySpan`1[System.Char])",
"System.String GetFullPath(System.String, System.String)",
"System.String GetRelativePath(System.String, System.String)",
"System.String Join(System.ReadOnlySpan`1[System.Char], System.ReadOnlySpan`1[System.Char])",
"System.String Join(System.ReadOnlySpan`1[System.Char], System.ReadOnlySpan`1[System.Char], System.ReadOnlySpan`1[System.Char])",
"System.String Join(System.ReadOnlySpan`1[System.Char], System.ReadOnlySpan`1[System.Char], System.ReadOnlySpan`1[System.Char], System.ReadOnlySpan`1[System.Char])",
"System.String Join(System.String, System.String)",
"System.String Join(System.String, System.String, System.String)",
"System.String Join(System.String, System.String, System.String, System.String)",
"System.String Join(System.String[])",
"System.String TrimEndingDirectorySeparator(System.String)"
]
}
Expand Up @@ -11,13 +11,20 @@
"Boolean EndsInDirectorySeparator(System.String)",
"Boolean HasExtension(System.ReadOnlySpan`1[System.Char])",
"Boolean IsPathFullyQualified(System.ReadOnlySpan`1[System.Char])",
"Boolean IsPathFullyQualified(System.String)",
"Boolean IsPathRooted(System.ReadOnlySpan`1[System.Char])",
"Boolean TryJoin(System.ReadOnlySpan`1[System.Char], System.ReadOnlySpan`1[System.Char], System.ReadOnlySpan`1[System.Char], System.Span`1[System.Char], Int32 ByRef)",
"Boolean TryJoin(System.ReadOnlySpan`1[System.Char], System.ReadOnlySpan`1[System.Char], System.Span`1[System.Char], Int32 ByRef)",
"System.ReadOnlySpan`1[System.Char] GetDirectoryName(System.ReadOnlySpan`1[System.Char])",
"System.ReadOnlySpan`1[System.Char] GetExtension(System.ReadOnlySpan`1[System.Char])",
"System.ReadOnlySpan`1[System.Char] GetFileName(System.ReadOnlySpan`1[System.Char])",
"System.ReadOnlySpan`1[System.Char] GetFileNameWithoutExtension(System.ReadOnlySpan`1[System.Char])",
"System.ReadOnlySpan`1[System.Char] GetPathRoot(System.ReadOnlySpan`1[System.Char])",
"System.ReadOnlySpan`1[System.Char] TrimEndingDirectorySeparator(System.ReadOnlySpan`1[System.Char])",
"System.String GetFullPath(System.String, System.String)",
"System.String GetRelativePath(System.String, System.String)",
"System.String Join(System.ReadOnlySpan`1[System.Char], System.ReadOnlySpan`1[System.Char])",
"System.String Join(System.ReadOnlySpan`1[System.Char], System.ReadOnlySpan`1[System.Char], System.ReadOnlySpan`1[System.Char])",
"System.String Join(System.ReadOnlySpan`1[System.Char], System.ReadOnlySpan`1[System.Char], System.ReadOnlySpan`1[System.Char], System.ReadOnlySpan`1[System.Char])",
"System.String Join(System.String, System.String)",
"System.String Join(System.String, System.String, System.String)",
Expand Down

0 comments on commit bb2a49d

Please sign in to comment.