コード例 #1
0
        private static void VerifyUpdateRestrictions(UpdateRestrictions update)
        {
            Assert.NotNull(update);

            Assert.NotNull(update.Updatable);
            Assert.False(update.Updatable.Value);

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

            Assert.True(update.IsNonUpdatableNavigationProperty("abc"));
            Assert.True(update.IsNonUpdatableNavigationProperty("RelatedEvents"));
            Assert.False(update.IsNonUpdatableNavigationProperty("Others"));
        }
コード例 #2
0
        /// <inheritdoc/>
        protected override void SetOperations(OpenApiPathItem item)
        {
            IEdmEntitySet             entitySet = NavigationSource as IEdmEntitySet;
            IEdmVocabularyAnnotatable target    = entitySet;

            if (target == null)
            {
                target = NavigationSource as IEdmSingleton;
            }

            string navigationPropertyPath = String.Join("/",
                                                        Path.Segments.OfType <ODataNavigationPropertySegment>().Select(e => e.NavigationProperty.Name));

            // contaiment: Get / (Post - Collection | Patch - Single)
            // non-containment: only Get
            NavigationRestrictions navigation = Context.Model.GetNavigationRestrictions(target);

            if (navigation == null || !navigation.IsRestrictedProperty(navigationPropertyPath))
            {
                AddOperation(item, OperationType.Get);
            }

            if (NavigationProperty.ContainsTarget)
            {
                if (NavigationProperty.TargetMultiplicity() == EdmMultiplicity.Many)
                {
                    if (LastSegmentIsKeySegment)
                    {
                        // Need to check this scenario is valid or not?
                        UpdateRestrictions update = Context.Model.GetUpdateRestrictions(target);
                        if (update == null || !update.IsNonUpdatableNavigationProperty(navigationPropertyPath))
                        {
                            AddOperation(item, OperationType.Patch);
                        }
                    }
                    else
                    {
                        InsertRestrictions insert = Context.Model.GetInsertRestrictions(target);
                        if (insert == null || !insert.IsNonInsertableNavigationProperty(navigationPropertyPath))
                        {
                            AddOperation(item, OperationType.Post);
                        }
                    }
                }
                else
                {
                    UpdateRestrictions update = Context.Model.GetUpdateRestrictions(target);
                    if (update == null || !update.IsNonUpdatableNavigationProperty(navigationPropertyPath))
                    {
                        AddOperation(item, OperationType.Patch);
                    }
                }
            }
        }