Example #1
0
        public void Ctor_SetsContentRange()
        {
            ContentRangeHeaderValue   contentRange = new ContentRangeHeaderValue(0, 20, 100);
            InvalidByteRangeException invalidByteRangeException = new InvalidByteRangeException(contentRange);

            Assert.Same(contentRange, invalidByteRangeException.ContentRange);
        }
        /// <summary>
        /// Helper method for creating an <see cref="HttpResponseMessage"/> message with a "416 (Requested Range Not Satisfiable)" status code.
        /// This response can be used in combination with the <see cref="ByteRangeStreamContent"/> to indicate that the requested range or
        /// ranges do not overlap with the current resource. The response contains a "Content-Range" header indicating the valid upper and lower
        /// bounds for requested ranges.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="invalidByteRangeException">An <see cref="InvalidByteRangeException"/> instance, typically thrown by a
        /// <see cref="ByteRangeStreamContent"/> instance.</param>
        /// <returns>An 416 (Requested Range Not Satisfiable) error response with a Content-Range header indicating the valid range.</returns>
        public static HttpResponseMessage CreateErrorResponse(
            [NotNull] this HttpRequestMessage request,
            [NotNull] InvalidByteRangeException invalidByteRangeException)
        {
            var rangeNotSatisfiableResponse = request.CreateErrorResponse(
                HttpStatusCode.RequestedRangeNotSatisfiable,
                invalidByteRangeException);

            rangeNotSatisfiableResponse.Content.Headers.ContentRange = invalidByteRangeException.ContentRange;
            return(rangeNotSatisfiableResponse);
        }
        public void CreateErrorResponseRangeNotSatisfiable_SetsCorrectStatusCodeAndContentRangeHeader()
        {
            // Arrange
            HttpRequestMessage        request = new HttpRequestMessage();
            ContentRangeHeaderValue   expectedContentRange      = new ContentRangeHeaderValue(length: 128);
            InvalidByteRangeException invalidByteRangeException = new InvalidByteRangeException(expectedContentRange);

            // Act
            HttpResponseMessage response = request.CreateErrorResponse(invalidByteRangeException);

            // Assert
            Assert.Equal(HttpStatusCode.RequestedRangeNotSatisfiable, response.StatusCode);
            Assert.Same(expectedContentRange, response.Content.Headers.ContentRange);
        }
        public void CreateErrorResponseRangeNotSatisfiable_SetsCorrectStatusCodeAndContentRangeHeader()
        {
            // Arrange
            var context = new DefaultHttpContext();

            context.RequestServices = CreateServices(new DefaultContentNegotiator());

            var request = CreateRequest(context);

            var expectedContentRange      = new ContentRangeHeaderValue(length: 128);
            var invalidByteRangeException = new InvalidByteRangeException(expectedContentRange);

            // Act
            var response = request.CreateErrorResponse(invalidByteRangeException);

            // Assert
            Assert.Equal(HttpStatusCode.RequestedRangeNotSatisfiable, response.StatusCode);
            Assert.Same(expectedContentRange, response.Content.Headers.ContentRange);
        }
Example #5
0
        public static HttpResponseMessage CreateErrorResponse(
            this HttpRequestMessage request,
            InvalidByteRangeException invalidByteRangeException
            )
        {
            if (invalidByteRangeException == null)
            {
                throw Error.ArgumentNull("invalidByteRangeException");
            }

            HttpResponseMessage rangeNotSatisfiableResponse = request.CreateErrorResponse(
                HttpStatusCode.RequestedRangeNotSatisfiable,
                invalidByteRangeException
                );

            rangeNotSatisfiableResponse.Content.Headers.ContentRange =
                invalidByteRangeException.ContentRange;
            return(rangeNotSatisfiableResponse);
        }
        public void CreateErrorResponseRangeNotSatisfiable_SetsCorrectStatusCodeAndContentRangeHeader()
        {
            // Arrange
            var context = new DefaultHttpContext();
            context.RequestServices = CreateServices(new DefaultContentNegotiator());

            var request = CreateRequest(context);

            var expectedContentRange = new ContentRangeHeaderValue(length: 128);
            var invalidByteRangeException = new InvalidByteRangeException(expectedContentRange);

            // Act
            var response = request.CreateErrorResponse(invalidByteRangeException);

            // Assert
            Assert.Equal(HttpStatusCode.RequestedRangeNotSatisfiable, response.StatusCode);
            Assert.Same(expectedContentRange, response.Content.Headers.ContentRange);
        }
        public void CreateErrorResponseRangeNotSatisfiable_SetsCorrectStatusCodeAndContentRangeHeader()
        {
            // Arrange
            HttpRequestMessage request = new HttpRequestMessage();
            ContentRangeHeaderValue expectedContentRange = new ContentRangeHeaderValue(length: 128);
            InvalidByteRangeException invalidByteRangeException = new InvalidByteRangeException(expectedContentRange);

            // Act
            HttpResponseMessage response = request.CreateErrorResponse(invalidByteRangeException);

            // Assert
            Assert.Equal(HttpStatusCode.RequestedRangeNotSatisfiable, response.StatusCode);
            Assert.Same(expectedContentRange, response.Content.Headers.ContentRange);
        }
 public void Ctor_SetsContentRange()
 {
     ContentRangeHeaderValue contentRange = new ContentRangeHeaderValue(0, 20, 100);
     InvalidByteRangeException invalidByteRangeException = new InvalidByteRangeException(contentRange);
     Assert.Same(contentRange, invalidByteRangeException.ContentRange);
 }