public static async Task <IDictionary <string, object> > ReadODataBodyAsync(ModelBindingContext bindingContext)
        {
            ODataActionPayloadDeserializer deserializer = bindingContext.HttpContext.Request.GetSubServiceProvider().GetService <ODataActionPayloadDeserializer>();

            if (deserializer == null)
            {
                return(null);
            }

            ODataDeserializerContext context = BuildDeserializerContext(bindingContext);
            HttpRequest request = bindingContext.HttpContext.Request;

            var body = request.HttpContext.Features.Get <Http.Features.IHttpBodyControlFeature>();

            if (body != null)
            {
                body.AllowSynchronousIO = true;
            }

            IODataRequestMessage oDataRequestMessage =
                ODataMessageWrapperHelper.Create(request.Body, request.Headers);
            IEdmModel model = request.GetModel();

            using (var messageReader = new ODataMessageReader(oDataRequestMessage, null, model))
            {
                var result = await deserializer.ReadAsync(messageReader, typeof(ODataActionParameters), context).ConfigureAwait(false);

                return(result as ODataActionParameters);
            }
        }
        public async Task ReadAsync_ThrowsArgumentNull_MessageReader()
        {
            // Arrange
            ODataActionPayloadDeserializer deserializer = new ODataActionPayloadDeserializer(_deserializerProvider);

            // Act & Assert
            await ExceptionAssert.ThrowsArgumentNullAsync(
                () => deserializer.ReadAsync(messageReader: null, type: typeof(ODataActionParameters), readContext: new ODataDeserializerContext()),
                "messageReader");
        }
        public async Task ReadAsync_ThrowsArgumentNull_ReadContext()
        {
            // Arrange
            ODataActionPayloadDeserializer deserializer  = new ODataActionPayloadDeserializer(_deserializerProvider);
            ODataMessageReader             messageReader = ODataTestUtil.GetMockODataMessageReader();

            // Act & Assert
            await ExceptionAssert.ThrowsArgumentNullAsync(
                () => deserializer.ReadAsync(messageReader, typeof(ODataActionParameters), readContext: null),
                "readContext");
        }
        public async Task ReadAsync_Throws_SerializationException_ODataPathMissing()
        {
            // Arrange
            ODataActionPayloadDeserializer deserializer  = new ODataActionPayloadDeserializer(_deserializerProvider);
            ODataMessageReader             messageReader = ODataTestUtil.GetMockODataMessageReader();

            // Act & Assert
            await ExceptionAssert.ThrowsAsync <SerializationException>(
                () => deserializer.ReadAsync(messageReader, typeof(ODataActionParameters), readContext: new ODataDeserializerContext()),
                "The operation cannot be completed because no ODataPath is available for the request.");
        }