public void RequestBodySetPipeReaderReturnsSameValue()
        {
            var context = new DefaultProtoContext();

            var feature = new RequestBodyPipeFeature(context);

            var pipeReader = new Pipe().Reader;

            feature.Reader = pipeReader;

            Assert.Equal(pipeReader, feature.Reader);
        }
        public void RequestBodyReturnsStreamPipeReader()
        {
            var context        = new DefaultProtoContext();
            var expectedStream = new MemoryStream();

            context.Request.Body = expectedStream;

            var feature = new RequestBodyPipeFeature(context);

            var pipeBody = feature.Reader;

            Assert.True(pipeBody is StreamPipeReader);
            Assert.Equal(expectedStream, (pipeBody as StreamPipeReader).InnerStream);
        }
        public void RequestBodySetPipeReadReturnsUserSetValueAlways()
        {
            var context = new DefaultProtoContext();

            var feature = new RequestBodyPipeFeature(context);

            var expectedPipeReader = new Pipe().Reader;

            feature.Reader = expectedPipeReader;

            // Because the user set the RequestBodyPipe, this will return the user set pipeReader
            context.Request.Body = new MemoryStream();

            Assert.Equal(expectedPipeReader, feature.Reader);
        }
        public async Task RequestBodyGetsDataFromSecondStream()
        {
            var context = new DefaultProtoContext();

            context.Request.Body = new MemoryStream(Encoding.ASCII.GetBytes("hahaha"));
            var feature = new RequestBodyPipeFeature(context);
            var _       = feature.Reader;

            var expectedString = "abcdef";

            context.Request.Body = new MemoryStream(Encoding.ASCII.GetBytes(expectedString));
            var data = await feature.Reader.ReadAsync();

            Assert.Equal(expectedString, GetStringFromReadResult(data));
        }
        public void RequestBodyGetPipeReaderAfterSettingBodyTwice()
        {
            var context = new DefaultProtoContext();

            context.Request.Body = new MemoryStream();

            var feature = new RequestBodyPipeFeature(context);

            var pipeBody = feature.Reader;

            // Requery the PipeReader after setting the body again.
            var expectedStream = new MemoryStream();

            context.Request.Body = expectedStream;
            pipeBody             = feature.Reader;

            Assert.True(pipeBody is StreamPipeReader);
            Assert.Equal(expectedStream, (pipeBody as StreamPipeReader).InnerStream);
        }