private void FillStockContentsForComplex(IEdmComplexType edmType, IEdmModel edmModel, EdmModel stockModel)
        {
            var stockType = (EdmComplexType)stockModel.FindType(edmType.FullName());

            this.SetImmediateAnnotations(edmType, stockType, edmModel, stockModel);

            foreach (var edmProperty in edmType.DeclaredStructuralProperties())
            {
                ConvertToStockStructuralProperty((IEdmStructuralProperty)edmProperty, edmModel, stockModel);
            }
        }
        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_Nested()
        {
            var taupoModel = new EntityModelSchema()
            {
                new ComplexType("NS1", "Complex1")
                {
                    new MemberProperty("p1", DataTypes.ComplexType.WithName("NS2", "NestedComplex")),
                },
                new ComplexType("NS2", "NestedComplex")
                {
                    new MemberProperty("p1", 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 complex = result.SchemaElements.OfType <IEdmComplexType>().ElementAt(0);

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

            IEdmTypeReference propertyType = complex.DeclaredStructuralProperties().First().Type;

            Assert.AreEqual("NS2.NestedComplex", propertyType.FullName());
            Assert.AreEqual(EdmTypeKind.Complex, propertyType.TypeKind());

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

            Assert.AreEqual("NS2.NestedComplex", complex.FullName());
            Assert.AreEqual(1, complex.DeclaredStructuralProperties().Count());
            Assert.AreEqual("p1", complex.DeclaredStructuralProperties().First().Name);
        }
Exemplo n.º 4
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()");
        }
        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()
        {
            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;
        }
        private void FillStockContentsForComplex(IEdmComplexType edmType, IEdmModel edmModel, EdmModel stockModel)
        {
            var stockType = (EdmComplexType)stockModel.FindType(edmType.FullName());
            this.SetImmediateAnnotations(edmType, stockType, edmModel, stockModel);

            foreach (var edmProperty in edmType.DeclaredStructuralProperties())
            {
                ConvertToStockStructuralProperty((IEdmStructuralProperty)edmProperty, edmModel, stockModel);
            }
        }