public void TryComputeCanonicalContainingPath_ForContainedEntitySetDirectAccess( string resourcePath, string expectedContainingPath) { // Arrange var path = CreatePathFromUri(new Uri(resourcePath, UriKind.Relative)); var builder = new ContainmentPathBuilder(); // Act path = builder.TryComputeCanonicalContainingPath(path); // Assert var uri = CreateUriFromPath(path); uri = _serviceRoot.MakeRelativeUri(uri); Assert.Equal(expectedContainingPath, uri.ToString()); }
private static Uri GenerateContainmentODataPathSegments(ResourceContext resourceContext, bool isEntityId) { Contract.Assert(resourceContext != null); Contract.Assert( resourceContext.NavigationSource.NavigationSourceKind() == EdmNavigationSourceKind.ContainedEntitySet); Contract.Assert(resourceContext.Request != null); ODataPath path = resourceContext.Request.ODataFeature().Path; if (path == null) { throw Error.InvalidOperation(SRResources.ODataPathMissing); } path = new ContainmentPathBuilder().TryComputeCanonicalContainingPath(path); List <ODataPathSegment> odataPath = path.ToList(); // create a template entity set if it's contained entity set IEdmEntitySet entitySet = resourceContext.NavigationSource as IEdmEntitySet; if (entitySet == null) { EdmEntityContainer container = new EdmEntityContainer("NS", "Default"); entitySet = new EdmEntitySet(container, resourceContext.NavigationSource.Name, resourceContext.NavigationSource.EntityType()); } odataPath.Add(new EntitySetSegment(entitySet)); odataPath.Add(new KeySegment(ConventionsHelpers.GetEntityKey(resourceContext), resourceContext.StructuredType as IEdmEntityType, resourceContext.NavigationSource)); if (!isEntityId) { bool isSameType = resourceContext.StructuredType == resourceContext.NavigationSource.EntityType(); if (!isSameType) { odataPath.Add(new TypeSegment(resourceContext.StructuredType, resourceContext.NavigationSource)); } } string odataLink = resourceContext.Request.CreateODataLink(odataPath); return(odataLink == null ? null : new Uri(odataLink)); }
private static Uri GenerateContainmentODataPathSegments(EntityInstanceContext entityContext, bool isEntityId) { Contract.Assert(entityContext != null); Contract.Assert( entityContext.NavigationSource.NavigationSourceKind() == EdmNavigationSourceKind.ContainedEntitySet); Contract.Assert(entityContext.Request != null); ODataPath path = entityContext.Request.ODataProperties().Path; if (path == null) { throw Error.InvalidOperation(SRResources.ODataPathMissing); } ODL.ODataPath odlPath = path.ODLPath; odlPath = new ContainmentPathBuilder().TryComputeCanonicalContainingPath(odlPath); path = ODataPathSegmentTranslator.TranslateODLPathToWebAPIPath( odlPath, entityContext.EdmModel, unresolvedPathSegment: null, id: null, enableUriTemplateParsing: false, parameterAliasNodes: new Dictionary <string, ODL.SingleValueNode>(), queryString: new NameValueCollection()); List <ODataPathSegment> odataPath = path.Segments.ToList(); odataPath.Add(new EntitySetPathSegment((IEdmEntitySetBase)entityContext.NavigationSource)); odataPath.Add(new KeyValuePathSegment(ConventionsHelpers.GetEntityKeyValue(entityContext))); if (!isEntityId) { bool isSameType = entityContext.EntityType == entityContext.NavigationSource.EntityType(); if (!isSameType) { odataPath.Add(new CastPathSegment(entityContext.EntityType)); } } string odataLink = entityContext.Url.CreateODataLink(odataPath); return(odataLink == null ? null : new Uri(odataLink)); }