public CsdlSemanticsEntitySetTests()
        {
            var referentialConstraints = new List<CsdlReferentialConstraint>();
            var csdlNavigation = new CsdlNavigationProperty("Navigation", null, null, null, false, null, referentialConstraints, null, null);
            this.csdlEntityType = new CsdlEntityType("EntityType", null, false, false, false, null, Enumerable.Empty<CsdlProperty>(), new[] { csdlNavigation }, null, null);
            var goodBinding = new CsdlNavigationPropertyBinding("Navigation", "EntitySet", null, new CsdlLocation(1, 1));
            this.csdlEntitySet = new CsdlEntitySet("EntitySet", "FQ.NS.EntityType", new[] { goodBinding }, null, null);
            this.csdlContainer = new CsdlEntityContainer("Container", null, new[] { this.csdlEntitySet }, Enumerable.Empty<CsdlSingleton>(), Enumerable.Empty<CsdlOperationImport>(), null, null);

            var derivedCsdlNavigation = new CsdlNavigationProperty("DerivedNavigation", null, null, null, false, null, referentialConstraints, null, null);
            var derivedCsdlEntityType = new CsdlEntityType("DerivedEntityType", "FQ.NS.EntityType", false, false, false, null, Enumerable.Empty<CsdlProperty>(), new[] { derivedCsdlNavigation }, null, null);

            var unrelatedCsdlEntityType = new CsdlEntityType("UnrelatedEntityType", null, false, false, false, null, Enumerable.Empty<CsdlProperty>(), Enumerable.Empty<CsdlNavigationProperty>(), null, null);

            var csdlSchema = new CsdlSchema("FQ.NS", null, null, new[] { this.csdlEntityType, derivedCsdlEntityType, unrelatedCsdlEntityType }, Enumerable.Empty<CsdlEnumType>(), Enumerable.Empty<CsdlOperation>(),Enumerable.Empty<CsdlTerm>(),Enumerable.Empty<CsdlEntityContainer>(),Enumerable.Empty<CsdlAnnotations>(), Enumerable.Empty<CsdlTypeDefinition>(), null, null);
            var csdlModel = new CsdlModel();
            csdlModel.AddSchema(csdlSchema);
            var semanticModel = new CsdlSemanticsModel(csdlModel, new EdmDirectValueAnnotationsManager(), Enumerable.Empty<IEdmModel>());
            this.semanticSchema = new CsdlSemanticsSchema(semanticModel, csdlSchema);
            this.semanticContainer = new CsdlSemanticsEntityContainer(this.semanticSchema, this.csdlContainer);

            this.semanticEntityType = semanticModel.FindType("FQ.NS.EntityType") as CsdlSemanticsEntityTypeDefinition;
            this.semanticEntityType.Should().NotBeNull();
            this.navigationProperty = this.semanticEntityType.FindProperty("Navigation") as CsdlSemanticsNavigationProperty;
            this.navigationProperty.Should().NotBeNull();
        }
        public CsdlSemanticsNavigationPropertyTests()
        {
            var constraints = new[] { new CsdlReferentialConstraint("FK", "ID", null, null) };
            this.collectionProperty = new CsdlNavigationProperty("Collection", "Collection(FQ.NS.EntityType)", null, "Reference", false, null, constraints, null, null);
            this.referenceProperty = new CsdlNavigationProperty("Reference", "FQ.NS.EntityType", false, null, false, null, Enumerable.Empty<CsdlReferentialConstraint>(), null, null);

            var navigationWithoutPartner = new CsdlNavigationProperty("WithoutPartner", "FQ.NS.EntityType", false, null, false, null, Enumerable.Empty<CsdlReferentialConstraint>(), null, null);

            var idProperty = new CsdlProperty("ID", new CsdlNamedTypeReference("Edm.Int32", false, null), false, null, null, null);
            var fkProperty = new CsdlProperty("FK", new CsdlNamedTypeReference("Edm.Int32", false, null), false, null, null, null);
            this.csdlEntityType = new CsdlEntityType("EntityType", null, false, false, false, new CsdlKey(new[] { new CsdlPropertyReference("ID", null) }, null), new[] { idProperty, fkProperty }, new[] { collectionProperty, referenceProperty, navigationWithoutPartner }, null, null);

            var csdlSchema = new CsdlSchema("FQ.NS", null, null, new[] { this.csdlEntityType }, Enumerable.Empty<CsdlEnumType>(), Enumerable.Empty<CsdlOperation>(),Enumerable.Empty<CsdlTerm>(),Enumerable.Empty<CsdlEntityContainer>(),Enumerable.Empty<CsdlAnnotations>(), Enumerable.Empty<CsdlTypeDefinition>(), null, null);
            var csdlModel = new CsdlModel();
            csdlModel.AddSchema(csdlSchema);

            var semanticModel = new CsdlSemanticsModel(csdlModel, new EdmDirectValueAnnotationsManager(), Enumerable.Empty<IEdmModel>());
           
            this.semanticEntityType = semanticModel.FindType("FQ.NS.EntityType") as CsdlSemanticsEntityTypeDefinition;
            this.semanticEntityType.Should().NotBeNull();

            this.semanticCollectionNavigation = this.semanticEntityType.FindProperty("Collection") as CsdlSemanticsNavigationProperty;
            this.semanticReferenceNavigation = this.semanticEntityType.FindProperty("Reference") as CsdlSemanticsNavigationProperty;
            this.semanticNavigationWithoutPartner = this.semanticEntityType.FindProperty("WithoutPartner") as CsdlSemanticsNavigationProperty;

            this.semanticCollectionNavigation.Should().NotBeNull();
            this.semanticReferenceNavigation.Should().NotBeNull();
            this.semanticNavigationWithoutPartner.Should().NotBeNull();
        }
Exemplo n.º 3
0
        /// <summary>
        ///  Returns an IEdmModel for the given CSDL artifacts.
        /// </summary>
        /// <param name="readers">Collection of XmlReaders containing the CSDL artifacts.</param>
        /// <param name="references">Models to be references by the created model.</param>
        /// <param name="model">The model generated by parsing.</param>
        /// <param name="errors">Errors reported while parsing.</param>
        /// <returns>Success of the parse operation.</returns>
        public static bool TryParse(IEnumerable<XmlReader> readers, IEnumerable<IEdmModel> references, out IEdmModel model, out IEnumerable<EdmError> errors)
        {
            CsdlModel ast;
            if (CsdlParser.TryParse(readers, out ast, out errors))
            {
                model = new CsdlSemanticsModel(ast, new CsdlSemanticsDirectValueAnnotationsManager(), references);
                return true;
            }

            model = null;
            return false;
        }
        public CsdlSemanticsOperationTests()
        {
            this.csdlEntityType = new CsdlEntityType("EntityType", null, false, false, false, null, Enumerable.Empty<CsdlProperty>(), Enumerable.Empty<CsdlNavigationProperty>(), null, null);

            var csdlSchema = CsdlBuilder.Schema("FQ.NS", csdlStructuredTypes: new[] { this.csdlEntityType });
            
            var csdlModel = new CsdlModel();
            csdlModel.AddSchema(csdlSchema);
            var semanticModel = new CsdlSemanticsModel(csdlModel, new EdmDirectValueAnnotationsManager(), Enumerable.Empty<IEdmModel>());
            this.semanticSchema = new CsdlSemanticsSchema(semanticModel, csdlSchema);
            this.testLocation = new CsdlLocation(1, 3);
        }
 public CsdlSemanticsDirectValueAnnotation(CsdlDirectValueAnnotation annotation, CsdlSemanticsModel model)
     : base(annotation)
 {
     this.annotation = annotation;
     this.model = model;
 }
 public CsdlSemanticsDocumentation(CsdlDocumentation documentation, CsdlSemanticsModel model)
     : base(documentation)
 {
     this.documentation = documentation;
     this.model = model;
 }
Exemplo n.º 7
0
 private IEdmExpression ComputeOperand()
 {
     return(CsdlSemanticsModel.WrapExpression(this.expression.Operand, this.bindingContext, this.Schema));
 }
Exemplo n.º 8
0
 private IEdmTypeReference ComputeDeclaredType()
 {
     return(this.expression.Type != null?CsdlSemanticsModel.WrapTypeReference(this.Schema, this.expression.Type) : null);
 }
Exemplo n.º 9
0
 private IEdmTypeReference ComputeElementType()
 {
     return(CsdlSemanticsModel.WrapTypeReference(this.schema, this.collection.ElementType));
 }
Exemplo n.º 10
0
 private IEdmExpression ComputeIfFalse()
 {
     return(CsdlSemanticsModel.WrapExpression(this.expression.IfFalse, this.BindingContext, this.Schema));
 }
 private IEdmExpression ComputeBase()
 {
     return((this.expression.BaseExpression != null) ? CsdlSemanticsModel.WrapExpression(this.expression.BaseExpression, this.bindingContext, this.Schema) : null);
 }
Exemplo n.º 12
0
        /// <summary>
        /// Constructor for creating a referenced model, is private and only called by the above constructor.
        /// </summary>
        /// <param name="referencedCsdlModel">The referenced raw CsdlModel.</param>
        /// <param name="annotationsManager">The IEdmDirectValueAnnotationsManager.</param>
        /// <param name="mainCsdlSemanticsModel">The CsdlSemanticsModel that will reference this new CsdlSemanticsModel. </param>
        private CsdlSemanticsModel(CsdlModel referencedCsdlModel, IEdmDirectValueAnnotationsManager annotationsManager, CsdlSemanticsModel mainCsdlSemanticsModel)
            : base(Enumerable.Empty<IEdmModel>(), annotationsManager)
        {
            this.mainEdmModel = mainCsdlSemanticsModel;
            Debug.Assert(referencedCsdlModel.ParentModelReferences.Any(), "referencedCsdlModel.ParentModelReferences.Any()");
            this.astModel = referencedCsdlModel;
            this.SetEdmReferences(referencedCsdlModel.CurrentModelReferences);

            foreach (var tmp in referencedCsdlModel.ParentModelReferences.SelectMany(s => s.Includes))
            {
                string includeNs = tmp.Namespace;
                if (!referencedCsdlModel.Schemata.Any(s => s.Namespace == includeNs))
                {
                    // edmx:include must be an existing namespace
                    // TODO: REF throw exception: should include a namespace that exists in referenced model.
                }
            }

            foreach (var tmp in referencedCsdlModel.CurrentModelReferences.SelectMany(s => s.Includes))
            {
                // in any referenced model, alias may point to a further referenced model, now make alias available:
                this.SetNamespaceAlias(tmp.Namespace, tmp.Alias);
            }

            foreach (var schema in referencedCsdlModel.Schemata)
            {
                string schemaNamespace = schema.Namespace;
                IEdmInclude edmInclude = referencedCsdlModel.ParentModelReferences.SelectMany(s => s.Includes).FirstOrDefault(s => s.Namespace == schemaNamespace);
                if (edmInclude != null)
                {
                    this.AddSchema(schema, false /*addAnnotations*/);
                }

                // TODO: REF add annotations
            }
        }
Exemplo n.º 13
0
 private IEdmTypeReference ComputeType()
 {
     return(CsdlSemanticsModel.WrapTypeReference(this.declaringType.Context, this.property.Type));
 }
Exemplo n.º 14
0
 private IEdmExpression ComputeValue()
 {
     return(CsdlSemanticsModel.WrapExpression((this.Annotation).Expression, TargetBindingContext, this.Schema));
 }
 private IEdmTypeReference ComputeType()
 {
     return(CsdlSemanticsModel.WrapTypeReference(this.declaringOperation.Context, this.parameter.Type));
 }
Exemplo n.º 16
0
 public CsdlSemanticsInclude(CsdlSemanticsModel model, CsdlInclude include)
     : base(include)
 {
     this.model   = model;
     this.include = include;
 }
Exemplo n.º 17
0
        private bool TryParse(IEnumerable<IEdmModel> referencedModels, out IEdmModel model, out IEnumerable<EdmError> parsingErrors)
        {
            Version edmxVersion;
            CsdlModel astModel;

            TryParseEdmxFileToCsdlModel(out edmxVersion, out astModel);

            if (!this.HasIntolerableError())
            {
                List<CsdlModel> referencedAstModels = this.LoadAndParseReferencedEdmxFiles(edmxVersion);

                IEnumerable<EdmError> csdlErrors;
                this.csdlParser.GetResult(out astModel, out csdlErrors);
                if (csdlErrors != null)
                {
                    this.errors.AddRange(csdlErrors.Except(this.errors));
                }

                if (!this.HasIntolerableError())
                {
                    CsdlSemanticsModel tmp = new CsdlSemanticsModel(astModel, new CsdlSemanticsDirectValueAnnotationsManager(), referencedAstModels);

                    // add more referenced IEdmModels in addition to the above loaded CsdlModels.
                    tmp.AddToReferencedModels(referencedModels);
                    model = tmp;
                    Debug.Assert(edmxVersion != null, "edmxVersion != null");
                    model.SetEdmxVersion(edmxVersion);
                }
                else
                {
                    model = null;
                }
            }
            else
            {
                model = null;
            }

            parsingErrors = this.errors;

            return !this.HasIntolerableError();
        }
Exemplo n.º 18
0
        /// <summary>
        /// Constructor for creating a referenced model, is private and only called by the above constructor.
        /// </summary>
        /// <param name="referencedCsdlModel">The referenced raw CsdlModel.</param>
        /// <param name="annotationsManager">The IEdmDirectValueAnnotationsManager.</param>
        /// <param name="mainCsdlSemanticsModel">The CsdlSemanticsModel that will reference this new CsdlSemanticsModel. </param>
        /// <param name="includeDefaultVocabularies">A value indicating enable/disable the built-in vocabulary supporting.</param>
        private CsdlSemanticsModel(CsdlModel referencedCsdlModel, IEdmDirectValueAnnotationsManager annotationsManager, CsdlSemanticsModel mainCsdlSemanticsModel, bool includeDefaultVocabularies)
            : base(Enumerable.Empty <IEdmModel>(), annotationsManager, includeDefaultVocabularies)
        {
            this.mainEdmModel = mainCsdlSemanticsModel;
            Debug.Assert(referencedCsdlModel.ParentModelReferences.Any(), "referencedCsdlModel.ParentModelReferences.Any()");
            this.astModel = referencedCsdlModel;
            this.SetEdmReferences(referencedCsdlModel.CurrentModelReferences);

            foreach (var tmp in referencedCsdlModel.ParentModelReferences.SelectMany(s => s.Includes))
            {
                string includeNs = tmp.Namespace;
                if (!referencedCsdlModel.Schemata.Any(s => s.Namespace == includeNs))
                {
                    // edmx:include must be an existing namespace
                    // TODO: REF throw exception: should include a namespace that exists in referenced model.
                }
            }

            foreach (var tmp in referencedCsdlModel.CurrentModelReferences.SelectMany(s => s.Includes))
            {
                // in any referenced model, alias may point to a further referenced model, now make alias available:
                this.SetNamespaceAlias(tmp.Namespace, tmp.Alias);
            }

            foreach (var schema in referencedCsdlModel.Schemata)
            {
                string      schemaNamespace = schema.Namespace;
                IEdmInclude edmInclude      = referencedCsdlModel.ParentModelReferences.SelectMany(s => s.Includes).FirstOrDefault(s => s.Namespace == schemaNamespace);
                if (edmInclude != null)
                {
                    this.AddSchema(schema, false /*addAnnotations*/);
                }

                // TODO: REF add annotations
            }
        }
Exemplo n.º 19
0
        public void TryGetEntitySetWithBoundCsdlSemanticOperationParameterShouldReturnTrueAndHaveNoErrors()
        {
            var csdlEntityType = new CsdlEntityType("EntityType", null, false, false, false, null, Enumerable.Empty<CsdlProperty>(), Enumerable.Empty<CsdlNavigationProperty>(), null, null);
            var csdlSchema = CsdlBuilder.Schema("FQ.NS", csdlStructuredTypes: new[] { csdlEntityType });

            var csdlModel = new CsdlModel();
            csdlModel.AddSchema(csdlSchema);
            var semanticModel = new CsdlSemanticsModel(csdlModel, new EdmDirectValueAnnotationsManager(), Enumerable.Empty<IEdmModel>());
            var semanticSchema = new CsdlSemanticsSchema(semanticModel, csdlSchema);
            var testLocation = new CsdlLocation(1, 3);

            var action = new CsdlAction(
                "Checkout",
                new CsdlOperationParameter[] { new CsdlOperationParameter("entity", new CsdlNamedTypeReference("FQ.NS.EntityType", false, testLocation), null, testLocation) },
                new CsdlNamedTypeReference("Edm.String", false, testLocation),
                true /*isBound*/,
                "entity",
                null /*documentation*/,
                testLocation);

            var semanticAction = new CsdlSemanticsAction(semanticSchema, action);
            IEdmOperationParameter edmParameter;
            IEnumerable<IEdmNavigationProperty> navigationProperties;
            IEdmEntityType entityType;
            IEnumerable<EdmError> errors;
            semanticAction.TryGetRelativeEntitySetPath(semanticSchema.Model, out edmParameter, out navigationProperties, out entityType, out errors).Should().BeTrue();
            edmParameter.Name.Should().Be("entity");
            navigationProperties.Should().BeEmpty();
            entityType.FullName().Should().Be("FQ.NS.EntityType");
            errors.Should().BeEmpty();
        }
 public CsdlSemanticsDocumentation(CsdlDocumentation documentation, CsdlSemanticsModel model)
     : base(documentation)
 {
     this.documentation = documentation;
     this.model         = model;
 }
Exemplo n.º 21
0
 private IEdmExpression ComputeExpression()
 {
     return(CsdlSemanticsModel.WrapExpression(this.sourceElement, this.BindingContext, this.schema));
 }
 public CsdlSemanticsDirectValueAnnotation(CsdlDirectValueAnnotation annotation, CsdlSemanticsModel model)
     : base(annotation)
 {
     this.annotation = annotation;
     this.model      = model;
 }