예제 #1
0
 public void FromEvent1_EventNeverRaised_NeverCompletes()
 {
     AsyncContext.Run(async() =>
     {
         var timer = new System.Timers.Timer();
         var task  = AsyncFactory <ElapsedEventArgs> .FromEvent(timer, "Elapsed");
         await AssertEx.NeverCompletesAsync(task);
     });
 }
예제 #2
0
 public void FromEvent1_EventNeverRaised_NeverCompletes()
 {
     Test.Async(async() =>
     {
         var timer = new Timer();
         var task  = AsyncFactory <ElapsedEventArgs> .FromEvent(timer, "Elapsed");
         await AssertEx.NeverCompletesAsync(task);
     });
 }
예제 #3
0
 public void FromEvent1_AsyncEventNeverRaised_NeverCompletes()
 {
     AsyncContext.Run(() => Task.Run(async() =>
     {
         var bgw     = new BackgroundWorker();
         bgw.DoWork += (_, __) => { new Semaphore(0, 1).WaitOne(); };
         var task    = AsyncFactory <RunWorkerCompletedEventArgs> .FromEvent(bgw, "RunWorkerCompleted");
         bgw.RunWorkerAsync();
         await AssertEx.NeverCompletesAsync(task);
     }));
 }
예제 #4
0
        public void FromEvent1_AsyncEventFailed_Fails()
        {
            AsyncContext.Run(() => Task.Run(async() =>
            {
                var bgw     = new BackgroundWorker();
                bgw.DoWork += (_, args) => { throw new NotImplementedException(); };
                var task    = AsyncFactory <RunWorkerCompletedEventArgs> .FromEvent(bgw, "RunWorkerCompleted");
                bgw.RunWorkerAsync();

                await AssertEx.ThrowsExceptionAsync <NotImplementedException>(task);
            }));
        }
예제 #5
0
        public void FromEvent1_AsyncEventRaised_Completes()
        {
            AsyncContext.Run(() => Task.Run(async() =>
            {
                var bgw     = new BackgroundWorker();
                var o       = new object();
                bgw.DoWork += (_, args) => { args.Result = o; };
                var task    = AsyncFactory <RunWorkerCompletedEventArgs> .FromEvent(bgw, "RunWorkerCompleted");
                bgw.RunWorkerAsync();

                var result = await task;

                Assert.AreSame(o, result.Result);
            }));
        }
예제 #6
0
        public void FromEvent1_EventRaised_Completes()
        {
            AsyncContext.Run(async() =>
            {
                var timer = new System.Timers.Timer();
                var task  = AsyncFactory <ElapsedEventArgs> .FromEvent(timer, "Elapsed");

                var start     = DateTime.Now;
                timer.Enabled = true;

                var result = await task;
                var end    = DateTime.Now;

                Assert.IsTrue(result.SignalTime >= start && result.SignalTime <= end);
            });
        }
예제 #7
0
        public void FromEvent0_EventRaised_Completes()
        {
            Test.Async(async() =>
            {
                var timer = new Timer();
                var task  = AsyncFactory <ElapsedEventArgs> .FromEvent(timer);

                var start     = DateTime.Now;
                timer.Enabled = true;

                var result = await task;
                var end    = DateTime.Now;

                Assert.IsTrue(result.SignalTime >= start && result.SignalTime <= end);
            });
        }
예제 #8
0
        public void FromEvent1_AsyncEventCanceled_Cancels()
        {
            Test.Async(async() =>
            {
                var bgw = new BackgroundWorker();
                bgw.WorkerSupportsCancellation = true;
                bgw.DoWork += (_, args) => { while (!bgw.CancellationPending)
                                             {
                                                 Thread.Sleep(100);
                                             }
                                             args.Cancel = true; };
                var task = AsyncFactory <RunWorkerCompletedEventArgs> .FromEvent(bgw, "RunWorkerCompleted");
                bgw.RunWorkerAsync();
                bgw.CancelAsync();

                await AssertEx.CompletesCanceledAsync(task);
            });
        }
예제 #9
0
        public void FromEvent1_EventNotFound_RaisesException()
        {
            var bgw = new BackgroundWorker();

            AssertEx.ThrowsException <InvalidOperationException>(() => AsyncFactory <RunWorkerCompletedEventArgs> .FromEvent(bgw, "Elapsed"));
        }