Exemple #1
0
        public CsdlSemanticsNavigationPropertyTests()
        {
            var constraints = new[] { new CsdlReferentialConstraint("FK", "ID", null) };

            this.collectionProperty = new CsdlNavigationProperty("Collection", "Collection(FQ.NS.EntityType)", null, "Reference", false, null, constraints, null);
            this.referenceProperty  = new CsdlNavigationProperty("Reference", "FQ.NS.EntityType", false, null, false, null, Enumerable.Empty <CsdlReferentialConstraint>(), null);

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

            var idProperty = new CsdlProperty("ID", new CsdlNamedTypeReference("Edm.Int32", false, null), null, null);
            var fkProperty = new CsdlProperty("FK", new CsdlNamedTypeReference("Edm.Int32", 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);

            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);
            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();
        }
Exemple #2
0
        private IEnumerable <IEdmSchemaType> ComputeTypes()
        {
            List <IEdmSchemaType> types = new List <IEdmSchemaType>();

            foreach (var structuredType in this.schema.StructuredTypes)
            {
                CsdlEntityType entity = structuredType as CsdlEntityType;
                if (entity != null)
                {
                    types.Add(new CsdlSemanticsEntityTypeDefinition(this, entity));
                }
                else
                {
                    CsdlComplexType complex = structuredType as CsdlComplexType;
                    if (complex != null)
                    {
                        types.Add(new CsdlSemanticsComplexTypeDefinition(this, complex));
                    }
                }
            }

            foreach (var enumType in this.schema.EnumTypes)
            {
                types.Add(new CsdlSemanticsEnumTypeDefinition(this, enumType));
            }

            return(types);
        }
        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();
        }
Exemple #4
0
        private IEnumerable <IEdmSchemaType> ComputeTypes()
        {
            List <IEdmSchemaType> list = new List <IEdmSchemaType>();

            foreach (CsdlStructuredType type in this.schema.StructuredTypes)
            {
                CsdlEntityType entity = type as CsdlEntityType;
                if (entity != null)
                {
                    list.Add(new CsdlSemanticsEntityTypeDefinition(this, entity));
                }
                else
                {
                    CsdlComplexType complex = type as CsdlComplexType;
                    if (complex != null)
                    {
                        list.Add(new CsdlSemanticsComplexTypeDefinition(this, complex));
                    }
                }
            }
            foreach (CsdlEnumType type4 in this.schema.EnumTypes)
            {
                list.Add(new CsdlSemanticsEnumTypeDefinition(this, type4));
            }
            return(list);
        }
Exemple #5
0
        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();
        }
Exemple #6
0
        private IEnumerable <IEdmSchemaType> ComputeTypes()
        {
            List <IEdmSchemaType> types = new List <IEdmSchemaType>();

            foreach (var typeDefinition in schema.TypeDefinitions)
            {
                this.AttachDefaultPrimitiveValueConverter(typeDefinition);
                types.Add(new CsdlSemanticsTypeDefinitionDefinition(this, typeDefinition));
            }

            foreach (var structuredType in this.schema.StructuredTypes)
            {
                CsdlEntityType entity = structuredType as CsdlEntityType;
                if (entity != null)
                {
                    types.Add(new CsdlSemanticsEntityTypeDefinition(this, entity));
                }
                else
                {
                    CsdlComplexType complex = structuredType as CsdlComplexType;
                    if (complex != null)
                    {
                        types.Add(new CsdlSemanticsComplexTypeDefinition(this, complex));
                    }
                }
            }

            foreach (var enumType in this.schema.EnumTypes)
            {
                types.Add(new CsdlSemanticsEnumTypeDefinition(this, enumType));
            }

            return(types);
        }
Exemple #7
0
        private static CsdlSemanticsSchema CreateCsdlSemanticsSchema(CsdlEntityContainer csdlEntityContainer, params CsdlOperation[] operations)
        {
            var csdlEntityType = new CsdlEntityType("EntityType", null, false, false, false, null, new Collection <CsdlProperty>(), new System.Collections.Generic.List <CsdlNavigationProperty>(), null, null);
            var schema         = CsdlBuilder.Schema("FQ.NS", csdlOperations: operations, csdlEntityContainers: new CsdlEntityContainer[] { csdlEntityContainer }, csdlStructuredTypes: new CsdlStructuredType[] { csdlEntityType });
            var csdlModel      = new CsdlModel();

            csdlModel.AddSchema(schema);
            var semanticSchema = new CsdlSemanticsSchema(new CsdlSemanticsModel(csdlModel, new EdmDirectValueAnnotationsManager(), Enumerable.Empty <IEdmModel>()), schema);

            return(semanticSchema);
        }
Exemple #8
0
        public CsdlSemanticsOperationTests()
        {
            this.csdlEntityType = new CsdlEntityType("EntityType", null, false, false, false, null, Enumerable.Empty <CsdlProperty>(), Enumerable.Empty <CsdlNavigationProperty>(), 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 CsdlSemanticsEntityTypeDefinition(CsdlSemanticsSchema context, CsdlEntityType entity)
     : base(context, entity)
 {
     this.entity = entity;
 }
 public CsdlSemanticsEntityTypeDefinition(CsdlSemanticsSchema context, CsdlEntityType entity) : base(context, entity)
 {
     this.baseTypeCache    = new Cache <CsdlSemanticsEntityTypeDefinition, IEdmEntityType>();
     this.declaredKeyCache = new Cache <CsdlSemanticsEntityTypeDefinition, IEnumerable <IEdmStructuralProperty> >();
     this.entity           = entity;
 }
Exemple #11
0
        public void ParseCsdlEntityTypeWithMembersWorksAsExpected()
        {
            string json = @"""Supplier"": {
  ""$Kind"": ""EntityType"",
  ""$Key"": [
    ""ID""
  ],
  ""ID"": {},
  ""Name"": {
    ""$Nullable"": true
  },
  ""Address"": {
    ""$Type"": ""self.Address""
  },
  ""Concurrency"": {
    ""$Type"": ""Edm.Int32""
  },
  ""Products"": {
    ""$Kind"": ""NavigationProperty"",
    ""$Partner"": ""Supplier"",
    ""$Collection"": true,
    ""$Type"": ""self.Product""
  }
}";

            CsdlEntityType entityType = ParseCsdlSchemaElement(json, SchemaJsonParser.ParseCsdlEntityType);

            Assert.NotNull(entityType);

            Assert.Equal("Supplier", entityType.Name);
            Assert.False(entityType.IsAbstract);
            Assert.False(entityType.IsOpen);
            Assert.Null(entityType.BaseTypeName);
            Assert.False(entityType.HasStream);

            CsdlPropertyReference propertyRef = Assert.Single(entityType.Key.Properties);

            Assert.Equal("ID", propertyRef.PropertyName);

            Assert.Equal(4, entityType.StructuralProperties.Count());
            // ID
            CsdlProperty id = entityType.StructuralProperties.FirstOrDefault(p => p.Name == "ID");

            Assert.NotNull(id);
            CsdlStringTypeReference stringType = Assert.IsType <CsdlStringTypeReference>(id.Type);

            Assert.False(stringType.IsUnbounded);
            Assert.Null(stringType.IsUnicode);
            Assert.Null(stringType.MaxLength);
            Assert.False(stringType.IsNullable);

            // Name
            CsdlProperty name = entityType.StructuralProperties.FirstOrDefault(p => p.Name == "Name");

            Assert.NotNull(name);
            stringType = Assert.IsType <CsdlStringTypeReference>(name.Type);
            Assert.True(stringType.IsNullable);

            // Address
            CsdlProperty address = entityType.StructuralProperties.FirstOrDefault(p => p.Name == "Address");

            Assert.NotNull(address);
            CsdlNamedTypeReference namedType = Assert.IsType <CsdlNamedTypeReference>(address.Type);

            Assert.Equal("self.Address", namedType.FullName);

            // Concurrency
            CsdlProperty concurrency = entityType.StructuralProperties.FirstOrDefault(p => p.Name == "Concurrency");

            Assert.NotNull(concurrency);
            CsdlPrimitiveTypeReference primitiveType = Assert.IsType <CsdlPrimitiveTypeReference>(concurrency.Type);

            Assert.Equal(EdmPrimitiveTypeKind.Int32, primitiveType.Kind);
            Assert.False(primitiveType.IsNullable);

            // Products
            CsdlNavigationProperty products = Assert.Single(entityType.NavigationProperties);

            Assert.Equal("Products", products.Name);
            Assert.Equal("Collection(self.Product)", products.Type);
            Assert.Equal("Supplier", products.PartnerPath.Path);
        }
 public CsdlSemanticsEntityTypeDefinition(CsdlSemanticsSchema context, CsdlEntityType entity)
     : base(context, entity)
 {
     this.entity   = entity;
     this.fullName = EdmUtil.GetFullNameForSchemaElement(context?.Namespace, this.entity?.Name);
 }