Ejemplo n.º 1
0
        public void Dispose_FaultsAwaiters()
        {
            var quota = new Quota(1L);

            using (var cts = new CancellationTokenSource())
            {
                var awaiters = new[]
                {
                    quota.WaitAsync(),
                    quota.WaitAsync(cts.Token),
                    quota.WaitAsync(),
                    quota.WaitAsync()
                };

                cts.Cancel();
                quota.Dispose();

                using (TaskAssert.Completed(awaiters[0])) { }
                TaskAssert.Cancelled(awaiters[1]);

                foreach (var awaiter in awaiters.Skip(2))
                {
                    TaskAssert.Faulted <ObjectDisposedException>(awaiter);
                }
            }
        }
Ejemplo n.º 2
0
        public void OrCanceledBy_NotCanceled_Propagates(TaskStatus AStatus)
        {
            using (var cts = new CancellationTokenSource())
            {
                var tcs  = new TaskCompletionSource <Void>();
                var cont = tcs.Task.OrCanceledBy(cts.Token);
                Assume.That(cont.Wait(10), Is.False);

                switch (AStatus)
                {
                case TaskStatus.RanToCompletion:
                    tcs.TrySetResult(default);
                    TaskAssert.Completed(cont);
                    break;

                case TaskStatus.Canceled:
                    tcs.TrySetCanceled(_FCanceled.Token);
                    TaskAssert.Cancelled(cont);
                    break;

                case TaskStatus.Faulted:
                    tcs.TrySetException(_FFaulted);
                    Assert.That(
                        TaskAssert.Faulted <Exception>(cont),
                        Is.SameAs(_FFaulted)
                        );
                    break;

                default:
                    throw new NotImplementedException();
                }
            }
        }
Ejemplo n.º 3
0
        public void Dispose_FaultsAwaiters()
        {
            var lck = new Lock();

            using (var cts = new CancellationTokenSource())
            {
                var awaiters = new[]
                {
                    TaskAssert.Detach(lck.WaitAsync),
                    TaskAssert.Detach(() => lck.WaitAsync(cts.Token)),
                    TaskAssert.Detach(lck.WaitAsync),
                    TaskAssert.Detach(lck.WaitAsync)
                };

                cts.Cancel();
                lck.Dispose();

                using (TaskAssert.Completed(awaiters[0])) { }
                TaskAssert.Cancelled(awaiters[1]);

                foreach (var awaiter in awaiters.Skip(2))
                {
                    TaskAssert.Faulted <ObjectDisposedException>(awaiter);
                }
            }
        }
Ejemplo n.º 4
0
        public void Dispose_FaultsAwaiters()
        {
            var turnstile = new Turnstile();

            using (var cts = new CancellationTokenSource())
            {
                var awaiters = new[]
                {
                    turnstile.WaitAsync(),
                    turnstile.WaitAsync(cts.Token),
                    turnstile.WaitAsync(),
                    turnstile.WaitAsync()
                };

                cts.Cancel();
                turnstile.Dispose();

                TaskAssert.Faulted <ObjectDisposedException>(awaiters[0]);
                TaskAssert.Cancelled(awaiters[1]);

                foreach (var awaiter in awaiters.Skip(2))
                {
                    TaskAssert.Faulted <ObjectDisposedException>(awaiter);
                }
            }
        }
Ejemplo n.º 5
0
        public void WaitAsync_Disposed_ReturnsFaultedTask()
        {
            var future = new Future <int>();

            future.Dispose();

            TaskAssert.Faulted <ObjectDisposedException>(future.WaitAsync());
        }
Ejemplo n.º 6
0
        public void WaitAsync_Disposed_ReturnsFaultedTask()
        {
            var evt = new Event <int>();

            evt.Dispose();

            TaskAssert.Faulted <ObjectDisposedException>(evt.WaitAsync());
        }
Ejemplo n.º 7
0
        public void WaitAsync_Disposed_ThrowsObjectDisposedException()
        {
            var cond = new Condition();

            cond.Dispose();

            TaskAssert.Faulted <ObjectDisposedException>(cond.WaitAsync());
        }
Ejemplo n.º 8
0
        public void WaitAsync_Disposed_ReturnsFaultedTask()
        {
            var trigger = new Trigger();

            trigger.Dispose();

            TaskAssert.Faulted <ObjectDisposedException>(trigger.WaitAsync());
        }
Ejemplo n.º 9
0
        public void WaitAsync_Disposed_ReturnsFaultedTask()
        {
            var era = new Era();

            era.Dispose();

            TaskAssert.Faulted <ObjectDisposedException>(era.WaitAsync());
        }
Ejemplo n.º 10
0
        public void WaitAsync_Disposed_ThrowsObjectDisposedException()
        {
            var quota = new Quota(1L);

            quota.Dispose();

            TaskAssert.Faulted <ObjectDisposedException>(quota.WaitAsync());
        }
Ejemplo n.º 11
0
        public void WaitAsync_Disposed_ThrowsObjectDisposedException()
        {
            var lck = new Lock();

            lck.Dispose();

            TaskAssert.Faulted <ObjectDisposedException>(lck.WaitAsync());
        }
Ejemplo n.º 12
0
        public void WaitAsync_Disposed_ThrowsObjectDisposedException()
        {
            var turnstile = new Turnstile();

            turnstile.Dispose();

            TaskAssert.Faulted <ObjectDisposedException>(turnstile.WaitAsync());
        }
Ejemplo n.º 13
0
        public void Dispose_FaultsAwaiters()
        {
            var era = new Era();

            var awaiter = era.WaitAsync();

            era.Dispose();

            TaskAssert.Faulted <ObjectDisposedException>(awaiter);
        }
Ejemplo n.º 14
0
        public void Dispose_FaultsAwaiters()
        {
            var trigger = new Trigger();

            var awaiter = trigger.WaitAsync();

            trigger.Dispose();

            TaskAssert.Faulted <ObjectDisposedException>(awaiter);
        }
Ejemplo n.º 15
0
        public void Dispose_FaultsAwaiters()
        {
            var evt = new Event <int>();

            var awaiter = evt.WaitAsync();

            evt.Dispose();

            TaskAssert.Faulted <ObjectDisposedException>(awaiter);
        }
Ejemplo n.º 16
0
        public void Dispose_FaultsAwaiters()
        {
            var future = new Future <int>();

            var awaiter = future.WaitAsync();

            future.Dispose();

            TaskAssert.Faulted <ObjectDisposedException>(awaiter);
        }
Ejemplo n.º 17
0
        public void Dispose_FaultsAwaiters()
        {
            var cond = new Condition();

            var awaiter = cond.WaitAsync();

            cond.Dispose();

            TaskAssert.Faulted <ObjectDisposedException>(awaiter);
        }
Ejemplo n.º 18
0
        public void WaitAsync_Disposed_ThrowsObjectDisposedException()
        {
            var barrier = new Barrier(3);

            barrier.Dispose();

            var awaiter = barrier.WaitAsync();

            TaskAssert.Faulted <ObjectDisposedException>(awaiter);
        }
Ejemplo n.º 19
0
        public void Dispose_FaultsAwaiters()
        {
            var barrier = new Barrier(3);

            var awaiters = new []
            {
                barrier.WaitAsync(),
                barrier.WaitAsync()
            };

            barrier.Dispose();

            foreach (var awaiter in awaiters)
            {
                TaskAssert.Faulted <ObjectDisposedException>(awaiter);
            }
        }