public void KindPropertyReturnsUpdateRestrictionsEnumMember()
        {
            // Arrange & Act
            UpdateRestrictions update = new UpdateRestrictions();

            // Assert
            Assert.Equal(CapabilitesTermKind.UpdateRestrictions, update.Kind);
        }
        /// <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);
                    }
                }
            }
        }
        public void UnknownAnnotatableTargetReturnsDefaultUpdateRestrictionsValues()
        {
            // Arrange
            UpdateRestrictions update     = new UpdateRestrictions();
            EdmEntityType      entityType = new EdmEntityType("NS", "Entity");

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

            // Assert
            Assert.False(result);
            Assert.True(update.IsUpdatable);
            Assert.Null(update.Updatable);
            Assert.Null(update.NonUpdatableNavigationProperties);
        }
        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"));
        }
        /// <inheritdoc/>
        protected override void SetOperations(OpenApiPathItem item)
        {
            // Retrieve a singleton.
            NavigationRestrictions navigation = Context.Model.GetNavigationRestrictions(Singleton);

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

            // Update a singleton
            UpdateRestrictions update = Context.Model.GetUpdateRestrictions(Singleton);

            if (update == null || update.IsUpdatable)
            {
                AddOperation(item, OperationType.Patch);
            }
        }
        /// <inheritdoc/>
        protected override void SetOperations(OpenApiPathItem item)
        {
            IndexableByKey index = Context.Model.GetIndexableByKey(EntitySet);

            if (index == null || index.IsSupported)
            {
                AddOperation(item, OperationType.Get);
            }

            UpdateRestrictions update = Context.Model.GetUpdateRestrictions(EntitySet);

            if (update == null || update.IsUpdatable)
            {
                AddOperation(item, OperationType.Patch);
            }

            DeleteRestrictions delete = Context.Model.GetDeleteRestrictions(EntitySet);

            if (delete == null || delete.IsDeletable)
            {
                AddOperation(item, OperationType.Delete);
            }
        }
        public void TargetOnEntitySetReturnsCorrectUpdateRestrictionsValue(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
            UpdateRestrictions update = new UpdateRestrictions();
            bool result = update.Load(model, calendars);

            // Assert
            Assert.True(result);
            VerifyUpdateRestrictions(update);
        }
        public void TargetOnEntityTypeReturnsCorrectUpdateRestrictionsValue(EdmVocabularyAnnotationSerializationLocation location)
        {
            // Arrange
            const string template = @"
                <Annotations Target=""NS.Calendar"">
                  {0}
                </Annotations>";

            IEdmModel model = GetEdmModel(template, location);

            Assert.NotNull(model); // guard

            IEdmEntityType calendar = model.SchemaElements.OfType <IEdmEntityType>().First(c => c.Name == "Calendar");

            Assert.NotNull(calendar); // guard

            // Act
            UpdateRestrictions update = new UpdateRestrictions();
            bool result = update.Load(model, calendar);

            // Assert
            Assert.True(result);
            VerifyUpdateRestrictions(update);
        }