public void ValidateRequest_Throws_IfRequestIsNull()
        {
            // Arrange
            DefaultODataBatchHandler batchHandler = new DefaultODataBatchHandler();

            // Act & Assert
            ExceptionAssert.ThrowsArgumentNull(() => batchHandler.ValidateRequest(null), "request");
        }
Example #2
0
        public void ValidateRequest_Throws_IfResponsesIsNull()
        {
            DefaultODataBatchHandler batchHandler = new DefaultODataBatchHandler(new HttpServer());

            ExceptionAssert.ThrowsArgumentNull(
                () => batchHandler.ValidateRequest(null),
                "request");
        }
Example #3
0
        public async Task ValidateRequest_Throws_IfRequestContentIsNull()
        {
            DefaultODataBatchHandler batchHandler = new DefaultODataBatchHandler(new HttpServer());
            HttpRequestMessage       request      = new HttpRequestMessage();

            HttpResponseException errorResponse = ExceptionAssert.Throws <HttpResponseException>(
                () => batchHandler.ValidateRequest(request));

            Assert.Equal(HttpStatusCode.BadRequest, errorResponse.Response.StatusCode);
            Assert.Equal("The 'Content' property on the batch request cannot be null.",
                         (await errorResponse.Response.Content.ReadAsAsync <HttpError>()).Message);
        }
Example #4
0
        public async Task ValidateRequest_Throws_IfRequestContentTypeDoesNotHaveBoundary()
        {
            DefaultODataBatchHandler batchHandler = new DefaultODataBatchHandler(new HttpServer());
            HttpRequestMessage       request      = new HttpRequestMessage();

            request.Content = new StringContent(String.Empty);
            request.Content.Headers.ContentType = new MediaTypeHeaderValue("multipart/mixed");

            HttpResponseException errorResponse = ExceptionAssert.Throws <HttpResponseException>(
                () => batchHandler.ValidateRequest(request));

            Assert.Equal(HttpStatusCode.BadRequest, errorResponse.Response.StatusCode);
            Assert.Equal("The batch request must have a boundary specification in the \"Content-Type\" header.",
                         (await errorResponse.Response.Content.ReadAsAsync <HttpError>()).Message);
        }
Example #5
0
        public async Task ValidateRequest_Throws_IfRequestMediaTypeIsWrong()
        {
            DefaultODataBatchHandler batchHandler = new DefaultODataBatchHandler(new HttpServer());
            HttpRequestMessage       request      = new HttpRequestMessage();

            request.Content = new StringContent(String.Empty);
            request.Content.Headers.ContentType = new MediaTypeHeaderValue("text/json");

            HttpResponseException errorResponse = ExceptionAssert.Throws <HttpResponseException>(
                () => batchHandler.ValidateRequest(request));

            Assert.Equal(HttpStatusCode.BadRequest, errorResponse.Response.StatusCode);
            Assert.Equal("The batch request must have 'multipart/mixed' or 'application/json' as the media type.",
                         (await errorResponse.Response.Content.ReadAsAsync <HttpError>()).Message);
        }
Example #6
0
        public async Task ValidateRequest_Throws_IfRequestContentTypeIsNull()
        {
            DefaultODataBatchHandler batchHandler = new DefaultODataBatchHandler(new HttpServer());
            HttpRequestMessage       request      = new HttpRequestMessage();

            request.Content = new StringContent(String.Empty);
            request.Content.Headers.ContentType = null;

            HttpResponseException errorResponse = ExceptionAssert.Throws <HttpResponseException>(
                () => batchHandler.ValidateRequest(request));

            Assert.Equal(HttpStatusCode.BadRequest, errorResponse.Response.StatusCode);
            Assert.Equal("The batch request must have a \"Content-Type\" header.",
                         (await errorResponse.Response.Content.ReadAsAsync <HttpError>()).Message);
        }
        public async Task ValidateRequest_Throws_IfRequestContentTypeDoesNotHaveBoundary()
        {
            // Arrange
            DefaultODataBatchHandler batchHandler = new DefaultODataBatchHandler();
            HttpContext context = new DefaultHttpContext();

            context.Request.Body        = new MemoryStream();
            context.Request.ContentType = "multipart/mixed";
            context.Response.Body       = new MemoryStream();

            // Act
            await batchHandler.ValidateRequest(context.Request);

            // Assert
            Assert.Equal(StatusCodes.Status400BadRequest, context.Response.StatusCode);
            Assert.Equal("The batch request must have a boundary specification in the \"Content-Type\" header.", context.Response.ReadBody());
        }
        public async Task ValidateRequest_Throws_IfRequestMediaTypeIsWrong()
        {
            // Arrange
            DefaultODataBatchHandler batchHandler = new DefaultODataBatchHandler();
            HttpContext context = new DefaultHttpContext();

            context.Request.Body        = new MemoryStream();
            context.Request.ContentType = "text/json";
            context.Response.Body       = new MemoryStream();

            // Act
            await batchHandler.ValidateRequest(context.Request);

            // Assert
            Assert.Equal(StatusCodes.Status400BadRequest, context.Response.StatusCode);
            Assert.Equal("The batch request must have 'multipart/mixed' or 'application/json' as the media type.", context.Response.ReadBody());
        }
        public async Task ValidateRequest_GetBadResponse_IfRequestContentIsNull()
        {
            // Arrange
            DefaultODataBatchHandler batchHandler = new DefaultODataBatchHandler();
            HttpContext context = new DefaultHttpContext();
            HttpRequest request = context.Request;

            request.Body          = null;
            context.Response.Body = new MemoryStream();

            // Act
            await batchHandler.ValidateRequest(request);

            // Assert
            Assert.Equal(StatusCodes.Status400BadRequest, context.Response.StatusCode);
            Assert.Equal("The 'Body' property on the batch request cannot be null.", context.Response.ReadBody());
        }
        public async Task ValidateRequest_GetBadResponse_IfRequestContentTypeIsNull()
        {
            // Arrange
            DefaultODataBatchHandler batchHandler = new DefaultODataBatchHandler();
            HttpContext context = new DefaultHttpContext();
            HttpRequest request = context.Request;

            request.Body          = new MemoryStream();
            request.ContentType   = null;
            context.Response.Body = new MemoryStream();

            // Act
            await batchHandler.ValidateRequest(request);

            // Assert
            Assert.Equal(StatusCodes.Status400BadRequest, context.Response.StatusCode);
            Assert.Equal("The batch request must have a \"Content-Type\" header.", context.Response.ReadBody());
        }