-
Notifications
You must be signed in to change notification settings - Fork 792
Expand file tree
/
Copy pathToImmutableArray.cs
More file actions
84 lines (72 loc) · 2.73 KB
/
Copy pathToImmutableArray.cs
File metadata and controls
84 lines (72 loc) · 2.73 KB
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
77
78
79
80
81
82
83
84
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT License.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
namespace Tests
{
public class ToImmutableArray : AsyncEnumerableTests
{
[Fact]
public async Task ToImmutableArray_Null()
{
await Assert.ThrowsAsync<ArgumentNullException>(() => ImmutableArrayAsyncEnumerableExtensions.ToImmutableArrayAsync<int>(default).AsTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => ImmutableArrayAsyncEnumerableExtensions.ToImmutableArrayAsync<int>(default, CancellationToken.None).AsTask());
}
[Fact]
public async Task ToImmutableArray_IAsyncIListProvider_Simple()
{
var xs = new[] { 42, 25, 39 };
var res = xs.ToAsyncEnumerable().ToImmutableArrayAsync();
Assert.True((await res).SequenceEqual(xs));
}
[Fact]
public async Task ToImmutableArray_IAsyncIListProvider_Empty1()
{
var xs = new int[0];
var res = xs.ToAsyncEnumerable().ToImmutableArrayAsync();
Assert.True((await res).SequenceEqual(xs));
}
[Fact]
public async Task ToImmutableArray_IAsyncIListProvider_Empty2()
{
var xs = new HashSet<int>();
var res = xs.ToAsyncEnumerable().ToImmutableArrayAsync();
Assert.True((await res).SequenceEqual(xs));
}
[Fact]
public async Task ToImmutableArray_Empty()
{
var xs = AsyncEnumerable.Empty<int>();
var res = xs.ToImmutableArrayAsync();
Assert.True((await res).Length == 0);
}
[Fact]
public async Task ToImmutableArray_Throw()
{
var ex = new Exception("Bang!");
var res = Throw<int>(ex).ToImmutableArrayAsync();
await AssertThrowsAsync(res, ex);
}
[Fact]
public async Task ToImmutableArray_Query()
{
var xs = await AsyncEnumerable.Range(5, 50).Take(10).ToImmutableArrayAsync();
var ex = new[] { 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
Assert.True(ex.SequenceEqual(xs));
}
[Fact]
public async Task ToImmutableArray_Set()
{
var res = new[] { 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
var xs = new HashSet<int>(res);
var arr = await xs.ToAsyncEnumerable().ToImmutableArrayAsync();
Assert.True(res.SequenceEqual(arr));
}
}
}