-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
ForAllTests.cs
76 lines (67 loc) · 2.62 KB
/
ForAllTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Xunit;
namespace System.Linq.Parallel.Tests
{
public static class ForAllTests
{
[Theory]
[InlineData(1)]
[InlineData(2)]
[InlineData(16)]
public static void ForAll(int count)
{
IntegerRangeSet seen = new IntegerRangeSet(0, count);
ParallelEnumerable.Range(0, count).ForAll(x => seen.Add(x));
seen.AssertComplete();
}
[Fact]
[OuterLoop]
public static void ForAll_Longrunning()
{
ForAll(Sources.OuterLoopCount);
}
[Fact]
public static void ForAll_OperationCanceledException()
{
AssertThrows.EventuallyCanceled((source, canceler) => source.ForAll(x => canceler()));
}
[Fact]
public static void ForAll_AggregateException_Wraps_OperationCanceledException()
{
AssertThrows.OtherTokenCanceled((source, canceler) => source.ForAll(x => canceler()));
AssertThrows.SameTokenNotCanceled((source, canceler) => source.ForAll(x => canceler()));
}
[Fact]
public static void ForAll_OperationCanceledException_PreCanceled()
{
AssertThrows.AlreadyCanceled(source => source.ForAll(x => { }));
}
[Fact]
public static void ForAll_AggregateException()
{
AssertThrows.Wrapped<DeliberateTestException>(() => ParallelEnumerable.Range(0, 1).ForAll(x => { throw new DeliberateTestException(); }));
AssertThrows.Wrapped<DeliberateTestException>(() => ParallelEnumerable.Range(0, 1).Select((Func<int, int>)(x => { throw new DeliberateTestException(); })).ForAll(x => { }));
}
[Fact]
public static void ForAll_ArgumentNullException()
{
AssertExtensions.Throws<ArgumentNullException>("source", () => ((ParallelQuery<int>)null).ForAll(x => { }));
AssertExtensions.Throws<ArgumentNullException>("action", () => ParallelEnumerable.Range(0, 1).ForAll(null));
}
[Fact]
public static void ForAll_UserThrownAggregateException()
{
const int Count = 10;
try
{
new int[Count].AsParallel().Select<int, int>(i => throw new AggregateException()).ForAll(_ => { });
}
catch (AggregateException e)
{
// PLINQ internals flatten all AggregateExceptions.
Assert.Equal(0, e.InnerExceptions.Count);
}
}
}
}