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());
        }
Beispiel #2
0
        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());
        }
Beispiel #3
0
        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.TranslateODataLibPathToWebApiPath(
                odlPath,
                entityContext.EdmModel,
                unresolvedPathSegment: null,
                id: null,
                enableUriTemplateParsing: false,
                parameterAliasNodes: new Dictionary<string, ODL.SingleValueNode>());

            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);
        }