Example #1
0
        public void SelectAction_ReturnsNull_IfPatchToCollectionProperty()
        {
            // Arrange
            IEdmModel model     = ODataCountTest.GetEdmModel();
            ODataPath odataPath = new DefaultODataPathHandler().Parse(model, _serviceRoot, "DollarCountEntities(7)/EnumCollectionProp");
            ILookup <string, HttpActionDescriptor> emptyActionMap = new HttpActionDescriptor[0].ToLookup(desc => "PatchToEnumCollectionProp");
            HttpRequestContext    requestContext    = new HttpRequestContext();
            HttpControllerContext controllerContext = new HttpControllerContext
            {
                Request        = new HttpRequestMessage(new HttpMethod("Patch"), "http://localhost/"),
                RequestContext = requestContext,
                RouteData      = new HttpRouteData(new HttpRoute())
            };

            controllerContext.Request.SetRequestContext(requestContext);

            // Act
            string selectedAction = new PropertyRoutingConvention().SelectAction(odataPath, controllerContext, emptyActionMap);

            // Assert
            Assert.Null(selectedAction);
            Assert.Empty(controllerContext.Request.GetRouteData().Values);
        }
Example #2
0
        public void SelectAction_ReturnsNull_IfActionIsMissing()
        {
            // Arrange
            CustomersModelWithInheritance model = new CustomersModelWithInheritance();
            ODataPath odataPath = new DefaultODataPathHandler().Parse(model.Model, _serviceRoot, "Customers(10)/Name");
            ILookup <string, HttpActionDescriptor> emptyActionMap = new HttpActionDescriptor[0].ToLookup(desc => (string)null);
            HttpRequestContext    requestContext    = new HttpRequestContext();
            HttpControllerContext controllerContext = new HttpControllerContext
            {
                Request        = new HttpRequestMessage(HttpMethod.Get, "http://localhost/"),
                RequestContext = requestContext,
                RouteData      = new HttpRouteData(new HttpRoute())
            };

            controllerContext.Request.SetRequestContext(requestContext);

            // Act
            string selectedAction = new PropertyRoutingConvention().SelectAction(odataPath, controllerContext, emptyActionMap);

            // Assert
            Assert.Null(selectedAction);
            Assert.Empty(controllerContext.Request.GetRouteData().Values);
        }
        public void SelectAction_OnSingletonPath_ReturnsTheActionNameWithCast(string httpMethod, string prefix)
        {
            // Arrange
            CustomersModelWithInheritance model = new CustomersModelWithInheritance();
            ODataPath odataPath = new DefaultODataPathHandler().Parse(model.Model, _serviceRoot, "VipCustomer/Account/NS.SpecialAccount");
            ILookup <string, HttpActionDescriptor> actionMap = new HttpActionDescriptor[1].ToLookup(desc => prefix + "AccountOfSpecialAccountFromCustomer");
            HttpRequestContext    requestContext             = new HttpRequestContext();
            HttpControllerContext controllerContext          = new HttpControllerContext
            {
                Request        = new HttpRequestMessage(new HttpMethod(httpMethod), "http://localhost/"),
                RequestContext = requestContext,
                RouteData      = new HttpRouteData(new HttpRoute())
            };

            controllerContext.Request.SetRequestContext(requestContext);

            // Act
            string selectedAction = new PropertyRoutingConvention().SelectAction(odataPath, controllerContext, actionMap);

            // Assert
            Assert.NotNull(selectedAction);
            Assert.Equal(prefix + "AccountOfSpecialAccountFromCustomer", selectedAction);
            Assert.Empty(controllerContext.Request.GetRouteData().Values);
        }
        public void SelectAction_OnEntitySetPath_ReturnsTheActionName(string httpMethod, string prefix)
        {
            // Arrange
            CustomersModelWithInheritance model = new CustomersModelWithInheritance();
            ODataPath odataPath = new DefaultODataPathHandler().Parse(model.Model, _serviceRoot, "Customers(7)/Name");
            ILookup<string, HttpActionDescriptor> actionMap = new HttpActionDescriptor[1].ToLookup(desc => prefix + "NameFromCustomer");
            HttpRequestContext requestContext = new HttpRequestContext();
            HttpControllerContext controllerContext = new HttpControllerContext
            {
                Request = new HttpRequestMessage(new HttpMethod(httpMethod), "http://localhost/"),
                RequestContext = requestContext,
                RouteData = new HttpRouteData(new HttpRoute())
            };
            controllerContext.Request.SetRequestContext(requestContext);

            // Act
            string selectedAction = new PropertyRoutingConvention().SelectAction(odataPath, controllerContext, actionMap);

            // Assert
            Assert.NotNull(selectedAction);
            Assert.Equal(prefix + "NameFromCustomer", selectedAction);
            Assert.Equal(1, controllerContext.Request.GetRouteData().Values.Count);
            Assert.Equal("7", controllerContext.Request.GetRouteData().Values["key"]);
        }
        public void SelectAction_ReturnsNull_IfPatchToCollectionProperty()
        {
            // Arrange
            IEdmModel model = ODataCountTest.GetEdmModel();
            ODataPath odataPath = new DefaultODataPathHandler().Parse(model, _serviceRoot, "DollarCountEntities(7)/EnumCollectionProp");
            ILookup<string, HttpActionDescriptor> emptyActionMap = new HttpActionDescriptor[0].ToLookup(desc => "PatchToEnumCollectionProp");
            HttpRequestContext requestContext = new HttpRequestContext();
            HttpControllerContext controllerContext = new HttpControllerContext
            {
                Request = new HttpRequestMessage(new HttpMethod("Patch"), "http://localhost/"),
                RequestContext = requestContext,
                RouteData = new HttpRouteData(new HttpRoute())
            };
            controllerContext.Request.SetRequestContext(requestContext);

            // Act
            string selectedAction = new PropertyRoutingConvention().SelectAction(odataPath, controllerContext, emptyActionMap);

            // Assert
            Assert.Null(selectedAction);
            Assert.Empty(controllerContext.Request.GetRouteData().Values);
        }
        public void SelectAction_ReturnsNull_IfActionIsMissing()
        {
            // Arrange
            CustomersModelWithInheritance model = new CustomersModelWithInheritance();
            ODataPath odataPath = new DefaultODataPathHandler().Parse(model.Model, _serviceRoot, "Customers(10)/Name");
            ILookup<string, HttpActionDescriptor> emptyActionMap = new HttpActionDescriptor[0].ToLookup(desc => (string)null);
            HttpRequestContext requestContext = new HttpRequestContext();
            HttpControllerContext controllerContext = new HttpControllerContext
            {
                Request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/"),
                RequestContext = requestContext,
                RouteData = new HttpRouteData(new HttpRoute())
            };
            controllerContext.Request.SetRequestContext(requestContext);

            // Act
            string selectedAction = new PropertyRoutingConvention().SelectAction(odataPath, controllerContext, emptyActionMap);

            // Assert
            Assert.Null(selectedAction);
            Assert.Empty(controllerContext.Request.GetRouteData().Values);
        }
        public void SelectAction_ReturnsTheActionName_DollarCount()
        {
            // Arrange
            IEdmModel model = ODataCountTest.GetEdmModel();
            ODataPath odataPath = new DefaultODataPathHandler().Parse(
                model, _serviceRoot, "DollarCountEntities(7)/EnumCollectionProp/$count");
            ILookup<string, HttpActionDescriptor> actionMap =
                new HttpActionDescriptor[1].ToLookup(desc => "GetEnumCollectionPropFromDollarCountEntity");
            HttpRequestContext requestContext = new HttpRequestContext();
            HttpControllerContext controllerContext = new HttpControllerContext
            {
                Request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/"),
                RequestContext = requestContext,
                RouteData = new HttpRouteData(new HttpRoute())
            };
            controllerContext.Request.SetRequestContext(requestContext);

            // Act
            string selectedAction = new PropertyRoutingConvention().SelectAction(odataPath, controllerContext, actionMap);

            // Assert
            Assert.NotNull(selectedAction);
            Assert.Equal("GetEnumCollectionPropFromDollarCountEntity", selectedAction);
            Assert.Equal(1, controllerContext.Request.GetRouteData().Values.Count);
            Assert.Equal("7", controllerContext.Request.GetRouteData().Values["key"]);
        }
        public void SelectAction_OnSingletonPath_ReturnsTheActionName()
        {
            // Arrange
            CustomersModelWithInheritance model = new CustomersModelWithInheritance();
            ODataPath odataPath = new DefaultODataPathHandler().Parse(model.Model, "VipCustomer/Address");
            ILookup<string, HttpActionDescriptor> actionMap = new HttpActionDescriptor[1].ToLookup(desc => "GetAddress");
            HttpRequestContext requestContext = new HttpRequestContext();
            HttpControllerContext controllerContext = new HttpControllerContext
            {
                Request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/"),
                RequestContext = requestContext,
                RouteData = new HttpRouteData(new HttpRoute())
            };
            controllerContext.Request.SetRequestContext(requestContext);

            // Act
            string selectedAction = new PropertyRoutingConvention().SelectAction(odataPath, controllerContext, actionMap);

            // Assert
            Assert.NotNull(selectedAction);
            Assert.Equal("GetAddress", selectedAction);
            Assert.Empty(controllerContext.Request.GetRouteData().Values);
        }