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 LinksPathSegment(), new NavigationPathSegment(ordersProperty)); HttpControllerContext controllerContext = CreateControllerContext(method); var actionMap = GetMockActionMap(methodsInController); // Act string selectedAction = new LinksRoutingConvention().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 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 LinksPathSegment(), new NavigationPathSegment(specialOrdersProperty)); HttpControllerContext controllerContext = CreateControllerContext(method); var actionMap = GetMockActionMap(methodsInController); // Act string selectedAction = new LinksRoutingConvention().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(specialOrdersProperty.Name, controllerContext.RouteData.Values["navigationProperty"]); } }
public void SelectAction_ReturnsNull_IfActionIsMissing(string httpMethod, string path) { ODataPath odataPath = new DefaultODataPathHandler().Parse(ODataRoutingModel.GetModel(), path); ILookup<string, HttpActionDescriptor> emptyActionMap = new HttpActionDescriptor[0].ToLookup(desc => (string)null); HttpControllerContext controllerContext = new HttpControllerContext(); controllerContext.Request = new HttpRequestMessage(new HttpMethod(httpMethod), "http://localhost/"); controllerContext.Request.Properties[HttpPropertyKeys.HttpRouteDataKey] = new HttpRouteData(new HttpRoute()); string selectedAction = new LinksRoutingConvention().SelectAction(odataPath, controllerContext, emptyActionMap); Assert.Null(selectedAction); Assert.Empty(controllerContext.Request.GetRouteData().Values); }
public void SelectAction_ReturnsNull_IfActionIsMissing(string httpMethod, string path) { ODataPath odataPath = new DefaultODataPathHandler().Parse(ODataRoutingModel.GetModel(), path); ILookup <string, HttpActionDescriptor> emptyActionMap = new HttpActionDescriptor[0].ToLookup(desc => (string)null); HttpControllerContext controllerContext = new HttpControllerContext(); controllerContext.Request = new HttpRequestMessage(new HttpMethod(httpMethod), "http://localhost/"); controllerContext.Request.SetRouteData(new HttpRouteData(new HttpRoute())); string selectedAction = new LinksRoutingConvention().SelectAction(odataPath, controllerContext, emptyActionMap); Assert.Null(selectedAction); Assert.Empty(controllerContext.Request.GetRouteData().Values); }