public void CompleteThrowsExceptionIfChannelIsAlreadyCompleted()
        {
            var sut = new BufferedChannel <int>(2);

            sut.TryComplete().ShouldBe(true);
            Should.Throw <OperationCanceledException>(() => sut.Complete());
        }
        public void CompletionSuccessfulAfterCompleteCalledWithoutException()
        {
            var sut = new BufferedChannel <int>(2);

            sut.Complete();
            sut.Completion.Status.ShouldBe(TaskStatus.RanToCompletion);
        }
        public void CannotWriteAfterCompletion()
        {
            var sut = new BufferedChannel <int>(2);

            sut.TryWrite(1);
            sut.Complete();
            sut.TryWrite(2).ShouldBe(false);
            Should.Throw <OperationCanceledException>(() => sut.WriteAsync(2));
        }
        public void CompleteAbortsPendingReadTasks()
        {
            var sut       = new BufferedChannel <int>(0);
            var readTask1 = sut.ReadAsync();
            var readTask2 = sut.ReadAsync();

            sut.Complete();
            Should.Throw <TaskCanceledException>(() => readTask1.AsTask(), Timeout1Sec);
            Should.Throw <TaskCanceledException>(() => readTask2.AsTask(), Timeout1Sec);
        }
        public void CompleteAbortsPendingWriteTasks()
        {
            var sut        = new BufferedChannel <int>(0);
            var writeTask1 = sut.WriteAsync(1);
            var writeTask2 = sut.WriteAsync(2);

            sut.Complete();
            Should.Throw <TaskCanceledException>(() => writeTask1, Timeout1Sec);
            Should.Throw <TaskCanceledException>(() => writeTask2, Timeout1Sec);
        }