Language: C#
Unit Test an Async Operation
1: [TestClass] 2: public class MyTests 3: { 4: static System.Threading.ManualResetEvent m_Trigger 5: = new System.Threading.ManualResetEvent(false); 6: 7: [TestMethod] 8: private static void MyTest() 9: { 10: Exception ex = null; 11: var _Item = new MyClass(); 12: _Item.AsyncCompleted += (s, e) => 13: { 14: // this delay is important in case it is too fast 15: System.Threading.Thread.Sleep(100); 16: ex = e.Error; 17: m_Trigger.Set(); 18: }; 19: _Item.DoAsync(); 20: m_Trigger.WaitOne(); 21: Assert.IsNull(ex); 22: } 23: }
Tags:
Report Abuse
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search

