/// <summary>
        ///     Initializes a new instance of the <see cref="HttpServer" /> class.
        /// </summary>
        /// <param name="moduleManager">The modules are used to process the HTTP requests. You need to specify at least one.</param>
        public HttpServer(IModuleManager moduleManager)
        {
            _moduleManager = moduleManager;
            BodyDecoder = new CompositeIMessageSerializer();

            _configuration = new ChannelTcpListenerConfiguration(() => new HttpMessageDecoder(BodyDecoder), () => new HttpMessageEncoder());
            _bufferSlicePool = new BufferSlicePool(65535, 100);
            ApplicationInfo = new MemoryItemStorage();
        }
        public ChannelTcpListenerConfiguration(Func<IMessageDecoder> decoderFactory, Func<IMessageEncoder> encoderFactory)
        {
            if (decoderFactory == null) throw new ArgumentNullException("decoderFactory");
            if (encoderFactory == null) throw new ArgumentNullException("encoderFactory");

            DecoderFactory = decoderFactory;
            EncoderFactory = encoderFactory;
            BufferPool = new BufferSlicePool(65535, 100);
        }
        public void return_to_pool_directly()
        {
            var sut = new BufferSlicePool(10, 2);
            var buffer = sut.Pop();
            sut.Push(buffer);

            sut.Pop();
            sut.Pop();
        }
        public void pop_one()
        {
            var sut = new BufferSlicePool(10, 2);

            var actual = sut.Pop();

            actual.Capacity.Should().Be(10);
            actual.Offset.Should().Be(10, "internal implementation is a stack, last buffer is at pos 10");
        }
        public void return_to_pool__verify_that_it_got_enqueued()
        {
            var sut = new BufferSlicePool(10, 2);
            var buffer = sut.Pop();
            
            sut.Push(buffer);

            sut.Pop();
            sut.Pop();
        }
        public void pop_too_many()
        {
            var sut = new BufferSlicePool(10, 2);

            sut.Pop();
            sut.Pop();
            Action actual = () => sut.Pop();

            actual.ShouldThrow<PoolEmptyException>();
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="HttpServer" /> class.
        /// </summary>
        /// <param name="moduleManager">The modules are used to process the HTTP requests. You need to specify at least one.</param>
        /// <param name="configuration">
        ///     You can override the configuration to your likings.
        /// </param>
        /// <exception cref="System.ArgumentNullException">moduleManager/configuration</exception>
        public HttpServer(IModuleManager moduleManager, ChannelTcpListenerConfiguration configuration)
        {
            if (moduleManager == null) throw new ArgumentNullException("moduleManager");
            if (configuration == null) throw new ArgumentNullException("configuration");

            BodyDecoder = new CompositeIMessageSerializer();
            _moduleManager = moduleManager;
            _configuration = configuration;
            _bufferSlicePool = new BufferSlicePool(65535, 100);
            ApplicationInfo = new MemoryItemStorage();
        }