public void KindPropertyReturnsInsertRestrictionsEnumMember() { // Arrange & Act InsertRestrictions insert = new InsertRestrictions(); // Assert Assert.Equal(CapabilitesTermKind.InsertRestrictions, insert.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); } } } }
private static void VerifyInsertRestrictions(InsertRestrictions insert) { Assert.NotNull(insert); Assert.NotNull(insert.Insertable); Assert.False(insert.Insertable.Value); Assert.NotNull(insert.NonInsertableNavigationProperties); Assert.Equal(2, insert.NonInsertableNavigationProperties.Count); Assert.Equal("abc|RelatedEvents", String.Join("|", insert.NonInsertableNavigationProperties)); Assert.True(insert.IsNonInsertableNavigationProperty("RelatedEvents")); Assert.False(insert.IsNonInsertableNavigationProperty("MyUnknownNavigationProperty")); }
public void UnknownAnnotatableTargetReturnsDefaultInsertRestrictionsValues() { // Arrange InsertRestrictions insert = new InsertRestrictions(); EdmEntityType entityType = new EdmEntityType("NS", "Entity"); // Act bool result = insert.Load(EdmCoreModel.Instance, entityType); // Assert Assert.False(result); Assert.True(insert.IsInsertable); Assert.Null(insert.Insertable); Assert.Null(insert.NonInsertableNavigationProperties); }
/// <inheritdoc/> protected override void SetOperations(OpenApiPathItem item) { NavigationRestrictions navigation = Context.Model.GetNavigationRestrictions(EntitySet); if (navigation == null || navigation.IsNavigable) { AddOperation(item, OperationType.Get); } InsertRestrictions insert = Context.Model.GetInsertRestrictions(EntitySet); if (insert == null || insert.IsInsertable) { AddOperation(item, OperationType.Post); } }
public void TargetOnEntitySetReturnsCorrectInsertRestrictionsValue(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 InsertRestrictions insert = new InsertRestrictions(); bool result = insert.Load(model, calendars); // Assert Assert.True(result); VerifyInsertRestrictions(insert); }