public async Task BatchMiddlewareShouldNotHandlePreflightRequests()
        {
            var request = CreateRequest(HttpMethod.Options);

            await _batchMiddleware.Invoke(request.HttpContext);

            Assert.True(request.HttpContext.Items.ContainsKey("TestKey"));
        }
Esempio n. 2
0
        public async Task Invoke_CallProcessBatchAsync_WithBatchHandler()
        {
            // Arrange
            bool            called = false;
            RequestDelegate next   = context =>
            {
                called = true;
                return(Task.CompletedTask);
            };
            Mock <ODataBatchHandler> batchHandlerMock = new Mock <ODataBatchHandler>();

            bool processed = false;

            batchHandlerMock.Setup(b => b.ProcessBatchAsync(It.IsAny <HttpContext>(), It.IsAny <RequestDelegate>()))
            .Returns(() =>
            {
                processed = true;
                return(Task.CompletedTask);
            });

            IServiceProvider     sp         = BuildServiceProvider(opt => opt.AddModel("odata", EdmCoreModel.Instance, batchHandlerMock.Object));
            ODataBatchMiddleware middleware = new ODataBatchMiddleware(sp, next.Invoke);
            HttpContext          context    = new DefaultHttpContext();

            context.Request.Path = new PathString("/odata/$batch");

            // Act
            Assert.False(called);
            Assert.False(processed);
            await middleware.Invoke(context);

            // Assert
            Assert.False(called);
            Assert.True(processed);
        }
Esempio n. 3
0
        public async Task Invoke_CallNextDelegate_WithoutBatchHandler()
        {
            // Arrange
            bool            called = false;
            RequestDelegate next   = context =>
            {
                called = true;
                return(Task.CompletedTask);
            };

            ODataBatchMiddleware middleware = new ODataBatchMiddleware(null, next.Invoke);
            HttpContext          context    = new DefaultHttpContext();

            // Act
            Assert.False(called);
            await middleware.Invoke(context);

            // Assert
            Assert.True(called);
        }