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); }); }
public void FromEvent1_EventNeverRaised_NeverCompletes() { Test.Async(async() => { var timer = new Timer(); var task = AsyncFactory <ElapsedEventArgs> .FromEvent(timer, "Elapsed"); await AssertEx.NeverCompletesAsync(task); }); }
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); })); }
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); })); }
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); })); }
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); }); }
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); }); }
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); }); }
public void FromEvent1_EventNotFound_RaisesException() { var bgw = new BackgroundWorker(); AssertEx.ThrowsException <InvalidOperationException>(() => AsyncFactory <RunWorkerCompletedEventArgs> .FromEvent(bgw, "Elapsed")); }