public async Task CreateResponseMessageAsync_Throws_IfResponsesAreNull() { DefaultODataBatchHandler batchHandler = new DefaultODataBatchHandler(new HttpServer()); HttpRequestMessage request = new HttpRequestMessage(); request.EnableHttpDependencyInjectionSupport(); await ExceptionAssert.ThrowsArgumentNullAsync( () => batchHandler.CreateResponseMessageAsync(null, request, CancellationToken.None), "responses"); }
public async Task CreateResponseMessageAsync_Throws_IfResponsesAreNull() { // Arrange DefaultODataBatchHandler batchHandler = new DefaultODataBatchHandler(); HttpContext context = new DefaultHttpContext(); context.ODataFeature().SubServiceProvider = _serviceProvider; HttpRequest request = context.Request; // Act & Assert await ExceptionAssert.ThrowsArgumentNullAsync(() => batchHandler.CreateResponseMessageAsync(null, request), "responses"); }
public void CreateResponseMessageAsync_ReturnsODataBatchContent() { DefaultODataBatchHandler batchHandler = new DefaultODataBatchHandler(new HttpServer()); ODataBatchResponseItem[] responses = new ODataBatchResponseItem[] { new OperationResponseItem(new HttpResponseMessage(HttpStatusCode.OK)) }; HttpResponseMessage response = batchHandler.CreateResponseMessageAsync(responses, new HttpRequestMessage(), CancellationToken.None).Result; var batchContent = Assert.IsType <ODataBatchContent>(response.Content); Assert.Equal(1, batchContent.Responses.Count()); }
public async Task CreateResponseMessageAsync_ReturnsODataBatchContent() { DefaultODataBatchHandler batchHandler = new DefaultODataBatchHandler(new HttpServer()); ODataBatchResponseItem[] responses = new ODataBatchResponseItem[] { new OperationResponseItem(new HttpResponseMessage(HttpStatusCode.OK)) }; HttpRequestMessage request = new HttpRequestMessage(); request.EnableHttpDependencyInjectionSupport(); HttpResponseMessage response = await batchHandler.CreateResponseMessageAsync(responses, request, CancellationToken.None); var batchContent = Assert.IsType <ODataBatchContent>(response.Content); Assert.Single(batchContent.Responses); }
public async Task CreateResponseMessageAsync_ReturnsODataBatchContent() { // Arrange DefaultODataBatchHandler batchHandler = new DefaultODataBatchHandler(); HttpRequest request = RequestFactory.Create(opt => opt.AddModel("odata", EdmCoreModel.Instance)); request.ODataFeature().PrefixName = "odata"; HttpContext httpContext = request.HttpContext; httpContext.Response.StatusCode = StatusCodes.Status200OK; httpContext.Response.Body = new MemoryStream(); ODataBatchResponseItem[] responses = new ODataBatchResponseItem[] { new OperationResponseItem(httpContext) }; // Act await batchHandler.CreateResponseMessageAsync(responses, request); // Assert string responseString = httpContext.Response.ReadBody(); Assert.Contains("200 OK", responseString); }