This project is read-only.

Project: AsyncAwait


The test class using async and await keywords, the test method must return the Task:
[TestClass]
public class NumberGeneratorTest
{
	[TestMethod]
	public async Task VerifyNumberIsGreaterThanZero()
	{
		var number = await NumberGenerator.Show();

		Assert.IsTrue(number > 0);
	}
}

Execute code with TPL (Task Parallel Library):
public class NumberGenerator
{
	public static async Task<int> Show()
	{
		var generator = new NumberGenerator();
		var number = await generator.Generate();
		Console.WriteLine(number);

		return number;
	}

	public Task<int> Generate()
	{
		return Task.Run(() => new Random().Next(1, 1000));
	}
}

Last edited Oct 24, 2012 at 11:40 AM by teoarch, version 1

Comments

No comments yet.