public void OnCompletedInvoked() { var queue = new DerivedQueue <GenericParameterHelper>(); int invoked = 0; queue.OnCompletedDelegate = () => invoked++; queue.Complete(); Assert.Equal(1, invoked); // Call it again to make sure it's only invoked once. queue.Complete(); Assert.Equal(1, invoked); }
public void OnEnqueuedNotAlreadyDispatched() { var queue = new DerivedQueue <int>(); bool callbackFired = false; queue.OnEnqueuedDelegate = (value, alreadyDispatched) => { Assert.Equal(5, value); Assert.False(alreadyDispatched); callbackFired = true; }; queue.Enqueue(5); Assert.True(callbackFired); }
public void OnDequeued() { var queue = new DerivedQueue <int>(); bool callbackFired = false; queue.OnDequeuedDelegate = value => { Assert.Equal(5, value); callbackFired = true; }; queue.Enqueue(5); Assert.True(queue.TryDequeue(out int dequeuedValue)); Assert.True(callbackFired); }
public async Task OnEnqueuedAlreadyDispatched() { var queue = new DerivedQueue <int>(); bool callbackFired = false; queue.OnEnqueuedDelegate = (value, alreadyDispatched) => { Assert.Equal(5, value); Assert.True(alreadyDispatched); callbackFired = true; }; Task <int>?dequeuer = queue.DequeueAsync(); queue.Enqueue(5); Assert.True(callbackFired); Assert.Equal(5, await dequeuer.WithTimeout(UnexpectedTimeout)); }
public void OnEnqueuedAlreadyDispatched() { var queue = new DerivedQueue <int>(); bool callbackFired = false; queue.OnEnqueuedDelegate = (value, alreadyDispatched) => { Assert.Equal(5, value); Assert.True(alreadyDispatched); callbackFired = true; }; var dequeuer = queue.DequeueAsync(); queue.Enqueue(5); Assert.True(callbackFired); Assert.True(dequeuer.IsCompleted); }