Ejemplo n.º 1
0
        public void MultipartEncodesWrappedStream()
        {
            using (var stream = new MultipartFormDataContentStream(new MemoryStream(Encoding.UTF8.GetBytes(CONTENT))))
                using (var reader = new StreamReader(stream))
                {
                    var actual = reader.ReadToEnd();

                    actual.Should().MatchRegex(EXPECTED_CONTENT_PATTERN);
                }
        }
Ejemplo n.º 2
0
        public void ClosesWrappedStream()
        {
            var streamMock = new Mock <MemoryStream>(MockBehavior.Default, Encoding.UTF8.GetBytes(CONTENT))
            {
                CallBase = true
            };

            using (var composite = new MultipartFormDataContentStream(streamMock.Object))
            {
                var buffer = new byte[10];
                composite.Read(buffer, 0, buffer.Length);
            }

            streamMock.Verify(s => s.Close());
        }
Ejemplo n.º 3
0
        public void ExhaustsWrappedStream()
        {
            using (var stream = new MultipartFormDataContentStream(new MemoryStream(Encoding.UTF8.GetBytes(CONTENT))))
            {
                var buffer = new byte[256];
                var offset = 0;
                int bytesRead;
                while ((bytesRead = stream.Read(buffer, offset, 8)) > 0)
                {
                    offset += bytesRead;
                }

                var actual = Encoding.UTF8.GetString(buffer, 0, offset);
                actual.Should().MatchRegex(EXPECTED_CONTENT_PATTERN);

                var trail = Encoding.UTF8.GetString(buffer, offset, buffer.Length - offset);
                trail.ToCharArray().Should().AllBeEquivalentTo('\0');
            }
        }