public void CreateSwaggerPathForOperationOfEntity_ReturnsSwaggerObject() { // Arrange & Act JObject obj = ODataSwaggerUtilities.CreateSwaggerPathForOperationOfEntity(_isCustomerUpgradedWithParam, _customers); // Assert Assert.NotNull(obj); Assert.Contains("\"Call operation IsUpgradedWithParam\"", obj.ToString()); }
/// <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)); } } } } }