Arise, awake, and learn by approaching the exalted ones,
for that path is sharp as a razor’s edge, impassable,
and hard to go by, say the wise.
Because every single reason has the same, if not more, number of reasons to be wrong. ;)
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 ! :)