public void SelectAction_Returns_ExpectedMethodOnDerivedType(string method, string[] methodsInController, string expectedSelectedAction) { // Arrange string key = "42"; CustomersModelWithInheritance model = new CustomersModelWithInheritance(); var specialOrdersProperty = model.SpecialCustomer.FindProperty("SpecialOrders") as IEdmNavigationProperty; ODataPath odataPath = new ODataPath(new EntitySetPathSegment(model.Customers), new KeyValuePathSegment(key), new CastPathSegment(model.SpecialCustomer), new NavigationPathSegment(specialOrdersProperty)); HttpControllerContext controllerContext = CreateControllerContext(method); var actionMap = GetMockActionMap(methodsInController); // Act string selectedAction = new NavigationRoutingConvention().SelectAction(odataPath, controllerContext, actionMap); // Assert Assert.Equal(expectedSelectedAction, selectedAction); if (expectedSelectedAction == null) { Assert.Empty(controllerContext.RouteData.Values); } else { Assert.Equal(1, controllerContext.RouteData.Values.Count); Assert.Equal(key, controllerContext.RouteData.Values["key"]); } }
public void SelectAction_ReturnsNull_IfActionIsMissing() { ODataPath odataPath = new DefaultODataPathHandler().Parse(ODataRoutingModel.GetModel(), "RoutingCustomers(10)/Name"); ILookup<string, HttpActionDescriptor> emptyActionMap = new HttpActionDescriptor[0].ToLookup(desc => (string)null); HttpControllerContext controllerContext = new HttpControllerContext(); controllerContext.Request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/"); controllerContext.Request.SetRouteData(new HttpRouteData(new HttpRoute())); string selectedAction = new NavigationRoutingConvention().SelectAction(odataPath, controllerContext, emptyActionMap); Assert.Null(selectedAction); Assert.Empty(controllerContext.Request.GetRouteData().Values); }
public void SelectAction_ReturnsNull_IfActionIsMissing() { ODataPath odataPath = new DefaultODataPathHandler().Parse(ODataRoutingModel.GetModel(), "RoutingCustomers(10)/Products"); ILookup <string, HttpActionDescriptor> emptyActionMap = new HttpActionDescriptor[0].ToLookup(desc => (string)null); HttpControllerContext controllerContext = new HttpControllerContext(); controllerContext.Request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/"); controllerContext.Request.SetRouteData(new HttpRouteData(new HttpRoute())); string selectedAction = new NavigationRoutingConvention().SelectAction(odataPath, controllerContext, emptyActionMap); Assert.Null(selectedAction); Assert.Empty(controllerContext.Request.GetRouteData().Values); }