Beispiel #1
0
        public void SelectAction_SetsRelatedKey_ForDeleteRefRequests()
        {
            // Arrange
            var keys        = new[] { new KeyValuePair <string, object>("ID", 42) };
            var relatedKeys = new[] { new KeyValuePair <string, object>("ID", 24) };
            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),
                new KeySegment(relatedKeys, model.Order, model.Orders));

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

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

            // Assert
            Assert.Equal(42, SelectActionHelper.GetRouteData(request).Values["key"]);
            Assert.Equal(42, SelectActionHelper.GetRouteData(request).Values["keyID"]);
            Assert.Equal("SpecialOrders", SelectActionHelper.GetRouteData(request).Values["navigationProperty"]);
            Assert.Equal(24, SelectActionHelper.GetRouteData(request).Values["relatedKey"]);
            Assert.Equal(24, SelectActionHelper.GetRouteData(request).Values["relatedKeyID"]);
        }
Beispiel #2
0
        public void SelectAction_OnEntitySetPath_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);
            var routingConventionsStore = SelectActionHelper.GetRoutingConventionsStore(request);

            Assert.Equal(4, routeData.Values.Count);
            Assert.Equal(7, routeData.Values["key"]);
            Assert.Equal(7, routeData.Values["keyID"]);
            Assert.Equal(1, routingConventionsStore[ODataRouteConstants.KeyCount]);
            Assert.Equal("DynamicPropertyA", routeData.Values["dynamicProperty"]);
            Assert.Equal("DynamicPropertyA", (routeData.Values[ODataParameterValue.ParameterValuePrefix + "dynamicProperty"] as ODataParameterValue).Value);
        }
Beispiel #3
0
        public void SelectAction_Returns_ExpectedMethodOnDerivedType(string method, string[] methodsInController,
                                                                     string expectedSelectedAction)
        {
            // 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(methodsInController);

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

            // Assert
            Assert.Equal(expectedSelectedAction, selectedAction);
            if (expectedSelectedAction == null)
            {
                Assert.Empty(SelectActionHelper.GetRouteData(request).Values);
            }
            else
            {
                Assert.Equal(3, SelectActionHelper.GetRouteData(request).Values.Count);
                Assert.Equal(42, SelectActionHelper.GetRouteData(request).Values["key"]);
                Assert.Equal(42, SelectActionHelper.GetRouteData(request).Values["keyID"]);
                Assert.Equal(specialOrdersProperty.Name, SelectActionHelper.GetRouteData(request).Values["navigationProperty"]);
                Assert.Equal(2, SelectActionHelper.GetRoutingConventionsStore(request)[ODataRouteConstants.KeyCount]);
            }
        }
        public void SelectAction_OnEntitySetPath_Returns_ExpectedMethodOnBaseType(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));
            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);
            if (expectedSelectedAction == null)
            {
                Assert.Empty(SelectActionHelper.GetRouteData(request).Values);
            }
            else
            {
                Assert.Single(SelectActionHelper.GetRouteData(request).Values);
                Assert.Equal(42, SelectActionHelper.GetRouteData(request).Values["key"]);
            }
        }
        public void SelectAction_ReturnsNull_RequestMethodIsNotPost(string requestMethod)
        {
            // Arrange
            ODataPath odataPath      = new ODataPath();
            var       request        = RequestFactory.Create(new HttpMethod(requestMethod), "http://localhost/");
            var       emptyActionMap = SelectActionHelper.CreateActionMap();

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

            // Assert
            Assert.Null(selectedAction);
        }
        public void SelectAction_ReturnsNull_IfActionIsMissing(string path)
        {
            // Arrange
            ODataPath odataPath = new DefaultODataPathHandler().Parse(ODataRoutingModel.GetModel(), "http://any", path);
            var       request   = RequestFactory.Create(new HttpMethod("GET"), "http://localhost/");
            var       actionMap = SelectActionHelper.CreateActionMap();

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

            // Assert
            Assert.Null(selectedAction);
        }
        public void SelectAction_ReturnsNull_NotSupportedMethodForDollarCount(string method)
        {
            // Arrange
            var model     = new CustomersModelWithInheritance();
            var odataPath = new ODataPath(new EntitySetSegment(model.Customers), CountSegment.Instance);
            var request   = RequestFactory.Create(new HttpMethod(method), "http://localhost/");
            var actionMap = SelectActionHelper.CreateActionMap("PostCustomer");

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

            // Assert
            Assert.Null(selectedAction);
        }
        public void SelectAction_ReturnsNull_IfActionIsMissing(string httpMethod)
        {
            // Arrange
            ODataPath odataPath      = new DefaultODataPathHandler().Parse(ODataRoutingModel.GetModel(), "http://any/", "RoutingCustomers(10)");
            var       request        = RequestFactory.Create(new HttpMethod(httpMethod), "http://localhost/");
            var       emptyActionMap = SelectActionHelper.CreateActionMap();

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

            // Assert
            Assert.Null(selectedAction);
            Assert.Empty(SelectActionHelper.GetRouteData(request).Values);
        }
        public void SelectAction_ReturnsNull_ForInvalidHttpMethods(string httpMethod)
        {
            // Arrange
            CustomersModelWithInheritance model = new CustomersModelWithInheritance();
            ODataPath odataPath      = new DefaultODataPathHandler().Parse(model.Model, _serviceRoot, "VipCustomer");
            var       request        = RequestFactory.Create(new HttpMethod(httpMethod), "http://localhost/");
            var       emptyActionMap = SelectActionHelper.CreateActionMap();

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

            // Act & Assert
            Assert.Null(selectedAction);
        }
        public void SelectAction_ReturnsNull_IfActionIsMissing(string path)
        {
            // Arrange
            ODataPath odataPath      = new DefaultODataPathHandler().Parse(ODataRoutingModel.GetModel(), _serviceRoot, path);
            var       request        = RequestFactory.Create(HttpMethod.Post, "http://localhost/");
            var       emptyActionMap = SelectActionHelper.CreateActionMap();

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

            // Assert
            Assert.Null(selectedAction);
            Assert.Empty(SelectActionHelper.GetRouteData(request).Values);
        }
Beispiel #11
0
        public void SelectAction_ReturnsActionImportName()
        {
            // Arrange
            OperationImportRoutingConvention importConvention = new OperationImportRoutingConvention();
            ODataPath odataPath = new DefaultODataPathHandler().Parse(EdmModel, "http://localhost/", "RateByName");
            var       request   = RequestFactory.Create(HttpMethod.Post, "http://localhost/");
            var       actionMap = SelectActionHelper.CreateActionMap("RateByName");

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

            // Assert
            Assert.Equal("RateByName", selectedAction);
            Assert.Empty(SelectActionHelper.GetRouteData(request).Values);
        }
        public void SelectAction_ReturnsGetAction_IfActionHasNestedPathsAttribute(string path, string expectedAction)
        {
            // Arrange
            ODataPath odataPath = new DefaultODataPathHandler().Parse(ODataRoutingModel.GetModel(), "http://any", path);
            var       request   = RequestFactory.Create(new HttpMethod("GET"), "http://localhost/");
            var       actionMap = SelectActionHelper.CreateActionMap(expectedAction);

            actionMap.First().MethodInfo = GetMethodWithNestedPathsAttribute();

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

            // Assert
            Assert.Equal(expectedAction, selectedAction);
        }
        public void SelectAction_ReturnsNull_IfActionIsMissing()
        {
            // Arrange
            CustomersModelWithInheritance model = new CustomersModelWithInheritance();
            ODataPath odataPath      = new DefaultODataPathHandler().Parse(model.Model, _serviceRoot, "Customers(10)/Name");
            var       request        = RequestFactory.Create(HttpMethod.Get, "http://localhost/");
            var       emptyActionMap = SelectActionHelper.CreateActionMap();

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

            // Assert
            Assert.Null(selectedAction);
            Assert.Empty(SelectActionHelper.GetRouteData(request).Values);
        }
        public void SelectAction_ReturnsNull_IfPatchToCollectionProperty()
        {
            // Arrange
            IEdmModel model     = ODataCountTest.GetEdmModel();
            ODataPath odataPath = new DefaultODataPathHandler().Parse(model, _serviceRoot, "DollarCountEntities(7)/EnumCollectionProp");
            var       request   = RequestFactory.Create(HttpMethod.Get, "http://localhost/");
            var       actionMap = SelectActionHelper.CreateActionMap("PatchToEnumCollectionProp");

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

            // Assert
            Assert.Null(selectedAction);
            Assert.Empty(SelectActionHelper.GetRouteData(request).Values);
        }
        public void SelectAction_ReturnsNull_IfNotCorrectMethod(string methodName)
        {
            // Arrange
            HttpMethod method = new HttpMethod(methodName);
            CustomersModelWithInheritance model = new CustomersModelWithInheritance();
            ODataPath odataPath = new DefaultODataPathHandler().Parse(model.Model, "http://localhost/", "Orders(7)/DynamicPropertyA");
            var       request   = RequestFactory.Create(method, "http://localhost/");
            var       actionMap = SelectActionHelper.CreateActionMap("GetDynamicProperty");

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

            // Assert
            Assert.Null(selectedAction);
            Assert.Empty(SelectActionHelper.GetRouteData(request).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");
            var       request   = RequestFactory.Create(new HttpMethod(httpMethod), "http://localhost/");
            var       actionMap = SelectActionHelper.CreateActionMap(prefix + "AccountOfSpecialAccountFromCustomer");

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

            // Assert
            Assert.NotNull(selectedAction);
            Assert.Equal(prefix + "AccountOfSpecialAccountFromCustomer", selectedAction);
            Assert.Empty(SelectActionHelper.GetRouteData(request).Values);
        }
        public void SelectAction_ReturnsTheActionName_ForEntitySetActionBoundToEntitySet()
        {
            // Arrange
            ActionRoutingConvention actionConvention = new ActionRoutingConvention();
            IEdmModel model     = ODataRoutingModel.GetModel();
            ODataPath odataPath = new DefaultODataPathHandler().Parse(model, _serviceRoot, "RoutingCustomers/Default.GetVIPs");
            var       request   = RequestFactory.Create(HttpMethod.Post, "http://localhost/");
            var       actionMap = SelectActionHelper.CreateActionMap("GetVIPs");

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

            // Assert
            Assert.Equal("GetVIPs", selectedAction);
            Assert.Empty(SelectActionHelper.GetRouteData(request).Values);
        }
Beispiel #18
0
        public void SelectAction_ReturnsFunctionName_ForFunctionOnEntityCollection()
        {
            // Arrange
            FunctionRoutingConvention     functionConvention = new FunctionRoutingConvention();
            CustomersModelWithInheritance model = new CustomersModelWithInheritance();
            ODataPath odataPath = new DefaultODataPathHandler().Parse(model.Model, _serviceRoot, "Customers/NS.IsAnyUpgraded");
            var       request   = RequestFactory.Create(HttpMethod.Get, "http://localhost/");
            var       actionMap = SelectActionHelper.CreateActionMap("IsAnyUpgraded");

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

            // Assert
            Assert.Equal("IsAnyUpgraded", selectedAction);
            Assert.Empty(SelectActionHelper.GetRouteData(request).Values);
        }
        public void SelectAction_ReturnsTheActionName_ForSingletonActionBoundToEntity()
        {
            // Arrange
            ActionRoutingConvention actionConvention = new ActionRoutingConvention();
            IEdmModel model     = new CustomersModelWithInheritance().Model;
            ODataPath odataPath = new DefaultODataPathHandler().Parse(model, _serviceRoot, "VipCustomer/NS.upgrade");
            var       request   = RequestFactory.Create(HttpMethod.Post, "http://localhost/");
            var       actionMap = SelectActionHelper.CreateActionMap("upgrade");

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

            // Assert
            Assert.Equal("upgrade", selectedAction);
            Assert.Empty(SelectActionHelper.GetRouteData(request).Values);
        }
Beispiel #20
0
        public void SelectAction_OnEnumCollection_ReturnsTheActionName(string httpMethod, string prefix)
        {
            // Arrange
            IEdmModel model     = ODataCountTest.GetEdmModel();
            ODataPath odataPath = new DefaultODataPathHandler().Parse(model, _serviceRoot, "DollarCountEntities(7)/EnumCollectionProp");
            var       request   = RequestFactory.Create(new HttpMethod(httpMethod), "http://localhost/");
            var       actionMap = SelectActionHelper.CreateActionMap(prefix + "EnumCollectionProp");

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

            // Assert
            Assert.NotNull(selectedAction);
            Assert.Equal(prefix + "EnumCollectionProp", selectedAction);
            Assert.Single(SelectActionHelper.GetRouteData(request).Values);
            Assert.Equal(7, SelectActionHelper.GetRouteData(request).Values["key"]);
        }
Beispiel #21
0
        public void SelectAction_SetsRelatedKey_ForDeleteRefRequestsWithDollarId(string uri)
        {
            // Arrange
            CustomersModelWithInheritance model = new CustomersModelWithInheritance();
            ODataPath odataPath = new DefaultODataPathHandler().Parse(model.Model, "http://any/", uri);
            var       request   = RequestFactory.Create(HttpMethod.Delete, "http://localhost/");
            var       actionMap = SelectActionHelper.CreateActionMap("DeleteRef");

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

            // Assert
            Assert.Equal("DeleteRef", selectedAction);
            Assert.Equal(42, SelectActionHelper.GetRouteData(request).Values["key"]);
            Assert.Equal("Orders", SelectActionHelper.GetRouteData(request).Values["navigationProperty"]);
            Assert.Equal(24, SelectActionHelper.GetRouteData(request).Values["relatedKey"]);
        }
Beispiel #22
0
        public void SelectAction_UpdatesRouteData_ForSingletonFunctionWithParameters()
        {
            // Arrange
            FunctionRoutingConvention     functionConvention = new FunctionRoutingConvention();
            CustomersModelWithInheritance model = new CustomersModelWithInheritance();
            ODataPath odataPath = new DefaultODataPathHandler().Parse(model.Model, _serviceRoot, "VipCustomer/NS.IsUpgradedWithParam(city='any')");
            var       request   = RequestFactory.Create(HttpMethod.Get, "http://localhost/");
            var       actionMap = SelectActionHelper.CreateActionMap("IsUpgradedWithParam");

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

            // Assert
            Assert.Equal("IsUpgradedWithParam", selectedAction);
            Assert.Single(SelectActionHelper.GetRouteData(request).Values);
            Assert.Equal("any", SelectActionHelper.GetRouteData(request).Values["city"]);
        }
        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");
            var       request   = RequestFactory.Create(new HttpMethod(httpMethod), "http://localhost/");
            var       actionMap = SelectActionHelper.CreateActionMap(prefix + "NameFromCustomer");

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

            // Assert
            Assert.NotNull(selectedAction);
            Assert.Equal(prefix + "NameFromCustomer", selectedAction);
            Assert.Single(SelectActionHelper.GetRouteData(request).Values);
            Assert.Equal(7, SelectActionHelper.GetRouteData(request).Values["key"]);
        }
Beispiel #24
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);
        }
        public void SelectAction_ReturnsFunctionName_DollarCount()
        {
            // Arrange
            var       model     = new CustomersModelWithInheritance();
            var       handler   = new DefaultODataPathHandler();
            ODataPath odataPath = handler.Parse(model.Model, _serviceRoot, "Customers(1)/NS.GetOrders(parameter=5)/$count");
            var       request   = RequestFactory.Create(HttpMethod.Get, "http://localhost/");
            var       actionMap = SelectActionHelper.CreateActionMap("GetOrders");

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

            // Assert
            Assert.Equal("GetOrders", selectedAction);
            Assert.Equal(2, SelectActionHelper.GetRouteData(request).Values.Count);
            Assert.Equal(1, SelectActionHelper.GetRouteData(request).Values["key"]);
            Assert.Equal(5, SelectActionHelper.GetRouteData(request).Values["parameter"]);
        }
        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);
        }
Beispiel #27
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);
        }
        public void SelectAction_OnComplexCollection_ReturnsTheActionName(string httpMethod, string prefix)
        {
            // Arrange
            CustomersModelWithInheritance model = new CustomersModelWithInheritance();
            ODataPath odataPath = new DefaultODataPathHandler().Parse(model.Model, _serviceRoot, "Customers(7)/OtherAccounts");
            var       request   = RequestFactory.Create(new HttpMethod(httpMethod), "http://localhost/");
            var       actionMap = SelectActionHelper.CreateActionMap(prefix + "OtherAccountsFromCustomer");

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

            // Assert
            Assert.NotNull(selectedAction);
            Assert.Equal(prefix + "OtherAccountsFromCustomer", selectedAction);
            Assert.Equal(2, SelectActionHelper.GetRouteData(request).Values.Count);
            Assert.Equal(7, SelectActionHelper.GetRouteData(request).Values["key"]);
            Assert.Equal(7, SelectActionHelper.GetRouteData(request).Values["keyID"]);
            Assert.Equal(1, SelectActionHelper.GetRoutingConventionsStore(request)[ODataRouteConstants.KeyCount]);
        }
        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);
        }
Beispiel #30
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);
        }