You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public class AwaitForeachReproduction
{
public async Task<int> Execute(CancellationToken token)
{
int sum = 0;
await foreach (int result in AsyncEnumerable(token))
{
sum += result;
}
return sum;
}
private async IAsyncEnumerable<int> AsyncEnumerable([EnumeratorCancellation] CancellationToken cancellationToken)
{
for (int i = 0; i < 100; i++)
{
await Task.Delay(10, cancellationToken);
yield return i;
}
}
}
Test Case for it:
public class AwaitForeachReproductionFixture
{
[Test]
public async Task Execute_Should_Work()
{
// Arrange
var sut = new AwaitForeachReproduction();
// Act
var result = await sut.Execute(CancellationToken.None);
// Assert
Assert.AreEqual(result, 4950);
}
[Test]
public void Execute_Should_Be_Canceled()
{
// Arrange
var sut = new AwaitForeachReproduction();
var cts = new CancellationTokenSource();
// Act
var resultAsync = sut.Execute(cts.Token);
cts.Cancel();
// Assert
Assert.ThrowsAsync<TaskCanceledException>(async () => await resultAsync);
}
}
Reported BRANCH coverage is 75%
Without EnumeratorCancellation attribute usage it is 100%
The text was updated successfully, but these errors were encountered:
Hello
got issue similar to that one
Updated reproduction class:
Test Case for it:
Reported BRANCH coverage is 75%
Without
EnumeratorCancellation
attribute usage it is 100%The text was updated successfully, but these errors were encountered: