public void IsEmpty_WithTwoItems_IsFalse() { var queue = new DefaultAsyncWaitQueue<object>() as IAsyncWaitQueue<object>; queue.Enqueue(); queue.Enqueue(); Assert.IsFalse(queue.IsEmpty); }
public void Dequeue_WithoutResult_CompletesWithDefaultResult() { var queue = new DefaultAsyncWaitQueue<object>() as IAsyncWaitQueue<object>; var task = queue.Enqueue(); queue.Dequeue().Dispose(); Assert.AreEqual(default(object), task.Result); }
public void Dequeue_WithResult_CompletesWithResult() { var queue = new DefaultAsyncWaitQueue<object>() as IAsyncWaitQueue<object>; var result = new object(); var task = queue.Enqueue(); queue.Dequeue(result).Dispose(); Assert.AreSame(result, task.Result); }
public void Dequeue_Disposed_CompletesTask() { var queue = new DefaultAsyncWaitQueue<object>() as IAsyncWaitQueue<object>; var task = queue.Enqueue(); var finish = queue.Dequeue(); Assert.IsFalse(task.IsCompleted); finish.Dispose(); Assert.IsTrue(task.IsCompleted); }
public void Dequeue_WithTwoItems_OnlyCompletesFirstItem() { Test.Async(async () => { var queue = new DefaultAsyncWaitQueue<object>() as IAsyncWaitQueue<object>; var task1 = queue.Enqueue(); var task2 = queue.Enqueue(); queue.Dequeue().Dispose(); Assert.IsTrue(task1.IsCompleted); await AssertEx.NeverCompletesAsync(task2); }); }
public void IsEmpty_WhenEmpty_IsTrue() { var queue = new DefaultAsyncWaitQueue <object>() as IAsyncWaitQueue <object>; Assert.IsTrue(queue.IsEmpty); }
public void IsEmpty_WhenEmpty_IsTrue() { var queue = new DefaultAsyncWaitQueue<object>() as IAsyncWaitQueue<object>; Assert.IsTrue(queue.IsEmpty); }
public void Cancelled_BeforeEnqueue_RemovesTaskFromQueue() { var queue = new DefaultAsyncWaitQueue<object>() as IAsyncWaitQueue<object>; var cts = new CancellationTokenSource(); cts.Cancel(); var task = queue.Enqueue(new object(), cts.Token); Assert.IsTrue(queue.IsEmpty); }
public void Cancelled_BeforeEnqueue_SynchronouslyCancelsTask() { var queue = new DefaultAsyncWaitQueue<object>() as IAsyncWaitQueue<object>; var cts = new CancellationTokenSource(); cts.Cancel(); var task = queue.Enqueue(new object(), cts.Token); Assert.IsTrue(task.IsCanceled); }
public void Cancelled_WhenNotInQueue_DoesNotRemoveTaskFromQueue() { var queue = new DefaultAsyncWaitQueue<object>() as IAsyncWaitQueue<object>; var cts = new CancellationTokenSource(); var task = queue.Enqueue(new object(), cts.Token); var _ = queue.Enqueue(); queue.Dequeue().Dispose(); cts.Cancel(); Assert.IsFalse(queue.IsEmpty); }
public void Cancelled_WhenInQueue_RemovesTaskFromQueue() { Test.Async(async () => { var queue = new DefaultAsyncWaitQueue<object>() as IAsyncWaitQueue<object>; var cts = new CancellationTokenSource(); var task = queue.Enqueue(new object(), cts.Token); cts.Cancel(); await AssertEx.ThrowsExceptionAsync<OperationCanceledException>(task); Assert.IsTrue(queue.IsEmpty); }); }
public void TryCancel_EntryNotFound_DoesNotRemoveTaskFromQueue() { var queue = new DefaultAsyncWaitQueue<object>() as IAsyncWaitQueue<object>; var task = queue.Enqueue(); queue.Enqueue(); queue.Dequeue().Dispose(); queue.TryCancel(task).Dispose(); Assert.IsFalse(queue.IsEmpty); }
public void TryCancel_EntryFound_RemovesTaskFromQueue() { var queue = new DefaultAsyncWaitQueue<object>() as IAsyncWaitQueue<object>; var task = queue.Enqueue(); queue.TryCancel(task).Dispose(); Assert.IsTrue(queue.IsEmpty); }
public void TryCancel_EntryFound_CancelsTask() { var queue = new DefaultAsyncWaitQueue<object>() as IAsyncWaitQueue<object>; var task = queue.Enqueue(); queue.TryCancel(task).Dispose(); Assert.IsTrue(task.IsCanceled); }
public void Cancelled_WhenInQueue_CancelsTask() { AsyncContext.Run(async () => { var queue = new DefaultAsyncWaitQueue<object>() as IAsyncWaitQueue<object>; var cts = new CancellationTokenSource(); var task = queue.Enqueue(cts.Token); cts.Cancel(); await AssertEx.ThrowsExceptionAsync<OperationCanceledException>(task); }); }
public DebugView(DefaultAsyncWaitQueue <T> queue) { _queue = queue; }