forked from dotnet/android-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAsyncTaskExtensionsTests.cs
More file actions
68 lines (61 loc) · 1.52 KB
/
Copy pathAsyncTaskExtensionsTests.cs
File metadata and controls
68 lines (61 loc) · 1.52 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
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Android.Build.Tasks;
using NUnit.Framework;
using Xamarin.Build;
namespace Microsoft.Android.Build.BaseTasks.Tests
{
[TestFixture]
public class AsyncTaskExtensionsTests
{
const int Iterations = 32;
[Test]
public async Task RunTask ()
{
bool set = false;
await new AsyncTask ().RunTask (delegate { set = true; }); // delegate { } has void return type
Assert.IsTrue (set);
}
[Test]
public async Task RunTaskOfT ()
{
bool set = false;
Assert.IsTrue (await new AsyncTask ().RunTask (() => set = true), "RunTask should return true");
Assert.IsTrue (set);
}
[Test]
public async Task WhenAll ()
{
bool set = false;
await new AsyncTask ().WhenAll (new [] { 0 }, _ => set = true);
Assert.IsTrue (set);
}
[Test]
public async Task WhenAllWithLock ()
{
var input = new int [Iterations];
var output = new List<int> ();
await new AsyncTask ().WhenAllWithLock (input, (i, l) => {
lock (l) output.Add (i);
});
Assert.AreEqual (Iterations, output.Count);
}
[Test]
public void ParallelForEach ()
{
bool set = false;
new AsyncTask ().ParallelForEach (new [] { 0 }, _ => set = true);
Assert.IsTrue (set);
}
[Test]
public void ParallelForEachWithLock ()
{
var input = new int [Iterations];
var output = new List<int> ();
new AsyncTask ().ParallelForEachWithLock (input, (i, l) => {
lock (l) output.Add (i);
});
Assert.AreEqual (Iterations, output.Count);
}
}
}