Beispiel #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();
        }
Beispiel #2
0
        internal static CsdlEntityType EntityType(
            string name,
            string baseName                   = null,
            bool isAbstract                   = false,
            bool isOpen                       = false,
            bool hasStream                    = false,
            CsdlKey csdlKey                   = null,
            CsdlProperty[] properties         = default(CsdlProperty[]),
            CsdlNavigationProperty[] navProps = default(CsdlNavigationProperty[]),
            CsdlLocation location             = null)
        {
            if (properties == null)
            {
                properties = new CsdlProperty[] { };
            }

            if (navProps == null)
            {
                navProps = new CsdlNavigationProperty[] { };
            }

            return(new CsdlEntityType(
                       name,
                       baseName,
                       isAbstract,
                       isOpen,
                       hasStream,
                       csdlKey,
                       properties,
                       navProps,
                       location));
        }
Beispiel #3
0
        public void CsdlProperty_LazyGetCustomData_Test()
        {
            // Arrange
            var prop = new CsdlProperty();

            // Act
            // Assert
            Assert.IsNotNull(prop.CustomData);
        }
Beispiel #4
0
        public void CsdlProperty_SetCustomData_Test()
        {
            // Arrange
            var prop = new CsdlProperty();
            var expectedCustomData = new System.Collections.Generic.Dictionary <string, object>();

            prop.CustomData = expectedCustomData;

            // Act
            // Assert
            Assert.AreEqual(expectedCustomData, prop.CustomData);
        }
Beispiel #5
0
 public CsdlSemanticsProperty(CsdlSemanticsStructuredTypeDefinition declaringType, CsdlProperty property)
     : base(property)
 {
     this.property      = property;
     this.declaringType = declaringType;
 }
Beispiel #6
0
        public void ParseCsdlComplexTypeWithMembersWorksAsExpected()
        {
            string json = @"""CountRestrictionsType"": {
    ""$Kind"": ""ComplexType"",
    ""Countable"": {
        ""$Type"": ""Edm.Boolean"",
        ""$DefaultValue"": true,
        ""@Core.Description"": ""Entities can be counted (only valid if targeting an entity set)""
    },
    ""NonCountableProperties"": {
        ""$Collection"": true,
        ""$Type"": ""Edm.PropertyPath"",
        ""@Core.Description"": ""Members of these collection properties cannot be counted""
    },
    ""NonCountableNavigationProperties"": {
        ""$Collection"": true,
        ""$Type"": ""Edm.NavigationPropertyPath"",
        ""@Core.Description"": ""Members of these navigation properties cannot be counted""
    }
}";

            CsdlComplexType complexType = ParseCsdlSchemaElement(json, SchemaJsonParser.ParseCsdlComplexType);

            Assert.NotNull(complexType);

            Assert.Equal("CountRestrictionsType", complexType.Name);
            Assert.False(complexType.IsAbstract);
            Assert.False(complexType.IsOpen);
            Assert.Null(complexType.BaseTypeName);
            Assert.Empty(complexType.NavigationProperties);

            Assert.Equal(3, complexType.StructuralProperties.Count());

            // Countable
            CsdlProperty countable = complexType.StructuralProperties.FirstOrDefault(p => p.Name == "Countable");

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

            Assert.Equal(EdmPrimitiveTypeKind.Boolean, primitiveType.Kind);
            Assert.Equal("true", countable.DefaultValue);
            Assert.IsType <CsdlConstantExpression>(Assert.Single(countable.VocabularyAnnotations).Expression);

            // NonCountableProperties
            CsdlProperty nonCountable = complexType.StructuralProperties.FirstOrDefault(p => p.Name == "NonCountableProperties");

            Assert.NotNull(nonCountable);
            CsdlExpressionTypeReference expressionType = Assert.IsType <CsdlExpressionTypeReference>(nonCountable.Type);
            CsdlNamedTypeReference      namedType      = Assert.IsType <CsdlNamedTypeReference>(Assert.IsType <CsdlCollectionType>(expressionType.TypeExpression).ElementType);

            Assert.Equal("Edm.PropertyPath", namedType.FullName);
            Assert.Null(nonCountable.DefaultValue);
            Assert.IsType <CsdlConstantExpression>(Assert.Single(nonCountable.VocabularyAnnotations).Expression);

            // NonCountableNavigationProperties
            CsdlProperty nonCountableNav = complexType.StructuralProperties.FirstOrDefault(p => p.Name == "NonCountableNavigationProperties");

            Assert.NotNull(nonCountableNav);
            expressionType = Assert.IsType <CsdlExpressionTypeReference>(nonCountableNav.Type);
            namedType      = Assert.IsType <CsdlNamedTypeReference>(Assert.IsType <CsdlCollectionType>(expressionType.TypeExpression).ElementType);
            Assert.Equal("Edm.NavigationPropertyPath", namedType.FullName);
            Assert.Null(nonCountableNav.DefaultValue);
            Assert.IsType <CsdlConstantExpression>(Assert.Single(nonCountableNav.VocabularyAnnotations).Expression);
        }
Beispiel #7
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 CsdlSemanticsProperty(CsdlSemanticsStructuredTypeDefinition declaringType, CsdlProperty property) : base(property)
 {
     this.typeCache     = new Cache <CsdlSemanticsProperty, IEdmTypeReference>();
     this.property      = property;
     this.declaringType = declaringType;
 }