protected override void ProcessComplexType(IEdmComplexType element)
 {
     base.ProcessComplexType(element);
     if (element.BaseComplexType() != null)
     {
         this.CheckSchemaElementReference(element.BaseComplexType());
     }
 }
		protected override void ProcessComplexType(IEdmComplexType element)
		{
			base.ProcessComplexType(element);
			if (element.BaseComplexType() != null)
			{
				this.CheckSchemaElementReference(element.BaseComplexType());
			}
		}
예제 #3
0
        public void CanCreateDerivedComplexType()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();

            builder.ComplexType <BaseComplexType>().Abstract().Property(v => v.BaseProperty);
            builder.ComplexType <DerivedComplexType>().DerivesFrom <BaseComplexType>().Property(v => v.DerivedProperty);

            // Act
            IEdmModel model = builder.GetEdmModel();

            // Assert
            IEdmComplexType baseComplexType = model.AssertHasComplexType(typeof(BaseComplexType));

            Assert.Null(baseComplexType.BaseComplexType());
            Assert.Single(baseComplexType.Properties());
            baseComplexType.AssertHasPrimitiveProperty(model, "BaseProperty", EdmPrimitiveTypeKind.String, true);

            IEdmComplexType derivedComplexType = model.AssertHasComplexType(typeof(DerivedComplexType));

            Assert.Equal(baseComplexType, derivedComplexType.BaseComplexType());
            Assert.Equal(2, derivedComplexType.Properties().Count());
            derivedComplexType.AssertHasPrimitiveProperty(model, "BaseProperty", EdmPrimitiveTypeKind.String, true);
            derivedComplexType.AssertHasPrimitiveProperty(model, "DerivedProperty", EdmPrimitiveTypeKind.Int32, false);
        }
예제 #4
0
 internal void WriteComplexTypeElementHeader(IEdmComplexType complexType)
 {
     this.xmlWriter.WriteStartElement(CsdlConstants.Element_ComplexType);
     this.WriteRequiredAttribute(CsdlConstants.Attribute_Name, complexType.Name, EdmValueWriter.StringAsXml);
     this.WriteOptionalAttribute(CsdlConstants.Attribute_BaseType, complexType.BaseComplexType(), this.TypeDefinitionAsXml);
     this.WriteOptionalAttribute(CsdlConstants.Attribute_Abstract, complexType.IsAbstract, CsdlConstants.Default_Abstract, EdmValueWriter.BooleanAsXml);
 }
 internal void WriteComplexTypeElementHeader(IEdmComplexType complexType)
 {
     this.xmlWriter.WriteStartElement("ComplexType");
     this.WriteRequiredAttribute <string>("Name", complexType.Name, new Func <string, string>(EdmValueWriter.StringAsXml));
     this.WriteOptionalAttribute <IEdmComplexType>("BaseType", complexType.BaseComplexType(), new Func <IEdmComplexType, string>(this.TypeDefinitionAsXml));
     this.WriteOptionalAttribute <bool>("Abstract", complexType.IsAbstract, false, new Func <bool, string>(EdmValueWriter.BooleanAsXml));
 }
예제 #6
0
        public static IEdmComplexType AssertHasComplexType(this IEdmModel model, Type mappedComplexClrType, Type mappedComplexBaseType)
        {
            IEdmComplexType complex     = AssertHasComplexType(model, mappedComplexClrType);
            IEdmComplexType baseComplex = AssertHasComplexType(model, mappedComplexBaseType);

            Assert.Equal(baseComplex, complex.BaseComplexType());
            return(complex);
        }
예제 #7
0
        /// <summary>
        /// Find all base types for a given <see cref="IEdmComplexType"/>
        /// </summary>
        /// <param name="complexType">The given complex type.</param>
        /// <returns>All base types or null.</returns>
        public static IEnumerable <IEdmComplexType> FindAllBaseTypes(this IEdmComplexType complexType)
        {
            if (complexType == null)
            {
                yield return(null);
            }

            IEdmComplexType current = complexType.BaseComplexType();

            while (current != null)
            {
                yield return(current);

                current = current.BaseComplexType();
            }
        }
예제 #8
0
        public void CanDefinePropertyOnDerivedType_NotPresentInBaseType_ButPresentInDerivedType()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();
            builder.ComplexType<DerivedComplexType>().DerivesFrom<BaseComplexType>().Property(m => m.BaseProperty);

            // Act
            IEdmModel model = builder.GetEdmModel();

            // Assert
            IEdmComplexType baseComplex = model.AssertHasComplexType(typeof(BaseComplexType));
            Assert.Null(baseComplex.BaseComplexType());
            Assert.Empty(baseComplex.Properties());

            IEdmComplexType derivedComplex = model.AssertHasComplexType(typeof(DerivedComplexType));
            Assert.Equal(baseComplex, derivedComplex.BaseComplexType());
            Assert.Single(derivedComplex.Properties());
            derivedComplex.AssertHasPrimitiveProperty(model, "BaseProperty", EdmPrimitiveTypeKind.String, true);
        }
예제 #9
0
        public void ComplexType_reference_extensions()
        {
            IEdmModel       edmModel           = this.GetEdmModel();
            IEdmComplexType derivedComplexType = edmModel.SchemaElements.OfType <IEdmComplexType>().First(c => c.BaseType != null);
            IEdmComplexType baseComplexType    = derivedComplexType.BaseComplexType();

            Assert.IsNotNull(baseComplexType, "Base complex type should not be null!");

            IEdmComplexTypeReference derivedComplexTypeRef = (IEdmComplexTypeReference)derivedComplexType.ToTypeReference();

            Assert.AreEqual(baseComplexType, derivedComplexTypeRef.BaseComplexType(), "ComplexTypeReference.BaseComplexType()");
            Assert.AreEqual(baseComplexType, derivedComplexTypeRef.BaseType(), "ComplexTypeReference.BaseType()");

            Assert.AreEqual(derivedComplexType.IsAbstract, derivedComplexTypeRef.IsAbstract(), "StructuralTypeReference.IsAbstract()");
            Assert.AreEqual(derivedComplexType.IsOpen, derivedComplexTypeRef.IsOpen(), "StructuralTypeReference.IsOpen()");

            Assert.AreEqual(derivedComplexType.DeclaredStructuralProperties().Count(), derivedComplexTypeRef.DeclaredStructuralProperties().Count(), "StructuralTypeReference.DeclaredStructuralProperties()");
            Assert.AreEqual(derivedComplexType.StructuralProperties().Count(), derivedComplexTypeRef.StructuralProperties().Count(), "StructuralTypeReference.StructuralProperties()");
        }
예제 #10
0
        private ComplexType ConvertToTaupoComplexType(IEdmComplexType edmComplexType)
        {
            // Taupo TODO: Abstract for ComplexType
            var taupoComplexType = new ComplexType(edmComplexType.Namespace, edmComplexType.Name);

            if (edmComplexType.BaseType != null)
            {
                taupoComplexType.BaseType = new ComplexTypeReference(edmComplexType.BaseComplexType().Namespace, edmComplexType.BaseComplexType().Name);
            }

            foreach (var edmProperty in edmComplexType.DeclaredStructuralProperties())
            {
                var taupoProperty = this.ConvertToTaupoProperty(edmProperty);
                taupoComplexType.Add(taupoProperty);
            }

            this.ConvertAnnotationsIntoTaupo(edmComplexType, taupoComplexType);
            return(taupoComplexType);
        }
        public void ConvertComplexType_Inheritance()
        {
            var taupoModel = new EntityModelSchema()
            {
                new ComplexType("NS1", "BaseComplex")
                {
                    new MemberProperty("p1", EdmDataTypes.Int16),
                },
                new ComplexType("NS2", "DerivedComplex")
                {
                    BaseType   = "BaseComplex",
                    Properties = { new MemberProperty("p2", EdmDataTypes.Int16) },
                },
            }
            .Resolve();

            IEdmModel result = this.converter.ConvertToEdmModel(taupoModel);

            Assert.IsNull(result.EntityContainer);
            Assert.AreEqual(2, result.SchemaElements.Count());
            Assert.AreEqual(2, result.SchemaElements.OfType <IEdmComplexType>().Count());

            IEdmComplexType baseComplex = result.SchemaElements.OfType <IEdmComplexType>().ElementAt(0);

            Assert.AreEqual("NS1.BaseComplex", baseComplex.FullName());
            Assert.AreEqual(1, baseComplex.DeclaredStructuralProperties().Count());
            Assert.AreEqual("p1", baseComplex.DeclaredStructuralProperties().First().Name);

            IEdmComplexType derivedComplex = result.SchemaElements.OfType <IEdmComplexType>().ElementAt(1);

            Assert.AreEqual("NS2.DerivedComplex", derivedComplex.FullName());
            Assert.AreEqual(1, derivedComplex.DeclaredStructuralProperties().Count());
            Assert.AreEqual("p2", derivedComplex.DeclaredStructuralProperties().First().Name);

            Assert.AreEqual(2, derivedComplex.StructuralProperties().Count());
            Assert.AreEqual(2, derivedComplex.Properties().Count());
            Assert.AreEqual(baseComplex, derivedComplex.BaseComplexType());
        }
        public void ConvertComplexType()
        {
            var taupoModel = new EntityModelSchema()
            {
                new ComplexType("NS1", "Complex1")
                {
                    new MemberProperty("p1", EdmDataTypes.Int32),
                    new MemberProperty("p2", EdmDataTypes.Int32.Nullable())
                    {
                        DefaultValue = 100,
                        Annotations  =
                        {
                            new ConcurrencyTokenAnnotation(),
                            new AttributeAnnotation()
                            {
                                Content = new XAttribute(this.annotationNamespace + "foo1", "bar1")
                            },
                        },
                    },
                    new AttributeAnnotation()
                    {
                        Content = new XAttribute(this.annotationNamespace + "foo2", "bar2")
                    },
                },
            };

            IEdmModel result = this.converter.ConvertToEdmModel(taupoModel);

            Assert.IsNull(result.EntityContainer);
            Assert.AreEqual(1, result.SchemaElements.Count());
            Assert.AreEqual(1, result.SchemaElements.OfType <IEdmComplexType>().Count());

            IEdmComplexType complex = result.SchemaElements.OfType <IEdmComplexType>().Single();

            Assert.AreEqual("NS1.Complex1", complex.FullName());
            Assert.IsNull(complex.BaseComplexType());
            Assert.AreEqual(2, complex.DeclaredStructuralProperties().Count());
            Assert.AreEqual(2, complex.StructuralProperties().Count());

            IEdmStructuralProperty property     = complex.DeclaredStructuralProperties().ElementAt(0);
            IEdmTypeReference      propertyType = property.Type;

            Assert.AreEqual("p1", property.Name);
            Assert.AreEqual("Edm.Int32", propertyType.FullName());
            Assert.AreEqual(EdmTypeKind.Primitive, propertyType.TypeKind());
            Assert.IsFalse(propertyType.IsNullable);

            Assert.AreEqual(complex, property.DeclaringType);
            Assert.AreEqual(EdmConcurrencyMode.None, property.ConcurrencyMode);
            Assert.IsNull(property.DefaultValueString);

            Assert.AreEqual(0, result.DirectValueAnnotations(property).Count());

            property     = complex.DeclaredStructuralProperties().ElementAt(1);
            propertyType = property.Type;

            Assert.AreEqual("p2", property.Name);
            Assert.AreEqual("Edm.Int32", propertyType.FullName());
            Assert.AreEqual(EdmTypeKind.Primitive, propertyType.TypeKind());
            Assert.IsTrue(propertyType.IsNullable);

            Assert.AreEqual(complex, property.DeclaringType);
            Assert.AreEqual(EdmConcurrencyMode.Fixed, property.ConcurrencyMode);
            Assert.AreEqual("100", property.DefaultValueString);

            Assert.AreEqual(1, result.DirectValueAnnotations(complex).Count());
            Assert.AreEqual("bogus", result.DirectValueAnnotations(complex).First().NamespaceUri);
            Assert.AreEqual("foo2", result.DirectValueAnnotations(complex).First().Name);
            Assert.AreEqual("bar2", (((IEdmDirectValueAnnotation)result.DirectValueAnnotations(complex).First()).Value as IEdmStringValue).Value);

            Assert.AreEqual(1, result.DirectValueAnnotations(property).Count());
            Assert.AreEqual("bogus", result.DirectValueAnnotations(property).First().NamespaceUri);
            Assert.AreEqual("foo1", result.DirectValueAnnotations(property).First().Name);
            Assert.AreEqual("bar1", (((IEdmDirectValueAnnotation)result.DirectValueAnnotations(property).First()).Value as IEdmStringValue).Value);
        }
        private ComplexType ConvertToTaupoComplexType(IEdmComplexType edmComplexType)
        {
            // Taupo TODO: Abstract for ComplexType
            var taupoComplexType = new ComplexType(edmComplexType.Namespace, edmComplexType.Name);

            if (edmComplexType.BaseType != null)
            {
                taupoComplexType.BaseType = new ComplexTypeReference(edmComplexType.BaseComplexType().Namespace, edmComplexType.BaseComplexType().Name);
            }

            foreach (var edmProperty in edmComplexType.DeclaredStructuralProperties())
            {
                var taupoProperty = this.ConvertToTaupoProperty(edmProperty);
                taupoComplexType.Add(taupoProperty);
            }

            this.ConvertAnnotationsIntoTaupo(edmComplexType, taupoComplexType);
            return taupoComplexType;
        }