This repository was archived by the owner on Jul 13, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
[BaseTasks] improve Task settings in AsyncTaskExtensions #129
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
tests/Microsoft.Android.Build.BaseTasks-Tests/AsyncTaskExtensionsTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,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); | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.