public void GenerateNavigationLink_WorksToGenerateExpectedNavigationLink_ForContainedNavigation( bool includeCast, string expectedNavigationLink) { // NOTE: This test is generating a link that does not technically correspond to a valid model (specifically // the extra OrderLines navigation), but it allows us to validate the nested navigation scenario // without twisting the model unnecessarily. // Arrange IEdmEntityType myOrder = (IEdmEntityType)_model.Model.FindDeclaredType("NS.MyOrder"); IEdmNavigationProperty orderLinesProperty = myOrder.NavigationProperties().Single(x => x.ContainsTarget); var serializerContext = new ODataSerializerContext { Model = _model.Model, NavigationSource = _model.OrderLines, Path = new ODataPath( new EntitySetPathSegment(_model.Model.FindDeclaredEntitySet("MyOrders")), new KeyValuePathSegment("42"), new NavigationPathSegment(orderLinesProperty), new KeyValuePathSegment("21")), Url = GetODataRequest(_model.Model).GetUrlHelper(), }; var entityContext = new EntityInstanceContext(serializerContext, _model.OrderLine.AsReference(), new { ID = 21 }); // Act Uri uri = entityContext.GenerateNavigationPropertyLink(orderLinesProperty, includeCast); // Assert Assert.Equal(expectedNavigationLink, uri.AbsoluteUri); }
public void GenerateNavigationLink_GeneratesExpectedNavigationLink(bool includeCast, string expectedNavigationLink) { HttpRequestMessage request = GetODataRequest(_model.Model); var serializerContext = new ODataSerializerContext { Model = _model.Model, EntitySet = _model.Customers, Url = request.GetUrlHelper() }; var entityContext = new EntityInstanceContext(serializerContext, _model.SpecialCustomer.AsReference(), new { ID = 42 }); IEdmNavigationProperty ordersProperty = _model.Customer.NavigationProperties().Single(); Uri uri = entityContext.GenerateNavigationPropertyLink(ordersProperty, includeCast); Assert.Equal(expectedNavigationLink, uri.AbsoluteUri); }