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 EnsureEntitySetResolvesToUnknownEntitySet()
        {
            var action = CsdlBuilder.Action("Checkout");
            var actionImport = new CsdlActionImport("Checkout", "FQ.NS.Checkout", "OtherSet" /*entitySet*/, null /*documentation*/, testLocation);
            var csdlEntityContainer = CsdlBuilder.EntityContainer("Container");

            var semanticSchema = CreateCsdlSemanticsSchema(csdlEntityContainer, action);
            var semanticAction = new CsdlSemanticsAction(semanticSchema, action);

            var csdlSemanticEntityContainer = new CsdlSemanticsEntityContainer(semanticSchema, csdlEntityContainer);
            var semanticActionImport = new CsdlSemanticsActionImport(csdlSemanticEntityContainer, actionImport, semanticAction);
            semanticActionImport.Action.Should().NotBeNull();
            semanticActionImport.Action.Name.Should().Be("Checkout");
            var edmEntitySetReference = (IEdmEntitySetReferenceExpression)semanticActionImport.EntitySet;
            edmEntitySetReference.ReferencedEntitySet.Name.Should().Be("OtherSet");
        }
        public void EnsureEntitySetReferenceResolvesCorrectly()
        {
            var action = CsdlBuilder.Action("Checkout");
            var actionImport = new CsdlActionImport("Checkout", "FQ.NS.Checkout", "EntitySet" /*entitySet*/, null /*documentation*/, testLocation);
            var csdlEntitySet = new CsdlEntitySet("EntitySet", "FQ.NS.EntityType", Enumerable.Empty<CsdlNavigationPropertyBinding>(), null, testLocation);
            var csdlEntityContainer = CsdlBuilder.EntityContainer("Container", entitySets: new CsdlEntitySet[] { csdlEntitySet });

            var semanticSchema = CreateCsdlSemanticsSchema(csdlEntityContainer, action);
            var semanticAction = new CsdlSemanticsAction(semanticSchema, action);

            var csdlSemanticEntityContainer = new CsdlSemanticsEntityContainer(semanticSchema, csdlEntityContainer);
            var semanticActionImport = new CsdlSemanticsActionImport(csdlSemanticEntityContainer, actionImport, semanticAction);
            semanticActionImport.Action.Should().NotBeNull();
            semanticActionImport.Action.Name.Should().Be("Checkout");
            var edmEntitySetReference = (IEdmEntitySetReferenceExpression)semanticActionImport.EntitySet;
            edmEntitySetReference.ReferencedEntitySet.Name.Should().Be("EntitySet");
        }
        public void EnsureEntitySetResolvesToEdmPathExpression()
        {
            var action = CsdlBuilder.Action("Checkout");
            var actionImport = new CsdlActionImport("Checkout", "FQ.NS.Checkout", "Nav1/Nav2" /*entitySet*/, null /*documentation*/, testLocation);
            var csdlEntityContainer = CsdlBuilder.EntityContainer("Container");

            var semanticSchema = CreateCsdlSemanticsSchema(csdlEntityContainer, action);
            var semanticAction = new CsdlSemanticsAction(semanticSchema, action);

            var csdlSemanticEntityContainer = new CsdlSemanticsEntityContainer(semanticSchema, csdlEntityContainer);
            var semanticActionImport = new CsdlSemanticsActionImport(csdlSemanticEntityContainer, actionImport, semanticAction);
            semanticActionImport.Action.Should().NotBeNull();
            semanticActionImport.Action.Name.Should().Be("Checkout");
            var pathExpression = (IEdmPathExpression)semanticActionImport.EntitySet;
            var items = pathExpression.Path.ToList();
            items[0].Should().Be("Nav1");
            items[1].Should().Be("Nav2");
        }
        public void CsdlSemanticsActionImportPropertiesShouldBeInitializedCorrectly()
        {
            var action = CsdlBuilder.Action("Checkout");
            var actionImport = new CsdlActionImport("Checkout", "FQ.NS.Checkout", null, null /*documentation*/, testLocation);
            var csdlEntityContainer = CsdlBuilder.EntityContainer("Container");

            var semanticSchema = CreateCsdlSemanticsSchema(csdlEntityContainer, action);
            var semanticAction = new CsdlSemanticsAction(semanticSchema, action);

            var csdlSemanticEntityContainer = new CsdlSemanticsEntityContainer(semanticSchema, csdlEntityContainer);
            var semanticActionImport = new CsdlSemanticsActionImport(csdlSemanticEntityContainer, actionImport, semanticAction);
            semanticActionImport.Action.Should().NotBeNull();
            semanticActionImport.Action.Name.Should().Be("Checkout");
            semanticActionImport.Container.Name.Should().Be("Container");
            semanticActionImport.Location().Should().Be(testLocation);
            semanticActionImport.ContainerElementKind.Should().Be(EdmContainerElementKind.ActionImport);
            semanticActionImport.EntitySet.Should().BeNull();
        }
        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);
            }
        }