コード例 #1
0
        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");
        }
コード例 #2
0
        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");
        }
コード例 #3
0
        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());
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }