コード例 #1
0
        public void SelectAction_ReturnsTheActionName_ForValidHttpMethods(string httpMethod, string httpMethodNamePrefix)
        {
            // Arrange
            const string SingletonName          = "VipCustomer";
            string       actionName             = httpMethodNamePrefix + SingletonName;
            CustomersModelWithInheritance model = new CustomersModelWithInheritance();
            ODataPath odataPath = new DefaultODataPathHandler().Parse(model.Model, _serviceRoot, SingletonName);
            var       request   = RequestFactory.Create(new HttpMethod(httpMethod), "http://localhost/");
            var       actionMap = SelectActionHelper.CreateActionMap(actionName);

            // Act
            string selectedAction = SelectActionHelper.SelectAction(new SingletonRoutingConvention(), odataPath, request, actionMap);

            // Assert
            Assert.NotNull(selectedAction);
            Assert.Equal(actionName, selectedAction);
            Assert.Empty(SelectActionHelper.GetRouteData(request).Values);
        }
コード例 #2
0
        public void SelectAction_OnSingletonPath_Returns_ExpectedMethodOnBaseType(string method, string[] methodsInController,
                                                                                  string expectedSelectedAction)
        {
            // Arrange
            CustomersModelWithInheritance model = new CustomersModelWithInheritance();
            var       ordersProperty            = model.Customer.FindProperty("Orders") as IEdmNavigationProperty;
            ODataPath odataPath = new ODataPath(new SingletonSegment(model.VipCustomer),
                                                new NavigationPropertySegment(ordersProperty, model.Orders));
            var request   = RequestFactory.Create(new HttpMethod(method), "http://localhost/");
            var actionMap = SelectActionHelper.CreateActionMap(methodsInController);

            // Act
            string selectedAction = SelectActionHelper.SelectAction(new NavigationRoutingConvention(), odataPath, request, actionMap);

            // Assert
            Assert.Equal(expectedSelectedAction, selectedAction);
            Assert.Empty(SelectActionHelper.GetRouteData(request).Values);
        }
コード例 #3
0
        public void SelectAction_ReturnsNull_ForNonDeleteRequestWithDollarId(string method)
        {
            // Arrange
            CustomersModelWithInheritance model = new CustomersModelWithInheritance();

            ODataPath odataPath = new DefaultODataPathHandler().Parse(
                model.Model,
                "http://any/",
                "http://any/Customers(42)/Orders/$ref?$id=http://any/Orders(24)");

            var request   = RequestFactory.Create(new HttpMethod(method), "http://localhost/");
            var actionMap = SelectActionHelper.CreateActionMap("DeleteRef", "CreateRef", "GetRef", "PutRef", "PostRef");

            // Act
            string selectedAction = SelectActionHelper.SelectAction(new RefRoutingConvention(), odataPath, request, actionMap);

            // Assert
            Assert.Null(selectedAction);
        }
コード例 #4
0
        public void SelectAction_ReturnsTheActionName_DollarCount()
        {
            // Arrange
            IEdmModel model     = ODataCountTest.GetEdmModel();
            ODataPath odataPath = new DefaultODataPathHandler().Parse(
                model, _serviceRoot, "DollarCountEntities(7)/EnumCollectionProp/$count");

            var request   = RequestFactory.Create(HttpMethod.Get, "http://localhost/");
            var actionMap = SelectActionHelper.CreateActionMap("GetEnumCollectionPropFromDollarCountEntity");

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

            // Assert
            Assert.NotNull(selectedAction);
            Assert.Equal("GetEnumCollectionPropFromDollarCountEntity", selectedAction);
            Assert.Single(SelectActionHelper.GetRouteData(request).Values);
            Assert.Equal(7, SelectActionHelper.GetRouteData(request).Values["key"]);
        }
コード例 #5
0
        public void SelectAction_WithCast_Returns_ExpectedActionName(string method, string expected)
        {
            // Arrange
            CustomersModelWithInheritance model = new CustomersModelWithInheritance();

            IEdmCollectionType collection = new EdmCollectionType(new EdmEntityTypeReference(model.SpecialCustomer, isNullable: false));

            ODataPath odataPath = new ODataPath(new EntitySetSegment(model.Customers),
                                                new TypeSegment(collection, model.Customers));

            var request   = RequestFactory.Create(new HttpMethod(method), "http://localhost/");
            var actionMap = SelectActionHelper.CreateActionMap(expected);

            // Act
            string selectedAction = SelectActionHelper.SelectAction(new EntitySetRoutingConvention(), odataPath, request, actionMap);

            // Assert
            Assert.Equal(expected, selectedAction);
        }
コード例 #6
0
        public void SelectAction_ReturnsNull_IfToCollectionValuedNavigationProperty(string method)
        {
            // Arrange
            CustomersModelWithInheritance model = new CustomersModelWithInheritance();
            var ordersProperty = model.Customer.FindProperty("Orders") as IEdmNavigationProperty;

            var       keys      = new[] { new KeyValuePair <string, object>("ID", 42) };
            ODataPath odataPath = new ODataPath(new EntitySetSegment(model.Customers), new KeySegment(keys, model.Customer, model.Customers),
                                                new NavigationPropertySegment(ordersProperty, model.Orders));

            var request        = RequestFactory.Create(new HttpMethod(method), "http://localhost/");
            var emptyActionMap = SelectActionHelper.CreateActionMap();

            // Act
            string selectedAction = SelectActionHelper.SelectAction(new NavigationRoutingConvention(), odataPath, request, emptyActionMap);

            // Assert
            Assert.Null(selectedAction);
        }
コード例 #7
0
        public void SelectAction_OnSingltonPath_OpenEntityType_ReturnsTheActionName(string url)
        {
            // Arrange
            CustomersModelWithInheritance model = new CustomersModelWithInheritance();
            ODataPath odataPath = new DefaultODataPathHandler().Parse(model.Model, "http://localhost/", url);
            var       request   = RequestFactory.Create(HttpMethod.Get, "http://localhost/");
            var       actionMap = SelectActionHelper.CreateActionMap("GetDynamicProperty");

            // Act
            string selectedAction = SelectActionHelper.SelectAction(_routingConvention, odataPath, request, actionMap);

            // Assert
            Assert.NotNull(selectedAction);
            Assert.Equal("GetDynamicProperty", selectedAction);

            var routeData = SelectActionHelper.GetRouteData(request);

            Assert.Equal(2, routeData.Values.Count);
            Assert.Equal("DynamicPropertyA", routeData.Values["dynamicProperty"]);
            Assert.Equal("DynamicPropertyA", (routeData.Values[ODataParameterValue.ParameterValuePrefix + "dynamicProperty"] as ODataParameterValue).Value);
        }
コード例 #8
0
        public void SelectAction_ReturnsNull_NotSupportedMethodForDollarCount(string method, string[] methodsInController)
        {
            // Arrange
            var keys = new[] { new KeyValuePair <string, object>("ID", 42) };
            CustomersModelWithInheritance model = new CustomersModelWithInheritance();
            var specialOrdersProperty           = model.SpecialCustomer.FindProperty("SpecialOrders") as IEdmNavigationProperty;

            ODataPath odataPath = new ODataPath(new EntitySetSegment(model.Customers), new KeySegment(keys, model.Customer, model.Customers),
                                                new TypeSegment(model.SpecialCustomer, model.Customers),
                                                new NavigationPropertySegment(specialOrdersProperty, model.Orders),
                                                CountSegment.Instance);

            var request   = RequestFactory.Create(new HttpMethod(method), "http://localhost/");
            var actionMap = SelectActionHelper.CreateActionMap(methodsInController);

            // Act
            string selectedAction = SelectActionHelper.SelectAction(new NavigationRoutingConvention(), odataPath, request, actionMap);

            // Assert
            Assert.Null(selectedAction);
        }
コード例 #9
0
        public void SelectAction_Returns_DollarCount(string method, string[] methodsInController,
                                                     string expectedSelectedAction)
        {
            // Arrange
            var keys = new[] { new KeyValuePair <string, object>("ID", 42) };
            CustomersModelWithInheritance model = new CustomersModelWithInheritance();
            var       ordersProperty            = model.Customer.FindProperty("Orders") as IEdmNavigationProperty;
            ODataPath odataPath = new ODataPath(new EntitySetSegment(model.Customers), new KeySegment(keys, model.Customer, model.Customers),
                                                new NavigationPropertySegment(ordersProperty, model.Orders), CountSegment.Instance);

            var request   = RequestFactory.Create(new HttpMethod(method), "http://localhost/");
            var actionMap = SelectActionHelper.CreateActionMap(methodsInController);

            // Act
            string selectedAction = SelectActionHelper.SelectAction(new NavigationRoutingConvention(), odataPath, request, actionMap);

            // Assert
            Assert.Equal(expectedSelectedAction, selectedAction);
            Assert.Single(SelectActionHelper.GetRouteData(request).Values);
            Assert.Equal(42, SelectActionHelper.GetRouteData(request).Values["key"]);
        }
コード例 #10
0
        public void SelectAction_ReturnsNull_IfPostToNavigationPropertyBindingToNonCollectionValuedNavigationProperty(string path)
        {
            // Arrange
            ODataConventionModelBuilder builder = ODataConventionModelBuilderFactory.Create();

            builder.EntitySet <Company>("Companies");
            builder.Singleton <Company>("MyCompany");
            builder.EntitySet <Employee>("Employees");
            builder.Singleton <Employee>("Tony");
            IEdmModel model = builder.GetEdmModel();

            ODataPath odataPath      = new DefaultODataPathHandler().Parse(model, "http://any/", path);
            var       request        = RequestFactory.Create(HttpMethod.Post, "http://localhost/");
            var       emptyActionMap = SelectActionHelper.CreateActionMap();

            // Act
            string selectedAction = SelectActionHelper.SelectAction(new NavigationRoutingConvention(), odataPath, request, emptyActionMap);

            // Assert
            Assert.Null(selectedAction);
        }
コード例 #11
0
        public void SelectAction_SetsRouteData_ForGetOrCreateRefRequests(string method, string actionName)
        {
            // Arrange
            var keys = new[] { new KeyValuePair <string, object>("ID", 42) };
            CustomersModelWithInheritance model = new CustomersModelWithInheritance();
            var specialOrdersProperty           = model.SpecialCustomer.FindProperty("SpecialOrders") as IEdmNavigationProperty;

            ODataPath odataPath = new ODataPath(
                new EntitySetSegment(model.Customers),
                new KeySegment(keys, model.Customer, model.Customers),
                new TypeSegment(model.SpecialCustomer, model.Customers),
                new NavigationPropertyLinkSegment(specialOrdersProperty, model.Orders));

            var request   = RequestFactory.Create(new HttpMethod(method), "http://localhost/");
            var actionMap = SelectActionHelper.CreateActionMap(actionName);

            // Act
            string selectedAction = SelectActionHelper.SelectAction(new RefRoutingConvention(), odataPath, request, actionMap);

            // Assert
            Assert.Equal(42, SelectActionHelper.GetRouteData(request).Values["key"]);
            Assert.Equal("SpecialOrders", SelectActionHelper.GetRouteData(request).Values["navigationProperty"]);
        }