private async Task <Endpoint> GenerateCorsEndPoint(bool isOptionsRequest, bool includeMetadata)
        {
            // Arrange
            IEndpointRouteBuilder builder = EndpointRouteBuilderFactory.Create("odata",
                                                                               c => c.AddService(ServiceLifetime.Singleton, b => GetEdmModel()));

            HttpContext httpContext = new DefaultHttpContext
            {
                RequestServices = builder.ServiceProvider
            };

            var httpMethod = isOptionsRequest ? HttpMethod.Options : HttpMethod.Get;

            HttpRequest          request = SetHttpRequest(httpContext, httpMethod, "http://localhost:123/Customers(1)");
            RouteValueDictionary values  = new RouteValueDictionary();

            values.Add("ODataEndpointPath_odata", "Customers(1)");

            ActionDescriptor actionDescriptor = new ControllerActionDescriptor
            {
                ControllerName   = "Customers",
                ActionName       = "Get",
                EndpointMetadata = GenerateMetadata(includeMetadata)
            };

            IActionSelector actionSelector = new MockActionSelector(actionDescriptor);

            ODataEndpointRouteValueTransformer transformer = new ODataEndpointRouteValueTransformer(actionSelector);
            await transformer.TransformAsync(httpContext, values);

            return(httpContext.GetEndpoint());
        }
        public void TransformAsyncReturnsCorrectRouteValues()
        {
            // Arrange
            IEndpointRouteBuilder builder = EndpointRouteBuilderFactory.Create("odata",
                                                                               c => c.AddService(ServiceLifetime.Singleton, b => GetEdmModel()));

            HttpContext httpContext = new DefaultHttpContext
            {
                RequestServices = builder.ServiceProvider
            };

            HttpRequest          request = SetHttpRequest(httpContext, HttpMethod.Get, "http://localhost:123/Customers(1)");
            RouteValueDictionary values  = new RouteValueDictionary();

            values.Add("ODataEndpointPath_odata", "Customers(1)");

            ActionDescriptor actionDescriptor = new ControllerActionDescriptor
            {
                ControllerName = "Customers",
                ActionName     = "Get"
            };
            IActionSelector actionSelector = new MockActionSelector(actionDescriptor);

            // Act
            ODataEndpointRouteValueTransformer transformer = new ODataEndpointRouteValueTransformer(actionSelector);
            ValueTask <RouteValueDictionary>   actual      = transformer.TransformAsync(httpContext, values);

            // Assert
            Assert.NotNull(actual.Result);
            RouteValueDictionary routeValues = actual.Result;

            Assert.Equal(4, routeValues.Count);
            Assert.Equal("Customers(1)", routeValues["ODataEndpointPath_odata"]);
            Assert.Equal("Customers", routeValues["controller"]);
            Assert.Equal("Get", routeValues["action"]);
            Assert.Equal("Customers(1)", routeValues["odataPath"]);

            Assert.NotNull(httpContext.ODataFeature().Path);
            Assert.Same(actionDescriptor, httpContext.ODataFeature().ActionDescriptor);
        }