public void SelectAction_Returns_ExpectedMethodOnBaseType(string method, string[] methodsInController, string expectedSelectedAction) { // Arrange string key = "42"; CustomersModelWithInheritance model = new CustomersModelWithInheritance(); var ordersProperty = model.Customer.FindProperty("Orders") as IEdmNavigationProperty; ODataPath odataPath = new ODataPath(new EntitySetPathSegment(model.Customers), new KeyValuePathSegment(key), new NavigationPathSegment(ordersProperty), new RefPathSegment()); HttpControllerContext controllerContext = CreateControllerContext(method); var actionMap = GetMockActionMap(methodsInController); // Act string selectedAction = new RefRoutingConvention().SelectAction(odataPath, controllerContext, actionMap); // Assert Assert.Equal(expectedSelectedAction, selectedAction); if (expectedSelectedAction == null) { Assert.Empty(controllerContext.RouteData.Values); } else { Assert.Equal(2, controllerContext.RouteData.Values.Count); Assert.Equal(key, controllerContext.RouteData.Values["key"]); Assert.Equal(ordersProperty.Name, controllerContext.RouteData.Values["navigationProperty"]); } }
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)); HttpControllerContext controllerContext = CreateControllerContext(method); var actionMap = GetMockActionMap(methodsInController); // Act string selectedAction = new RefRoutingConvention().SelectAction(odataPath, controllerContext, actionMap); // Assert Assert.Equal(expectedSelectedAction, selectedAction); if (expectedSelectedAction == null) { Assert.Empty(controllerContext.RouteData.Values); } else { Assert.Equal(2, controllerContext.RouteData.Values.Count); Assert.Equal(42, controllerContext.RouteData.Values["key"]); Assert.Equal(specialOrdersProperty.Name, controllerContext.RouteData.Values["navigationProperty"]); } }
public void SelectAction_SetsRelatedKey_ForDeleteRefRequestsWithDollarId(string uri) { // Arrange CustomersModelWithInheritance model = new CustomersModelWithInheritance(); ODataPath odataPath = new DefaultODataPathHandler().Parse(model.Model, "http://any/", uri); HttpControllerContext controllerContext = CreateControllerContext("DELETE"); var actionMap = GetMockActionMap("DeleteRef"); // Act var actionName = new RefRoutingConvention().SelectAction(odataPath, controllerContext, actionMap); var routeData = controllerContext.RouteData; // Assert Assert.Equal("DeleteRef", actionName); Assert.Equal(42, routeData.Values["key"]); Assert.Equal("Orders", routeData.Values["navigationProperty"]); Assert.Equal(24, routeData.Values["relatedKey"]); }
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)"); HttpControllerContext controllerContext = CreateControllerContext(method); var actionMap = GetMockActionMap("DeleteRef", "CreateRef", "GetRef", "PutRef", "PostRef"); // Act string actionName = new RefRoutingConvention().SelectAction(odataPath, controllerContext, actionMap); // Assert Assert.Null(actionName); }
public void SelectAction_SetsRelatedKey_ForDeleteRefRequestsWithDollarId(string uri) { // Arrange CustomersModelWithInheritance model = new CustomersModelWithInheritance(); ODataPath odataPath = new DefaultODataPathHandler().Parse(model.Model, "http://any/", uri); HttpControllerContext controllerContext = CreateControllerContext("DELETE"); var actionMap = GetMockActionMap("DeleteRef"); // Act var actionName = new RefRoutingConvention().SelectAction(odataPath, controllerContext, actionMap); var routeData = controllerContext.RouteData; // Assert Assert.Equal("DeleteRef", actionName); Assert.Equal("42", routeData.Values["key"]); Assert.Equal("Orders", routeData.Values["navigationProperty"]); Assert.Equal("24", routeData.Values["relatedKey"]); }