public async Task When_Reader_Does_Not_Complete_Readers_Not_Completed()
        {
            // Arrange
            using var multiplexer = new MergingMultiplexer(10, _outputHelper.ToLogger <MergingMultiplexer>());

            var cts = new CancellationTokenSource();

            var channel1 = Channel.CreateBounded <IQueueMessageContext>(10);
            var channel2 = Channel.CreateBounded <IQueueMessageContext>(10);

            multiplexer.ReadFrom(channel1);
            multiplexer.ReadFrom(channel2);

            // Act
            await multiplexer.RunAsync(cts.Token);

            var multiplexerRunTask = ReadAllMessages(multiplexer);

            channel1.Writer.Complete();

            // Assert
            var delay         = Task.Delay(TimeoutPeriod);
            var completedTask = await Task.WhenAny(multiplexerRunTask, delay);

            Assert.Equal(delay, completedTask);

            cts.Cancel();
        }
        public async Task When_Reader_Completes_When_All_Readers_Completed()
        {
            // Arrange
            using var multiplexer = new MergingMultiplexer(10, _outputHelper.ToLogger <MergingMultiplexer>());

            var cts = new CancellationTokenSource();

            var channel1 = Channel.CreateBounded <IQueueMessageContext>(10);
            var channel2 = Channel.CreateBounded <IQueueMessageContext>(10);

            multiplexer.ReadFrom(channel1);
            multiplexer.ReadFrom(channel2);

            // Act
            await multiplexer.RunAsync(cts.Token);

            var multiplexerRunTask = ReadAllMessages(multiplexer);

            channel1.Writer.Complete();
            channel2.Writer.Complete();

            // Assert
            await Patiently.AssertThatAsync(_outputHelper, () => multiplexerRunTask.IsCompletedSuccessfully);

            cts.Cancel();
        }
        public void Cannot_Add_Invalid_Reader()
        {
            // Arrange
            using var multiplexer = new MergingMultiplexer(10, _outputHelper.ToLogger <MergingMultiplexer>());

            // Act and Assert
            Assert.Throws <ArgumentNullException>(() => multiplexer.ReadFrom(null));
        }