Translate

Saturday 6 October 2012

When Synchronous is ahead of the asynchronous...

When Synchronous is ahead of the asynchronous...make the asynchronous call wait ! :)

1, 2, 3 & 4. The unit test, TestAdd fails because it calls the async method AddWithTask which, in turn, calls the async method add.
5. This is  because the  async keyword does not ensure asynchronicity; the "await" keyword does that making sure that the method call awaits 'asynchronously' for the method call to complete.

To make the test pass, add the 'await' keyword to the Task.Factory.StartNew as in the AddWithTask method.

Please refer to the next post for the "buggy"code and the test to find the bug.

Happy unit testing with NUnit ! :)

No comments: