Exemplo n.º 1
0
        public async void InvokeQueryRequestMiddleware_Transforms_ODataQueryRequest()
        {
            // Arrange
            RequestDelegate next = c => Task.CompletedTask;

            IODataQueryRequestParser[] parsers = new IODataQueryRequestParser[]
            {
                new DefaultODataQueryRequestParser()
            };

            ODataQueryRequestMiddleware middleware = new ODataQueryRequestMiddleware(parsers, next);

            HttpContext context = new DefaultHttpContext();
            HttpRequest request = context.Request;

            context.Request.Path = new PathString("/$query");
            request.ContentType  = "text/plain";
            request.Method       = "Post";
            context.Request.Body = new MemoryStream(Encoding.UTF8.GetBytes("$filter=Id le 5"));

            // Act
            await middleware.Invoke(context);

            // Assert
            Assert.Equal("Get", request.Method, ignoreCase: true);
            Assert.Equal("?$filter=Id le 5", request.QueryString.Value);
        }
Exemplo n.º 2
0
        public void InvokeQueryRequestMiddleware_ThrowsArgumentNull_Context()
        {
            // Arrange
            ODataQueryRequestMiddleware middleware = new ODataQueryRequestMiddleware(null, null);

            // Act & Assert
            ExceptionAssert.ThrowsArgumentNull(() => middleware.Invoke(context: null).Wait(), "context");
        }