Skip to content

Commit 0ef2d98

Browse files
christianrondeaufgreinacher
authored andcommitted
Support File.ReadAllLinesAsync and friends on .NET Core 3 / netstandard2.1 (#502)
Fixes #499
1 parent 0ff06ae commit 0ef2d98

18 files changed

Lines changed: 72 additions & 72 deletions

System.IO.Abstractions.TestingHelpers.Tests/FileSystemTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public void Is_Serializable()
2020
}
2121
#endif
2222

23-
#if NETCOREAPP2_0
23+
#if NETCOREAPP2_0 || NETSTANDARD2_1
2424
[Test]
2525
public void Mock_File_Succeeds()
2626
{

System.IO.Abstractions.TestingHelpers.Tests/MockFileAppendAllLinesTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using NUnit.Framework;
33
using XFS = System.IO.Abstractions.TestingHelpers.MockUnixSupport;
44

5-
#if NETCOREAPP2_0
5+
#if NETCOREAPP2_0 || NETSTANDARD2_1
66
using System.Threading.Tasks;
77
#endif
88

@@ -123,7 +123,7 @@ public void MockFile_AppendAllLines_ShouldThrowArgumentNullExceptionIfEncodingIs
123123
Assert.That(exception.ParamName, Is.EqualTo("encoding"));
124124
}
125125

126-
#if NETCOREAPP2_0
126+
#if NETCOREAPP2_0 || NETSTANDARD2_1
127127
[Test]
128128
public async Task MockFile_AppendAllLinesAsync_ShouldPersistNewLinesToExistingFile()
129129
{

System.IO.Abstractions.TestingHelpers.Tests/MockFileAppendAllTextTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace System.IO.Abstractions.TestingHelpers.Tests
99

1010
using XFS = MockUnixSupport;
1111

12-
#if NETCOREAPP2_0
12+
#if NETCOREAPP2_0 || NETSTANDARD2_1
1313
using System.Threading.Tasks;
1414
#endif
1515

@@ -158,7 +158,7 @@ public void MockFile_AppendAllText_ShouldWorkWithRelativePath()
158158
Assert.That(fileSystem.File.Exists(file));
159159
}
160160

161-
#if NETCOREAPP2_0
161+
#if NETCOREAPP2_0 || NETSTANDARD2_1
162162
[Test]
163163
public async Task MockFile_AppendAllTextAsync_ShouldPersistNewText()
164164
{

System.IO.Abstractions.TestingHelpers.Tests/MockFileReadAllBytesTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using NUnit.Framework;
33
using XFS = System.IO.Abstractions.TestingHelpers.MockUnixSupport;
44

5-
#if NETCOREAPP2_0
5+
#if NETCOREAPP2_0 || NETSTANDARD2_1
66
using System.Threading.Tasks;
77
#endif
88

@@ -64,7 +64,7 @@ public void MockFile_ReadAllBytes_ShouldTolerateAltDirectorySeparatorInPath()
6464

6565
Assert.AreEqual(data, fileSystem.File.ReadAllBytes(altPath));
6666
}
67-
#if NETCOREAPP2_0
67+
#if NETCOREAPP2_0 || NETSTANDARD2_1
6868
[Test]
6969
public async Task MockFile_ReadAllBytesAsync_ShouldReturnOriginalByteData()
7070
{

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace System.IO.Abstractions.TestingHelpers.Tests
88

99
using XFS = MockUnixSupport;
1010

11-
#if NETCOREAPP2_0
11+
#if NETCOREAPP2_0 || NETSTANDARD2_1
1212
using System.Threading.Tasks;
1313
#endif
1414

@@ -71,7 +71,7 @@ public void MockFile_ReadAllLines_NotExistingFile_ThrowsCorrectFileNotFoundExcep
7171
Assert.That(exception.Message, Is.EqualTo("Could not find file '" + absentFileNameFullPath + "'."));
7272
}
7373

74-
#if NETCOREAPP2_0
74+
#if NETCOREAPP2_0 || NETSTANDARD2_1
7575
[Test]
7676
public async Task MockFile_ReadAllLinesAsync_ShouldReturnOriginalTextData()
7777
{

System.IO.Abstractions.TestingHelpers.Tests/MockFileWriteAllBytesTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using NUnit.Framework;
33
using XFS = System.IO.Abstractions.TestingHelpers.MockUnixSupport;
44

5-
#if NETCOREAPP2_0
5+
#if NETCOREAPP2_0 || NETSTANDARD2_1
66
using System.Threading.Tasks;
77
#endif
88

@@ -85,7 +85,7 @@ public void MockFile_WriteAllBytes_ShouldThrowAnArgumentNullExceptionIfBytesAreN
8585
Assert.That(exception.ParamName, Is.EqualTo("bytes"));
8686
}
8787

88-
#if NETCOREAPP2_0
88+
#if NETCOREAPP2_0 || NETSTANDARD2_1
8989
[Test]
9090
public void MockFile_WriteAllBytesAsync_ShouldThrowDirectoryNotFoundExceptionIfPathDoesNotExists()
9191
{

System.IO.Abstractions.TestingHelpers.Tests/MockFileWriteAllLinesTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public static IEnumerable ForContentsIsNull
195195
}
196196
}
197197

198-
#if NETCOREAPP2_0
198+
#if NETCOREAPP2_0 || NETSTANDARD2_1
199199
public static IEnumerable ForDifferentEncodingAsync
200200
{
201201
get
@@ -485,7 +485,7 @@ public void MockFile_WriteAllLinesGeneric_ShouldThrowAnArgumentNullExceptionIfCo
485485
Assert.That(exception.ParamName, Is.EqualTo("contents"));
486486
}
487487

488-
#if NETCOREAPP2_0
488+
#if NETCOREAPP2_0 || NETSTANDARD2_1
489489
[TestCaseSource(typeof(TestDataForWriteAllLines), "ForDifferentEncodingAsync")]
490490
public void MockFile_WriteAllLinesAsyncGeneric_ShouldWriteTheCorrectContent(IMockFileDataAccessor fileSystem, Action action, string expectedContent)
491491
{

System.IO.Abstractions.TestingHelpers.Tests/MockFileWriteAllTextTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
using XFS = MockUnixSupport;
1010

11-
#if NETCOREAPP2_0
11+
#if NETCOREAPP2_0 || NETSTANDARD2_1
1212
using System.Threading.Tasks;
1313
#endif
1414

@@ -227,7 +227,7 @@ public void MockFile_WriteAllTextMultipleLines_ShouldWriteTextFileToMemoryFileSy
227227
fileSystem.GetFile(path).TextContents);
228228
}
229229

230-
#if NETCOREAPP2_0
230+
#if NETCOREAPP2_0 || NETSTANDARD2_1
231231
[Test]
232232
public async Task MockFile_WriteAllTextAsync_ShouldWriteTextFileToMemoryFileSystem()
233233
{

System.IO.Abstractions.TestingHelpers/MockFile.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public override void AppendAllLines(string path, IEnumerable<string> contents, E
3939
AppendAllText(path, concatContents, encoding);
4040
}
4141

42-
#if NETCOREAPP2_0
42+
#if NETCOREAPP2_0 || NETSTANDARD2_1
4343
public override Task AppendAllLinesAsync(string path, IEnumerable<string> contents, CancellationToken cancellationToken = default(CancellationToken))
4444
{
4545
AppendAllLines(path, contents);
@@ -82,7 +82,7 @@ public override void AppendAllText(string path, string contents, Encoding encodi
8282
}
8383
}
8484

85-
#if NETCOREAPP2_0
85+
#if NETCOREAPP2_0 || NETSTANDARD2_1
8686
public override Task AppendAllTextAsync(string path, string contents, CancellationToken cancellationToken = default(CancellationToken))
8787
{
8888
AppendAllText(path, contents);
@@ -491,7 +491,7 @@ public override byte[] ReadAllBytes(string path)
491491
return mockFileDataAccessor.GetFile(path).Contents;
492492
}
493493

494-
#if NETCOREAPP2_0
494+
#if NETCOREAPP2_0 || NETSTANDARD2_1
495495
public override Task<byte[]> ReadAllBytesAsync(string path, CancellationToken cancellationToken = default(CancellationToken))
496496
{
497497
return Task.FromResult(ReadAllBytes(path));
@@ -534,7 +534,7 @@ public override string[] ReadAllLines(string path, Encoding encoding)
534534
.SplitLines();
535535
}
536536

537-
#if NETCOREAPP2_0
537+
#if NETCOREAPP2_0 || NETSTANDARD2_1
538538
public override Task<string[]> ReadAllLinesAsync(string path, CancellationToken cancellationToken = default(CancellationToken))
539539
{
540540
return Task.FromResult(ReadAllLines(path));
@@ -570,7 +570,7 @@ public override string ReadAllText(string path, Encoding encoding)
570570
return ReadAllTextInternal(path, encoding);
571571
}
572572

573-
#if NETCOREAPP2_0
573+
#if NETCOREAPP2_0 || NETSTANDARD2_1
574574
public override Task<string> ReadAllTextAsync(string path, CancellationToken cancellationToken)
575575
{
576576
return Task.FromResult(ReadAllText(path));
@@ -752,7 +752,7 @@ public override void WriteAllBytes(string path, byte[] bytes)
752752
mockFileDataAccessor.AddFile(path, new MockFileData(bytes));
753753
}
754754

755-
#if NETCOREAPP2_0
755+
#if NETCOREAPP2_0 || NETSTANDARD2_1
756756
public override Task WriteAllBytesAsync(string path, byte[] bytes, CancellationToken cancellationToken)
757757
{
758758
WriteAllBytes(path, bytes);
@@ -947,7 +947,7 @@ public override void WriteAllLines(string path, string[] contents, Encoding enco
947947
WriteAllLines(path, new List<string>(contents), encoding);
948948
}
949949

950-
#if NETCOREAPP2_0
950+
#if NETCOREAPP2_0 || NETSTANDARD2_1
951951
public override Task WriteAllLinesAsync(string path, IEnumerable<string> contents, CancellationToken cancellationToken)
952952
{
953953
WriteAllLines(path, contents);
@@ -1056,7 +1056,7 @@ public override void WriteAllText(string path, string contents, Encoding encodin
10561056
mockFileDataAccessor.AddFile(path, data);
10571057
}
10581058

1059-
#if NETCOREAPP2_0
1059+
#if NETCOREAPP2_0 || NETSTANDARD2_1
10601060
public override Task WriteAllTextAsync(string path, string contents, CancellationToken cancellationToken)
10611061
{
10621062
WriteAllText(path, contents);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>netstandard1.4;netstandard2.0;netcoreapp2.0</TargetFrameworks>
3+
<TargetFrameworks>netstandard1.4;netstandard2.0;netstandard2.1;netcoreapp2.0</TargetFrameworks>
44
<TargetFrameworks Condition="!$([MSBuild]::IsOsUnixLike())">$(TargetFrameworks);net40</TargetFrameworks>
55
<PackageId>System.IO.Abstractions.TestingHelpers</PackageId>
66
<Description>A set of pre-built mocks to help when testing file system interactions.</Description>
@@ -26,7 +26,7 @@
2626
<ProjectReference Include="..\System.IO.Abstractions\System.IO.Abstractions.csproj" />
2727
</ItemGroup>
2828

29-
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.0'">
29+
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' Or '$(TargetFramework)' == 'netstandard2.1' Or '$(TargetFramework)' == 'netcoreapp2.0'">
3030
<PackageReference Include="System.IO.FileSystem.AccessControl">
3131
<Version>4.6.0</Version>
3232
</PackageReference>

0 commit comments

Comments
 (0)