public void CreateEntityPathItemWorksForDeleteRestrictionsCapablities(bool deletable, OperationType[] expected)
        {
            // Arrange
            string annotation = String.Format(@"
<Annotation Term=""Org.OData.Capabilities.V1.DeleteRestrictions"">
  <Record>
    <PropertyValue Property=""Deletable"" Bool=""{0}"" />
  </Record>
</Annotation>", deletable);

            IEdmModel     model     = EntitySetPathItemHandlerTests.GetEdmModel(annotation);
            ODataContext  context   = new ODataContext(model);
            IEdmEntitySet entitySet = model.EntityContainer.FindEntitySet("Customers");

            Assert.NotNull(entitySet); // guard
            ODataPath path = new ODataPath(new ODataNavigationSourceSegment(entitySet), new ODataKeySegment(entitySet.EntityType()));

            // Act
            var pathItem = _pathItemHandler.CreatePathItem(context, path);

            // Assert
            Assert.NotNull(pathItem);

            Assert.NotNull(pathItem.Operations);
            Assert.NotEmpty(pathItem.Operations);
            Assert.Equal(expected, pathItem.Operations.Select(e => e.Key));
        }
Example #2
0
        public void CreateEntityPathItemAddsCustomAttributeValuesToPathExtensions()
        {
            // Arrange
            IEdmModel    model   = EntitySetPathItemHandlerTests.GetEdmModel(annotation: "");
            ODataContext context = new(model);

            context.Settings.CustomXMLAttributesMapping = new()
            {
                {
                    "ags:IsHidden", "x-ms-isHidden"
                },
                {
                    "isOwner", "x-ms-isOwner"
                }
            };
Example #3
0
        public void CreatePathItemThrowsForNonNavigationPropertyPath()
        {
            // Arrange
            IEdmModel     model     = EntitySetPathItemHandlerTests.GetEdmModel(annotation: "");
            ODataContext  context   = new ODataContext(model);
            IEdmEntitySet entitySet = model.EntityContainer.FindEntitySet("Customers");

            Assert.NotNull(entitySet); // guard
            var path = new ODataPath(new ODataNavigationSourceSegment(entitySet));

            Assert.Equal(ODataPathKind.EntitySet, path.Kind); // guard

            // Act
            Action test = () => _pathItemHandler.CreatePathItem(context, path);

            // Assert
            var exception = Assert.Throws <InvalidOperationException>(test);

            Assert.Equal(String.Format(SRResource.InvalidPathKindForPathItemHandler, "RefPathItemHandler", path.Kind), exception.Message);
        }
        private void VerifyPathItemOperations(string annotation, OperationType[] expected)
        {
            // Arrange
            IEdmModel     model     = EntitySetPathItemHandlerTests.GetEdmModel(annotation);
            ODataContext  context   = new ODataContext(model);
            IEdmEntitySet entitySet = model.EntityContainer.FindEntitySet("Customers");

            Assert.NotNull(entitySet); // guard
            ODataPath path = new ODataPath(new ODataNavigationSourceSegment(entitySet), new ODataKeySegment(entitySet.EntityType()));

            // Act
            var pathItem = _pathItemHandler.CreatePathItem(context, path);

            // Assert
            Assert.NotNull(pathItem);

            Assert.NotNull(pathItem.Operations);
            Assert.NotEmpty(pathItem.Operations);
            Assert.Equal(expected, pathItem.Operations.Select(e => e.Key));
        }
        public void CreateEntityPathItemReturnsCorrectPathItem()
        {
            // Arrange
            IEdmModel     model     = EntitySetPathItemHandlerTests.GetEdmModel(annotation: "");
            ODataContext  context   = new ODataContext(model);
            IEdmEntitySet entitySet = model.EntityContainer.FindEntitySet("Customers");

            Assert.NotNull(entitySet); // guard
            ODataPath path = new ODataPath(new ODataNavigationSourceSegment(entitySet), new ODataKeySegment(entitySet.EntityType()));

            // Act
            var pathItem = _pathItemHandler.CreatePathItem(context, path);

            // Assert
            Assert.NotNull(pathItem);

            Assert.NotNull(pathItem.Operations);
            Assert.NotEmpty(pathItem.Operations);
            Assert.Equal(3, pathItem.Operations.Count);
            Assert.Equal(new OperationType[] { OperationType.Get, OperationType.Patch, OperationType.Delete },
                         pathItem.Operations.Select(o => o.Key));
        }
Example #6
0
        public void CreateEntityPathItemReturnsCorrectPathItemWithPathParameters(bool declarePathParametersOnPathItem)
        {
            // Arrange
            IEdmModel model = EntitySetPathItemHandlerTests.GetEdmModel(annotation: "");
            OpenApiConvertSettings convertSettings = new OpenApiConvertSettings
            {
                DeclarePathParametersOnPathItem = declarePathParametersOnPathItem,
            };
            ODataContext  context   = new ODataContext(model, convertSettings);
            IEdmEntitySet entitySet = model.EntityContainer.FindEntitySet("Customers");

            Assert.NotNull(entitySet); // guard
            ODataPath path = new ODataPath(new ODataNavigationSourceSegment(entitySet), new ODataKeySegment(entitySet.EntityType()));

            // Act
            var pathItem = _pathItemHandler.CreatePathItem(context, path);

            // Assert
            Assert.NotNull(pathItem);

            Assert.NotNull(pathItem.Operations);
            Assert.NotEmpty(pathItem.Operations);
            Assert.Equal(3, pathItem.Operations.Count);
            Assert.Equal(new OperationType[] { OperationType.Get, OperationType.Patch, OperationType.Delete },
                         pathItem.Operations.Select(o => o.Key));

            if (declarePathParametersOnPathItem)
            {
                Assert.NotEmpty(pathItem.Parameters);
                Assert.Equal(1, pathItem.Parameters.Count);
            }
            else
            {
                Assert.Empty(pathItem.Parameters);
            }
        }