public void TestInboundRemoveBeforeAdded()
        {
            CombinedChannelDuplexHandler <ChannelHandlerAdapter, ChannelHandlerAdapter> handler =
                new CombinedChannelDuplexHandler <ChannelHandlerAdapter, ChannelHandlerAdapter>(
                    new ChannelHandlerAdapter(), new ChannelHandlerAdapter());

            Assert.Throws <InvalidOperationException>(() => handler.RemoveInboundHandler());
        }
        public void TestInboundEvents()
        {
            Queue <Event> queue          = new Queue <Event>();
            var           inboundHandler = new ChannelInboundHandlerAdapter2(queue);

            CombinedChannelDuplexHandler <ChannelHandlerAdapter, ChannelHandlerAdapter> handler =
                new CombinedChannelDuplexHandler <ChannelHandlerAdapter, ChannelHandlerAdapter>(
                    inboundHandler, new ChannelHandlerAdapter());

            EmbeddedChannel channel = new EmbeddedChannel(handler);

            channel.Pipeline.FireChannelWritabilityChanged();
            channel.Pipeline.FireUserEventTriggered(MSG);
            channel.Pipeline.FireChannelRead(MSG);
            channel.Pipeline.FireChannelReadComplete();

            Assert.Equal(Event.HANDLER_ADDED, queue.Dequeue());
            Assert.Equal(Event.REGISTERED, queue.Dequeue());
            Assert.Equal(Event.ACTIVE, queue.Dequeue());
            Assert.Equal(Event.CHANNEL_WRITABILITY_CHANGED, queue.Dequeue());
            Assert.Equal(Event.USER_EVENT_TRIGGERED, queue.Dequeue());
            Assert.Equal(Event.CHANNEL_READ, queue.Dequeue());
            Assert.Equal(Event.CHANNEL_READ_COMPLETE, queue.Dequeue());

            handler.RemoveInboundHandler();
            Assert.Equal(Event.HANDLER_REMOVED, queue.Dequeue());

            // These should not be handled by the inboundHandler anymore as it was removed before
            channel.Pipeline.FireChannelWritabilityChanged();
            channel.Pipeline.FireUserEventTriggered(MSG);
            channel.Pipeline.FireChannelRead(MSG);
            channel.Pipeline.FireChannelReadComplete();

            // Should have not received any more events as it was removed before via removeInboundHandler()
            Assert.Empty(queue);
            Assert.True(channel.Finish());
            Assert.Empty(queue);
        }