private static ODataExpandPath BuildExpandPath(ExpandModelPath path, IEdmNavigationSource navigationSource, IEdmNavigationSource currentEdmNavigationSource) { IList <ODataPathSegment> segments = new List <ODataPathSegment>(); IEdmType previousPropertyType = null; foreach (var node in path) { if (node is IEdmStructuralProperty property) { segments.Add(new PropertySegment(property)); previousPropertyType = property.Type.GetElementType(); } else if (node is IEdmStructuredType typeNode) { if (previousPropertyType == null) { segments.Add(new TypeSegment(typeNode, navigationSource)); } else { segments.Add(new TypeSegment(typeNode, previousPropertyType, navigationSource)); } } else if (node is IEdmNavigationProperty navigation) { segments.Add(new NavigationPropertySegment(navigation, currentEdmNavigationSource)); } } return(new ODataExpandPath(segments)); }
public void Ctor_ExpandModelPath_WithBasicElements_SetsProperties() { // Arrange IList <IEdmElement> elements = new List <IEdmElement> { _relatedNavProperty }; // Act ExpandModelPath expandPath = new ExpandModelPath(elements); // Assert Assert.Same(_relatedNavProperty, expandPath.Navigation); Assert.Equal("RelatedCustomers", expandPath.ExpandPath); Assert.Equal("", expandPath.NavigationPropertyPath); }
public void Ctor_ExpandModelPath_WithTypeElements_SetsProperties() { // Arrange IList <IEdmElement> elements = new List <IEdmElement> { _homeAddress, _customerType, // it's not valid from the model, but it's valid for the test. _relatedNavProperty }; // Act ExpandModelPath expandPath = new ExpandModelPath(elements); // Assert Assert.Same(_relatedNavProperty, expandPath.Navigation); Assert.Equal("HomeAddress/NS.Customer/RelatedCustomers", expandPath.ExpandPath); Assert.Equal("HomeAddress/NS.Customer", expandPath.NavigationPropertyPath); }