private void AddOperationImport(CsdlOperationImport operationImport, List <IEdmEntityContainerElement> elements)
        {
            var functionImport = operationImport as CsdlFunctionImport;
            var actionImport   = operationImport as CsdlActionImport;
            CsdlSemanticsOperationImport semanticsOperation = null;
            EdmSchemaElementKind         filterKind         = EdmSchemaElementKind.Action;

            if (functionImport != null)
            {
                filterKind = EdmSchemaElementKind.Function;
            }

            // OperationImports only work with non-bound operations hence this extra logic in the where clause
            var operations = this.context.FindOperations(operationImport.SchemaOperationQualifiedTypeName).Where(o => o.SchemaElementKind == filterKind && !o.IsBound);

            int operationsCount = 0;

            foreach (IEdmOperation operation in operations)
            {
                if (functionImport != null)
                {
                    semanticsOperation = new CsdlSemanticsFunctionImport(this, functionImport, (IEdmFunction)operation);
                }
                else
                {
                    Debug.Assert(actionImport != null, "actionImport should not be null");
                    semanticsOperation = new CsdlSemanticsActionImport(this, actionImport, (IEdmAction)operation);
                }

                operationsCount++;
                elements.Add(semanticsOperation);
            }

            // If none have been created then its an unresolved operation.
            if (operationsCount == 0)
            {
                if (filterKind == EdmSchemaElementKind.Action)
                {
                    var action = new UnresolvedAction(operationImport.SchemaOperationQualifiedTypeName, Edm.Strings.Bad_UnresolvedOperation(operationImport.SchemaOperationQualifiedTypeName), operationImport.Location);
                    semanticsOperation = new CsdlSemanticsActionImport(this, actionImport, action);
                }
                else
                {
                    Debug.Assert(filterKind == EdmSchemaElementKind.Function, "Should be a function");
                    var function = new UnresolvedFunction(operationImport.SchemaOperationQualifiedTypeName, Edm.Strings.Bad_UnresolvedOperation(operationImport.SchemaOperationQualifiedTypeName), operationImport.Location);
                    semanticsOperation = new CsdlSemanticsFunctionImport(this, functionImport, function);
                }

                elements.Add(semanticsOperation);
            }
        }
        public void CsdlSemanticsFunctionImportPropertiesShouldBeInitializedCorrectly()
        {
            // Added to ensure this is filtered out
            var function = CsdlBuilder.Function("GetStuff");
            
            var functionImport = new CsdlFunctionImport("GetStuff", "FQ.NS.GetStuff", null /*entitySet*/, true /*includeInServiceDocument*/, null /*documentation*/, testLocation);
            var csdlEntityContainer = CsdlBuilder.EntityContainer("Container");

            var semanticSchema = CreateCsdlSemanticsSchema(csdlEntityContainer, function);
            var semanticFunction = new CsdlSemanticsFunction(semanticSchema, function);

            var csdlSemanticEntityContainer = new CsdlSemanticsEntityContainer(semanticSchema, csdlEntityContainer);
            var semanticActionImport = new CsdlSemanticsFunctionImport(csdlSemanticEntityContainer, functionImport, semanticFunction);
            semanticActionImport.Function.Should().NotBeNull();
            semanticActionImport.Function.Name.Should().Be("GetStuff");
            semanticActionImport.Container.Name.Should().Be("Container");
            semanticActionImport.Location().Should().Be(testLocation);
            semanticActionImport.ContainerElementKind.Should().Be(EdmContainerElementKind.FunctionImport);
            semanticActionImport.EntitySet.Should().BeNull();
            semanticActionImport.IncludeInServiceDocument.Should().BeTrue();
        }
        private void AddOperationImport(CsdlOperationImport operationImport, List<IEdmEntityContainerElement> elements)
        {
            var functionImport = operationImport as CsdlFunctionImport;
            var actionImport = operationImport as CsdlActionImport;
            CsdlSemanticsOperationImport semanticsOperation = null;
            EdmSchemaElementKind filterKind = EdmSchemaElementKind.Action;
            if (functionImport != null)
            {
                filterKind = EdmSchemaElementKind.Function;
            }

            // OperationImports only work with non-bound operations hence this extra logic in the where clause
            var operations = this.context.FindOperations(operationImport.SchemaOperationQualifiedTypeName).Where(o => o.SchemaElementKind == filterKind && !o.IsBound);

            int operationsCount = 0;
            foreach (IEdmOperation operation in operations)
            {
                if (functionImport != null)
                {
                    semanticsOperation = new CsdlSemanticsFunctionImport(this, functionImport, (IEdmFunction)operation);
                }
                else
                {
                    Debug.Assert(actionImport != null, "actionImport should not be null");
                    semanticsOperation = new CsdlSemanticsActionImport(this, actionImport, (IEdmAction)operation);
                }

                operationsCount++;
                elements.Add(semanticsOperation);
            }

            // If none have been created then its an unresolved operation.
            if (operationsCount == 0)
            {
                if (filterKind == EdmSchemaElementKind.Action)
                {
                    var action = new UnresolvedAction(operationImport.SchemaOperationQualifiedTypeName, Edm.Strings.Bad_UnresolvedOperation(operationImport.SchemaOperationQualifiedTypeName), operationImport.Location);
                    semanticsOperation = new CsdlSemanticsActionImport(this, actionImport, action);
                }
                else
                {
                    Debug.Assert(filterKind == EdmSchemaElementKind.Function, "Should be a function");
                    var function = new UnresolvedFunction(operationImport.SchemaOperationQualifiedTypeName, Edm.Strings.Bad_UnresolvedOperation(operationImport.SchemaOperationQualifiedTypeName), operationImport.Location);
                    semanticsOperation = new CsdlSemanticsFunctionImport(this, functionImport, function);
                }

                elements.Add(semanticsOperation);
            }
        }