There is a right way and a wrong way with programme Asynchronously, mainly due to the initial way Microsoft brought in Async programming was not best practise and they have now made changes to make it more effective and be more productive.
Continue reading Asynchronous Programming the right wayCategory Archives: Async
How to Async
There are a number of best practices when it comes to Async what I’ll try and cover here are the “guidelines” than actual rules. There are exceptions to each of these guidelines. The guidelines are summarised in the table below.
Continue reading How to Async
Async Unit Tests
In theory, Async unit testing seems easy, run the Async, wait until it is finished and look at the results. But as you will find out it is not that easy.
Here is the official approach to Async unit testing
[TestMethod]
public void FourDividedByTwoIsTwo()
{
GeneralThreadAffineContext.Run(async () =>
{
int result = await MyClass.Divide(4, 2);
Assert.AreEqual(2, result);
});
}
[TestMethod]
[ExpectedException(typeof(DivideByZeroException))]
public void DenominatorIsZeroThrowsDivideByZero()
{
GeneralThreadAffineContext.Run(async () =>
{
await MyClass.Divide(4, 0);
});
}
Hang on what is GeneralThreadAffineContext, it a Utility code originally distributed as part of the Async CTP, and the project file can be found here: AsyncTestUtilities
Original article: Async Unit Tests, Part 2: The Right Way