public async Task ParseBatchRequestsAsync_Returns_RequestsFromMultipartContent() { DefaultODataBatchHandler batchHandler = new DefaultODataBatchHandler(new HttpServer()); HttpRequestMessage batchRequest = new HttpRequestMessage(HttpMethod.Post, "http://example.com/$batch") { Content = new MultipartContent("mixed") { ODataBatchRequestHelper.CreateODataRequestContent(new HttpRequestMessage(HttpMethod.Get, "http://example.com/")), new MultipartContent("mixed") // ChangeSet { ODataBatchRequestHelper.CreateODataRequestContent(new HttpRequestMessage(HttpMethod.Post, "http://example.com/values")) } } }; batchRequest.EnableHttpDependencyInjectionSupport(); IList <ODataBatchRequestItem> requests = await batchHandler.ParseBatchRequestsAsync(batchRequest, CancellationToken.None); Assert.Equal(2, requests.Count); var operationRequest = ((OperationRequestItem)requests[0]).Request; Assert.Equal(HttpMethod.Get, operationRequest.Method); Assert.Equal("http://example.com/", operationRequest.RequestUri.AbsoluteUri); var changeSetRequest = ((ChangeSetRequestItem)requests[1]).Requests.First(); Assert.Equal(HttpMethod.Post, changeSetRequest.Method); Assert.Equal("http://example.com/values", changeSetRequest.RequestUri.AbsoluteUri); }
public async Task ParseBatchRequestsAsync_Throws_IfRequestIsNull() { DefaultODataBatchHandler batchHandler = new DefaultODataBatchHandler(new HttpServer()); await ExceptionAssert.ThrowsArgumentNullAsync( () => batchHandler.ParseBatchRequestsAsync(null, CancellationToken.None), "request"); }
public async Task ParseBatchRequestsAsync_Throws_IfRequestIsNull() { // Arrange DefaultODataBatchHandler batchHandler = new DefaultODataBatchHandler(); // Act & Assert await ExceptionAssert.ThrowsArgumentNullAsync(() => batchHandler.ParseBatchRequestsAsync(null), "context"); }
public void ParseBatchRequestsAsync_Throws_IfRequestIsNull() { DefaultODataBatchHandler batchHandler = new DefaultODataBatchHandler(new HttpServer()); Assert.ThrowsArgumentNull( () => batchHandler.ParseBatchRequestsAsync(null, CancellationToken.None).Wait(), "request"); }
public async Task ParseBatchRequestsAsync_CopiesPropertiesFromRequest_WithoutExcludedProperties() { DefaultODataBatchHandler batchHandler = new DefaultODataBatchHandler(new HttpServer()); HttpRequestMessage batchRequest = new HttpRequestMessage(HttpMethod.Post, "http://example.com/$batch") { Content = new MultipartContent("mixed") { ODataBatchRequestHelper.CreateODataRequestContent(new HttpRequestMessage(HttpMethod.Get, "http://example.com/")), new MultipartContent("mixed") // ChangeSet { ODataBatchRequestHelper.CreateODataRequestContent(new HttpRequestMessage(HttpMethod.Post, "http://example.com/values")) } } }; batchRequest.Properties.Add("foo", "bar"); batchRequest.SetRouteData(new HttpRouteData(new HttpRoute())); batchRequest.RegisterForDispose(new StringContent(String.Empty)); batchRequest.EnableHttpDependencyInjectionSupport(); IList <ODataBatchRequestItem> requests = await batchHandler.ParseBatchRequestsAsync(batchRequest, CancellationToken.None); Assert.Equal(2, requests.Count); var operationRequest = ((OperationRequestItem)requests[0]).Request; Assert.Equal(HttpMethod.Get, operationRequest.Method); Assert.Equal("http://example.com/", operationRequest.RequestUri.AbsoluteUri); Assert.Equal("bar", operationRequest.Properties["foo"]); Assert.Null(operationRequest.GetRouteData()); Assert.Same(operationRequest, operationRequest.GetUrlHelper().Request); Assert.Empty(operationRequest.GetResourcesForDisposal()); var changeSetRequest = ((ChangeSetRequestItem)requests[1]).Requests.First(); Assert.Equal(HttpMethod.Post, changeSetRequest.Method); Assert.Equal("http://example.com/values", changeSetRequest.RequestUri.AbsoluteUri); Assert.Equal("bar", changeSetRequest.Properties["foo"]); Assert.Null(changeSetRequest.GetRouteData()); Assert.Same(operationRequest, operationRequest.GetUrlHelper().Request); Assert.Empty(changeSetRequest.GetResourcesForDisposal()); }
public async Task ParseBatchRequestsAsync_CopiesPropertiesFromRequest_WithoutExcludedProperties() { // Arrange DefaultODataBatchHandler batchHandler = new DefaultODataBatchHandler(); string batchRequest = @" --7289e6c2-adbd-4dd8-bfb1-f36099442947 Content-Type: application/http Content-Transfer-Encoding: binary Content-ID: 1430195875 GET / HTTP/1.1 Host: example.com --7289e6c2-adbd-4dd8-bfb1-f36099442947 Content-Type: multipart/mixed;boundary=e58fa556-67f1-4180-b04e-e28df22ac4d9 --e58fa556-67f1-4180-b04e-e28df22ac4d9 Content-Type: application/http Content-Transfer-Encoding: binary Content-ID: 675766617 POST /values HTTP/1.1 Host: example.com --e58fa556-67f1-4180-b04e-e28df22ac4d9-- --7289e6c2-adbd-4dd8-bfb1-f36099442947-- "; HttpContext httpContext = HttpContextHelper.Create("Post", "http://example.com/$batch"); byte[] requestBytes = Encoding.UTF8.GetBytes(batchRequest); httpContext.Request.Body = new MemoryStream(requestBytes); httpContext.Request.ContentType = "multipart/mixed;boundary=7289e6c2-adbd-4dd8-bfb1-f36099442947"; httpContext.Request.ContentLength = requestBytes.Length; IEdmModel model = new EdmModel(); httpContext.ODataFeature().PrefixName = "odata"; httpContext.RequestServices = BuildServiceProvider(opt => opt.AddModel("odata", model)); httpContext.Response.Body = new MemoryStream(); batchHandler.PrefixName = "odata"; httpContext.Features[typeof(DefaultODataBatchHandlerTest)] = "bar"; // Act IList <ODataBatchRequestItem> requests = await batchHandler.ParseBatchRequestsAsync(httpContext); // Assert Assert.Equal(2, requests.Count); var operationContext = ((OperationRequestItem)requests[0]).Context; Assert.Equal("GET", operationContext.Request.Method); Assert.Equal("http://example.com/", operationContext.Request.GetDisplayUrl()); Assert.Equal("bar", operationContext.Features[typeof(DefaultODataBatchHandlerTest)]); var changeSetContext = ((ChangeSetRequestItem)requests[1]).Contexts.First(); Assert.Equal("POST", changeSetContext.Request.Method); Assert.Equal("http://example.com/values", changeSetContext.Request.GetDisplayUrl()); Assert.Equal("bar", operationContext.Features[typeof(DefaultODataBatchHandlerTest)]); }