Ejemplo n.º 1
0
 public void BeginMethodTest()
 {
     bool methodCalled = false;
     // setup the method
     Func<int, int> method = n =>
                                 {
                                     methodCalled = true;
                                     return -1;
                                 };
     // setup the test instance
     var asyncSample = new AsyncBench(
         20, method);
     IAsyncResult ar = asyncSample.BeginMethod();
     // wait until method call completes
     ar.AsyncWaitHandle.WaitOne();
     // verify it is completed
     Assert.IsTrue(ar.IsCompleted, "Operation should have completed before reaching this point!");
     // verify our delegate was called
     Assert.IsTrue(methodCalled, "Test method should have been called, but it was not!");
     // The bellow assert would require more synchronization and exceeds the testing contract
     //Assert.AreEqual(-1, asyncSample.Param);
 }