Beispiel #1
0
        public void GetPathForOperationOfEntitySet_Returns()
        {
            // Arrange & Act
            string path = ODataSwaggerUtilities.GetPathForOperationOfEntitySet(_isAnyUpgraded, _customers);

            // Assert
            Assert.NotNull(path);
            Assert.Equal("/Customers/NS.IsAnyUpgraded()", path);
        }
Beispiel #2
0
        /// <summary>
        /// Initialize the operations to Swagger model.
        /// </summary>
        protected virtual void InitializeOperations()
        {
            Contract.Assert(SwaggerDoc != null);
            Contract.Assert(EdmModel != null);
            Contract.Assert(SwaggerPaths != null);

            if (EdmModel.EntityContainer == null)
            {
                return;
            }

            foreach (var operation in EdmModel.SchemaElements.OfType <IEdmOperation>())
            {
                // skip unbound operation
                if (!operation.IsBound)
                {
                    continue;
                }

                var boundParameter = operation.Parameters.First();
                var boundType      = boundParameter.Type.Definition;

                // skip operation bound to non entity (or entity collection)
                if (boundType.TypeKind == EdmTypeKind.Entity)
                {
                    IEdmEntityType entityType = (IEdmEntityType)boundType;
                    foreach (var entitySet in
                             EdmModel.EntityContainer.EntitySets().Where(es => es.EntityType().Equals(entityType)))
                    {
                        SwaggerPaths.Add(ODataSwaggerUtilities.GetPathForOperationOfEntity(operation, entitySet),
                                         ODataSwaggerUtilities.CreateSwaggerPathForOperationOfEntity(operation, entitySet));
                    }
                }
                else if (boundType.TypeKind == EdmTypeKind.Collection)
                {
                    IEdmCollectionType collectionType = boundType as IEdmCollectionType;

                    if (collectionType != null && collectionType.ElementType.Definition.TypeKind == EdmTypeKind.Entity)
                    {
                        IEdmEntityType entityType = (IEdmEntityType)collectionType.ElementType.Definition;
                        foreach (var entitySet in
                                 EdmModel.EntityContainer.EntitySets().Where(es => es.EntityType().Equals(entityType)))
                        {
                            SwaggerPaths.Add(ODataSwaggerUtilities.GetPathForOperationOfEntitySet(operation, entitySet),
                                             ODataSwaggerUtilities.CreateSwaggerPathForOperationOfEntitySet(operation, entitySet));
                        }
                    }
                }
            }
        }