Skip to content

Commit 6a56d93

Browse files
committed
.
1 parent 1d16b43 commit 6a56d93

File tree

4 files changed

+50
-42
lines changed

4 files changed

+50
-42
lines changed

readme.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The package targets `netstandard2.0` and is designed to support the following ru
1313
* `uap10`
1414

1515

16-
**API count: 646**<!-- singleLineInclude: apiCount. path: /apiCount.include.md -->
16+
**API count: 657**<!-- singleLineInclude: apiCount. path: /apiCount.include.md -->
1717

1818

1919
**See [Milestones](../../milestones?state=closed) for release notes.**
@@ -1211,6 +1211,12 @@ The class `Polyfill` includes the following extension methods:
12111211
* `void SetCanceled<T>(CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.taskcompletionsource-1.setcanceled?view=net-10.0#system-threading-tasks-taskcompletionsource-1-setcanceled(system-threading-cancellationtoken))
12121212

12131213

1214+
#### TaskWhenEach
1215+
1216+
* `IAsyncEnumerable<Task> WhenEach(IEnumerable<Task>, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task.wheneach?view=net-10.0)
1217+
* `IAsyncEnumerable<Task<TResult>> WhenEach<TResult>(IEnumerable<Task<TResult>>, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task.wheneach?view=net-10.0)
1218+
1219+
12141220
#### TextReader
12151221

12161222
* `ValueTask<int> ReadAsync(Memory<char>, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.textreader.readasync?view=net-10.0#system-io-textreader-readasync(system-memory((system-char))-system-threading-cancellationtoken))
@@ -1245,6 +1251,7 @@ The class `Polyfill` includes the following extension methods:
12451251
* `int Nanoseconds()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.timespan.nanoseconds?view=net-10.0)
12461252
* `bool TryFormat(Span<byte>, int, ReadOnlySpan<char>, IFormatProvider?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.timespan.tryformat?view=net-10.0#system-timespan-tryformat(system-span((system-byte))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider))
12471253
* `bool TryFormat(Span<char>, int, ReadOnlySpan<char>, IFormatProvider?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.timespan.tryformat?view=net-10.0#system-timespan-tryformat(system-span((system-char))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider))
1254+
* `TimeSpan FromMilliseconds(long)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.timespan.frommilliseconds?view=net-10.0)
12481255

12491256

12501257
#### Type
@@ -1338,6 +1345,17 @@ The class `Polyfill` includes the following extension methods:
13381345
* `ExternalAttributes` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.ziparchiveentry.externalattributes?view=net-10.0)
13391346

13401347

1348+
#### ZipFile
1349+
1350+
* `Task CreateFromDirectoryAsync(string, string, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.zipfile.createfromdirectoryasync?view=net-10.0)
1351+
* `Task CreateFromDirectoryAsync(string, string, CompressionLevel, bool, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.zipfile.createfromdirectoryasync?view=net-10.0)
1352+
* `Task CreateFromDirectoryAsync(string, string, CompressionLevel, bool, Encoding, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.zipfile.createfromdirectoryasync?view=net-10.0)
1353+
* `Task ExtractToDirectoryAsync(string, string, bool, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.zipfile.extracttodirectoryasync?view=net-10.0)
1354+
* `Task ExtractToDirectoryAsync(string, string, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.zipfile.extracttodirectoryasync?view=net-10.0)
1355+
* `Task ExtractToDirectoryAsync(string, string, Encoding, bool, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.zipfile.extracttodirectoryasync?view=net-10.0)
1356+
* `Task ExtractToDirectoryAsync(string, string, Encoding, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.zipfile.extracttodirectoryasync?view=net-10.0)
1357+
1358+
13411359
#### Ensure
13421360

13431361
* `void DirectoryExists(string)`

src/Tests/PolyfillTests_Compression.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public async Task ExtractToDirectory_Extracts_All_Entries()
1010
using (var archive = new ZipArchive(memStream, ZipArchiveMode.Create, true))
1111
{
1212
var entry = archive.CreateEntry("test.txt");
13-
await using var stream = entry.Open();
13+
using var stream = entry.Open();
1414
using var writer = new StreamWriter(stream);
1515
await writer.WriteAsync("content");
1616
}
@@ -40,7 +40,7 @@ public async Task ExtractToDirectory_Overwrites_Existing_File_When_True()
4040
using (var archive = new ZipArchive(memStream, ZipArchiveMode.Create, true))
4141
{
4242
var entry = archive.CreateEntry("test.txt");
43-
await using var stream = entry.Open();
43+
using var stream = entry.Open();
4444
using var writer = new StreamWriter(stream);
4545
await writer.WriteAsync("new content");
4646
}
@@ -101,7 +101,7 @@ public async Task ZipFile_ExtractToDirectoryAsync_ExtractsAllEntries()
101101
using (var archive = ZipFile.Open(tempArchive, ZipArchiveMode.Create))
102102
{
103103
var entry = archive.CreateEntry("test.txt");
104-
await using var stream = entry.Open();
104+
using var stream = entry.Open();
105105
using var writer = new StreamWriter(stream);
106106
await writer.WriteAsync("async content");
107107
}
@@ -144,7 +144,7 @@ public async Task ZipFile_ExtractToDirectoryAsync_WithOverwrite_OverwritesFiles(
144144
using (var archive = ZipFile.Open(tempArchive, ZipArchiveMode.Create))
145145
{
146146
var entry = archive.CreateEntry("test.txt");
147-
await using var stream = entry.Open();
147+
using var stream = entry.Open();
148148
using var writer = new StreamWriter(stream);
149149
writer.Write("new content");
150150
}
@@ -182,7 +182,7 @@ public async Task ZipFile_ExtractToDirectoryAsync_WithEncoding_ExtractsCorrectly
182182
using (var archive = ZipFile.Open(tempArchive, ZipArchiveMode.Create, Encoding.UTF8))
183183
{
184184
var entry = archive.CreateEntry("test.txt");
185-
await using var stream = entry.Open();
185+
using var stream = entry.Open();
186186
using var writer = new StreamWriter(stream);
187187
await writer.WriteAsync("encoded content");
188188
}
@@ -223,7 +223,7 @@ public async Task ZipFile_ExtractToDirectoryAsync_WithCancellation_CanBeCancelle
223223
using (var archive = ZipFile.Open(tempArchive, ZipArchiveMode.Create))
224224
{
225225
var entry = archive.CreateEntry("test.txt");
226-
await using var stream = entry.Open();
226+
using var stream = entry.Open();
227227
using var writer = new StreamWriter(stream);
228228
writer.Write("content");
229229
}

src/Tests/PolyfillTests_MicroNanosecond.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,7 @@ public async Task TimeSpan_FromMilliseconds_Long_MaxValue_ThrowsOverflowExceptio
8686
// Arrange - value that would overflow
8787
var tooLarge = long.MaxValue;
8888

89-
// Act & Assert - Native .NET 10+ throws ArgumentOutOfRangeException, polyfill throws OverflowException
90-
#if NET10_0_OR_GREATER
9189
await Assert.That(() => TimeSpan.FromMilliseconds(tooLarge)).Throws<ArgumentOutOfRangeException>();
92-
#else
93-
await Assert.That(() => TimeSpan.FromMilliseconds(tooLarge)).Throws<OverflowException>();
94-
#endif
9590
}
9691

9792
[Test]
@@ -100,12 +95,7 @@ public async Task TimeSpan_FromMilliseconds_Long_MinValue_ThrowsOverflowExceptio
10095
// Arrange - value that would overflow
10196
var tooSmall = long.MinValue;
10297

103-
// Act & Assert - Native .NET 10+ throws ArgumentOutOfRangeException, polyfill throws OverflowException
104-
#if NET10_0_OR_GREATER
10598
await Assert.That(() => TimeSpan.FromMilliseconds(tooSmall)).Throws<ArgumentOutOfRangeException>();
106-
#else
107-
await Assert.That(() => TimeSpan.FromMilliseconds(tooSmall)).Throws<OverflowException>();
108-
#endif
10999
}
110100

111101
[Test]

src/Tests/PolyfillTests_Task.cs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ public async Task WaitAsync_TimeoutAndToken_CancellationBeforeTimeout_ThrowsTask
201201
var task = Task.Delay(10000);
202202

203203
// Act & Assert (cancellation should win - use 5s timeout to ensure cancellation fires first on slow CI servers)
204-
await Assert.ThrowsAsync<TaskCanceledException>(async () =>
205-
await task.WaitAsync(TimeSpan.FromSeconds(5), cancelSource.Token));
204+
await Assert.That(async () =>
205+
await task.WaitAsync(TimeSpan.FromSeconds(5), cancelSource.Token)).Throws<TaskCanceledException>();
206206
}
207207

208208
[Test]
@@ -642,7 +642,7 @@ public async Task WhenEach_NonGeneric_CompletesInOrder()
642642
await whenEachTask;
643643

644644
// Assert - verify we got all tasks
645-
Assert.AreEqual(3, completed.Count);
645+
await Assert.That(completed.Count).IsEqualTo(3);
646646
}
647647

648648
[Test]
@@ -673,10 +673,10 @@ public async Task WhenEach_Generic_CompletesInOrder()
673673
await whenEachTask;
674674

675675
// Assert - verify we got all results
676-
Assert.AreEqual(3, results.Count);
677-
Assert.Contains(1, results);
678-
Assert.Contains(2, results);
679-
Assert.Contains(3, results);
676+
await Assert.That(results.Count).IsEqualTo(3);
677+
await Assert.That(results.Contains(1)).IsTrue();
678+
await Assert.That(results.Contains(2)).IsTrue();
679+
await Assert.That(results.Contains(3)).IsTrue();
680680
}
681681

682682
[Test]
@@ -693,7 +693,7 @@ public async Task WhenEach_NonGeneric_EmptyCollection_CompletesImmediately()
693693
}
694694

695695
// Assert
696-
Assert.AreEqual(0, count);
696+
await Assert.That(count).IsEqualTo(0);
697697
}
698698

699699
[Test]
@@ -710,34 +710,34 @@ public async Task WhenEach_Generic_EmptyCollection_CompletesImmediately()
710710
}
711711

712712
// Assert
713-
Assert.AreEqual(0, count);
713+
await Assert.That(count).IsEqualTo(0);
714714
}
715715

716716
[Test]
717-
public void WhenEach_NonGeneric_NullTasks_ThrowsArgumentNullException()
717+
public async Task WhenEach_NonGeneric_NullTasks_ThrowsArgumentNullException()
718718
{
719719
// Act & Assert
720720
#pragma warning disable IDE0022
721-
Assert.ThrowsAsync<ArgumentNullException>(async () =>
721+
await Assert.That(async () =>
722722
{
723723
await foreach (var task in Task.WhenEach((IEnumerable<Task>)null!))
724724
{
725725
}
726-
});
726+
}).Throws<ArgumentNullException>();
727727
#pragma warning restore IDE0022
728728
}
729729

730730
[Test]
731-
public void WhenEach_Generic_NullTasks_ThrowsArgumentNullException()
731+
public async Task WhenEach_Generic_NullTasks_ThrowsArgumentNullException()
732732
{
733733
// Act & Assert
734734
#pragma warning disable IDE0022
735-
Assert.ThrowsAsync<ArgumentNullException>(async () =>
735+
await Assert.That(async () =>
736736
{
737737
await foreach (var task in Task.WhenEach((IEnumerable<Task<int>>)null!))
738738
{
739739
}
740-
});
740+
}).Throws<ArgumentNullException>();
741741
#pragma warning restore IDE0022
742742
}
743743

@@ -774,7 +774,7 @@ public async Task WhenEach_NonGeneric_WithCancellation_StopsIterating()
774774
tcs3.SetResult();
775775

776776
// Assert
777-
Assert.ThrowsAsync<OperationCanceledException>(() => whenEachTask);
777+
await Assert.That(() => whenEachTask).Throws<OperationCanceledException>();
778778
}
779779
#endif
780780

@@ -802,9 +802,9 @@ public async Task WhenEach_Generic_WithFaultedTask_PropagatesException()
802802
await whenEachTask;
803803

804804
// Assert - WhenEach completes, but the task itself is faulted
805-
Assert.AreEqual(2, results.Count);
806-
Assert.DoesNotThrowAsync(() => results[0]);
807-
Assert.ThrowsAsync<InvalidOperationException>(() => results[1]);
805+
await Assert.That(results.Count).IsEqualTo(2);
806+
await Assert.That(async () => await results[0]).ThrowsNothing();
807+
await Assert.That(async () => await results[1]).Throws<InvalidOperationException>();
808808
}
809809

810810
[Test]
@@ -823,11 +823,11 @@ public async Task WhenEach_NonGeneric_AlreadyCompletedTasks_YieldsAll()
823823
await foreach (var task in Task.WhenEach(tasks))
824824
{
825825
count++;
826-
Assert.True(task.IsCompleted);
826+
await Assert.That(task.IsCompleted).IsTrue();
827827
}
828828

829829
// Assert
830-
Assert.AreEqual(3, count);
830+
await Assert.That(count).IsEqualTo(3);
831831
}
832832

833833
[Test]
@@ -849,10 +849,10 @@ public async Task WhenEach_Generic_AlreadyCompletedTasks_YieldsAll()
849849
}
850850

851851
// Assert
852-
Assert.AreEqual(3, results.Count);
853-
Assert.Contains(1, results);
854-
Assert.Contains(2, results);
855-
Assert.Contains(3, results);
852+
await Assert.That(results.Count).IsEqualTo(3);
853+
await Assert.That(results.Contains(1)).IsTrue();
854+
await Assert.That(results.Contains(2)).IsTrue();
855+
await Assert.That(results.Contains(3)).IsTrue();
856856
}
857857

858858
#endregion

0 commit comments

Comments
 (0)