コード例 #1
0
        public void MultipleRangesGeneratesMultipartByteRangesContent(string ranges, int innerStreamLength, int expectedBodyparts, string[] contentRanges)
        {
            // Arrange
            string data = new String('a', innerStreamLength);

            byte[]           bytes     = Encoding.UTF8.GetBytes(data);
            MemoryStream     memStream = new MemoryStream(bytes);
            RangeHeaderValue range     = RangeHeaderValue.Parse(ranges);

            // Act
            ByteRangeStreamContent content = new ByteRangeStreamContent(memStream, range, _expectedMediatype);
            MemoryStream           result  = new MemoryStream();

            content.CopyToAsync(result).Wait();
            MultipartMemoryStreamProvider multipart = content.ReadAsMultipartAsync().Result;

            // Assert
            Assert.Equal(expectedBodyparts, multipart.Contents.Count);
            for (int count = 0; count < multipart.Contents.Count; count++)
            {
                MediaTypeHeaderValue contentType = multipart.Contents[count].Headers.ContentType;
                Assert.Equal(_expectedMediatype, contentType);

                ContentRangeHeaderValue expectedContentRange = ContentRangeHeaderValue.Parse(contentRanges[count]);
                ContentRangeHeaderValue contentRange         = multipart.Contents[count].Headers.ContentRange;
                Assert.Equal(expectedContentRange, contentRange);
            }
        }
コード例 #2
0
        public void SingleRangeGeneratesNonMultipartContent(
            string ranges,
            int innerStreamLength,
            string contentRange
            )
        {
            // Arrange
            string data = new String('a', innerStreamLength);

            byte[]           bytes     = Encoding.UTF8.GetBytes(data);
            MemoryStream     memStream = new MemoryStream(bytes);
            RangeHeaderValue range     = RangeHeaderValue.Parse(ranges);

            // Act
            ByteRangeStreamContent rangeContent = new ByteRangeStreamContent(
                memStream,
                range,
                _expectedMediatype
                );

            // Assert
            Assert.Equal(_expectedMediatype, rangeContent.Headers.ContentType);
            ContentRangeHeaderValue expectedContentRange = ContentRangeHeaderValue.Parse(
                contentRange
                );

            Assert.Equal(expectedContentRange, rangeContent.Headers.ContentRange);
        }
コード例 #3
0
        public void MultipleRangesGeneratesMultipartByteRangesContent(string ranges, int innerStreamLength, int expectedBodyparts, string[] contentRanges)
        {
            // Arrange
            string data = new String('a', innerStreamLength);
            byte[] bytes = Encoding.UTF8.GetBytes(data);
            MemoryStream memStream = new MemoryStream(bytes);
            RangeHeaderValue range = RangeHeaderValue.Parse(ranges);

            // Act
            ByteRangeStreamContent content = new ByteRangeStreamContent(memStream, range, _expectedMediatype);
            MemoryStream result = new MemoryStream();
            content.CopyToAsync(result).Wait();
            MultipartMemoryStreamProvider multipart = content.ReadAsMultipartAsync().Result;

            // Assert
            Assert.Equal(expectedBodyparts, multipart.Contents.Count);
            for (int count = 0; count < multipart.Contents.Count; count++)
            {
                MediaTypeHeaderValue contentType = multipart.Contents[count].Headers.ContentType;
                Assert.Equal(_expectedMediatype, contentType);

                ContentRangeHeaderValue expectedContentRange = ContentRangeHeaderValue.Parse(contentRanges[count]);
                ContentRangeHeaderValue contentRange = multipart.Contents[count].Headers.ContentRange;
                Assert.Equal(expectedContentRange, contentRange);
            }
        }
コード例 #4
0
        public void SingleRangeGeneratesNonMultipartContent(string ranges, int innerStreamLength, string contentRange)
        {
            // Arrange
            string data = new String('a', innerStreamLength);
            byte[] bytes = Encoding.UTF8.GetBytes(data);
            MemoryStream memStream = new MemoryStream(bytes);
            RangeHeaderValue range = RangeHeaderValue.Parse(ranges);

            // Act
            ByteRangeStreamContent rangeContent = new ByteRangeStreamContent(memStream, range, _expectedMediatype);

            // Assert
            Assert.Equal(_expectedMediatype, rangeContent.Headers.ContentType);
            ContentRangeHeaderValue expectedContentRange = ContentRangeHeaderValue.Parse(contentRange);
            Assert.Equal(expectedContentRange, rangeContent.Headers.ContentRange);
        }