Example #1
0
        public void TargetOnEntitySetReturnsCorrectExpandRestrictionsValue(EdmVocabularyAnnotationSerializationLocation location)
        {
            // Arrange
            const string template = @"
                <Annotations Target=""NS.Default/Calendars"">
                  {0}
                </Annotations>";

            IEdmModel model = GetEdmModel(template, location);

            Assert.NotNull(model); // guard

            IEdmEntitySet calendars = model.EntityContainer.FindEntitySet("Calendars");

            Assert.NotNull(calendars); // guard

            // Act
            // Act
            ExpandRestrictions expand = new ExpandRestrictions();
            bool result = expand.Load(model, calendars);

            // Assert
            Assert.True(result);
            VerifyExpandRestrictions(expand);
        }
Example #2
0
        public void KindPropertyReturnsExpandRestrictionsEnumMember()
        {
            // Arrange & Act
            ExpandRestrictions expand = new ExpandRestrictions();

            // Assert
            Assert.Equal(CapabilitesTermKind.ExpandRestrictions, expand.Kind);
        }
Example #3
0
        private static void VerifyExpandRestrictions(ExpandRestrictions expand)
        {
            Assert.NotNull(expand);

            Assert.NotNull(expand.Expandable);
            Assert.False(expand.Expandable.Value);

            Assert.NotNull(expand.NonExpandableProperties);
            Assert.Equal(2, expand.NonExpandableProperties.Count);
            Assert.Equal("abc|RelatedEvents", String.Join("|", expand.NonExpandableProperties));

            Assert.True(expand.IsNonExpandableProperty("RelatedEvents"));
        }
Example #4
0
        public void UnknownAnnotatableTargetReturnsDefaultExpandRestrictionsValues()
        {
            // Arrange
            ExpandRestrictions expand     = new ExpandRestrictions();
            EdmEntityType      entityType = new EdmEntityType("NS", "Entity");

            //  Act
            bool result = expand.Load(EdmCoreModel.Instance, entityType);

            // Assert
            Assert.False(result);
            Assert.Equal(CapabilitesTermKind.ExpandRestrictions, expand.Kind);
            Assert.True(expand.IsExpandable);
            Assert.Null(expand.Expandable);
            Assert.Null(expand.NonExpandableProperties);
        }
Example #5
0
        /// <summary>
        /// Create $expand parameter for the <see cref="IEdmNavigationSource"/>.
        /// </summary>
        /// <param name="context">The OData context.</param>
        /// <param name="target">The edm entity path.</param>
        /// <param name="entityType">The edm entity path.</param>
        /// <returns>The created <see cref="OpenApiParameter"/> or null.</returns>
        public static OpenApiParameter CreateExpand(this ODataContext context, IEdmVocabularyAnnotatable target, IEdmEntityType entityType)
        {
            Utils.CheckArgumentNull(context, nameof(context));
            Utils.CheckArgumentNull(target, nameof(target));
            Utils.CheckArgumentNull(entityType, nameof(entityType));

            ExpandRestrictions expand = context.Model.GetExpandRestrictions(target);

            if (expand != null && !expand.IsExpandable)
            {
                return(null);
            }

            IList <IOpenApiAny> expandItems = new List <IOpenApiAny>
            {
                new OpenApiString("*")
            };

            foreach (var property in entityType.NavigationProperties())
            {
                if (expand != null && expand.IsNonExpandableProperty(property.Name))
                {
                    continue;
                }

                expandItems.Add(new OpenApiString(property.Name));
            }

            return(new OpenApiParameter
            {
                Name = "$expand",
                In = ParameterLocation.Query,
                Description = "Expand related entities",
                Schema = new OpenApiSchema
                {
                    Type = "array",
                    UniqueItems = true,
                    Items = new OpenApiSchema
                    {
                        Type = "string",
                        Enum = expandItems
                    }
                },
                Style = ParameterStyle.Simple
            });
        }