Exemplo n.º 1
0
        /// <summary>
        /// Parses a single csdl/ssdl file.
        /// </summary>
        /// <param name="model">the entity model schema which the csdl/ssdl file parses to</param>
        /// <param name="schemaElement">the top level schema element in the csdl/ssdl file</param>
        protected virtual void ParseSingleXsdl(EntityModelSchema model, XElement schemaElement)
        {
            this.AssertXsdlElement(schemaElement, "Schema");

            this.SetupNamespaceAndAliases(schemaElement);

            foreach (var entityContainerElement in schemaElement.Elements().Where(el => this.IsXsdlElement(el, "EntityContainer")))
            {
                model.Add(this.ParseEntityContainer(entityContainerElement));
            }

            foreach (var entityTypeElement in schemaElement.Elements().Where(el => this.IsXsdlElement(el, "EntityType")))
            {
                model.Add(this.ParseEntityType(entityTypeElement));
            }

            foreach (var associationTypeElement in schemaElement.Elements().Where(el => this.IsXsdlElement(el, "Association")))
            {
                model.Add(this.ParseAssociation(associationTypeElement));
            }

            foreach (var functionElement in schemaElement.Elements().Where(el => this.IsXsdlElement(el, "Function")))
            {
                model.Add(this.ParseFunction(functionElement));
            }
        }
        /// <summary>
        /// Converts a model from Edm term into Taupo term
        /// </summary>
        /// <param name="edmModel">The input model in Edm term</param>
        /// <returns>The output model in Taupo term</returns>
        public EntityModelSchema ConvertToTaupoModel(IEdmModel edmModel)
        {
            this.edmModel            = edmModel;
            this.associationRegistry = new AssociationRegistry();

            var taupoModel = new EntityModelSchema();

            foreach (var edmComplexType in edmModel.SchemaElements.OfType <IEdmComplexType>())
            {
                ComplexType taupoComplexType = this.ConvertToTaupoComplexType(edmComplexType);
                taupoModel.Add(taupoComplexType);
            }

            foreach (var edmEntityType in edmModel.SchemaElements.OfType <IEdmEntityType>())
            {
                EntityType taupoEntityType = this.ConvertToTaupoEntityType(edmEntityType);
                taupoModel.Add(taupoEntityType);

                // convert to Association using information inside Navigations
                foreach (var edmNavigationProperty in edmEntityType.DeclaredNavigationProperties())
                {
                    if (!this.associationRegistry.IsAssociationRegistered(edmNavigationProperty))
                    {
                        this.associationRegistry.RegisterAssociation(edmNavigationProperty);
                    }
                }
            }

            var edmEntityContainer = edmModel.EntityContainer;

            if (edmEntityContainer != null)
            {
                EntityContainer taupoEntityContainer = this.ConvertToTaupoEntityContainer(edmEntityContainer);
                taupoModel.Add(taupoEntityContainer);
            }

            foreach (var edmFunction in edmModel.SchemaElements.OfType <IEdmOperation>())
            {
                Function taupoFunction = this.ConvertToTaupoFunction(edmFunction);
                taupoModel.Add(taupoFunction);
            }

            foreach (var edmEnum in edmModel.SchemaElements.OfType <IEdmEnumType>())
            {
                EnumType taupoEnumType = this.ConvertToTaupoEnumType(edmEnum);
                taupoModel.Add(taupoEnumType);
            }

            return(taupoModel.Resolve());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates an <see cref="AssociationType"/> between the <paramref name="from"/> and <paramref name="to"/>
        /// entity types. It uses computed names for the association and its ends.
        /// </summary>
        /// <param name="from">The entity type the association starts on.</param>
        /// <param name="to">The entity type the association goes to.</param>
        /// <param name="isSingletonRelationship">true if the navigation property is of singleton cardinality; false for a cardinality many. Default is false.</param>
        /// <returns>A new <see cref="AssociationType"/> between the <paramref name="from"/> and <paramref name="to"/> entity types.</returns>
        public static AssociationType AssociationType(this EntityModelSchema model, EntityType from, EntityType to, bool isSingletonRelationship)
        {
            ExceptionUtilities.CheckArgumentNotNull(model, "model");
            ExceptionUtilities.CheckArgumentNotNull(from, "from");
            ExceptionUtilities.CheckArgumentNotNull(to, "to");

            string associationTypeName = from.Name + "_" + to.Name;

            int index = 0;

            while (model.Associations.Where(a => a.Name == associationTypeName).Count() > 0)
            {
                index++;
                associationTypeName = from.Name + "_" + to.Name + index;
            }

            // create the association type
            AssociationType associationType = new AssociationType(associationTypeName)
            {
                new AssociationEnd("From" + from.Name, from, EndMultiplicity.ZeroOne),
                new AssociationEnd("To" + to.Name, to, isSingletonRelationship ? EndMultiplicity.One : EndMultiplicity.Many),
            };

            model.Add(associationType);
            return(associationType);
        }
Exemplo n.º 4
0
        private void AddIncrementIntegerPropertyActions(EntityModelSchema model, EntitySet entitySet, string propertyName)
        {
            var entityType = entitySet.EntityType;

            model.Add(
                new Function(entityType.NamespaceName, "ReturnBindingEntity" + entityType.Name)
            {
                ReturnType = DataTypes.EntityType.WithDefinition(entityType),
                Parameters =
                {
                    new FunctionParameter("bindingEntity", DataTypes.EntityType.WithDefinition(entityType)),
                },
                Annotations =
                {
                    new ServiceOperationAnnotation()
                    {
                        IsAction = true
                    },
                    new IncrementIntegerPropertyValueActionAnnotation()
                    {
                        IntegerProperty = propertyName
                    }
                }
            });
        }
Exemplo n.º 5
0
 /// <summary>
 /// Improve the model if goals not yet met
 /// </summary>
 /// <param name="model">model to improve</param>
 public override void Improve(EntityModelSchema model)
 {
     while (model.EntityTypes.Count() < this.MinNumberOfEntities)
     {
         model.Add(new EntityType());
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// Add default EntityContainer to the given EntitySchemaModel
        ///   For each base entity type, add an EntitySet
        ///   For each association, add an AssociationSet, between two possible EntitySets
        /// </summary>
        /// <param name="model">the given EntitySchemaModel</param>
        public void Fixup(EntityModelSchema model)
        {
            EntityContainer container = model.EntityContainers.FirstOrDefault();

            if (container == null)
            {
                container = new EntityContainer(this.DefaultContainerName);
                model.Add(container);
            }

            foreach (EntityType entity in model.EntityTypes.Where(e => e.BaseType == null && !container.EntitySets.Any(set => set.EntityType == e)))
            {
                if (!entity.Annotations.OfType <FixupNoSetAnnotation>().Any())
                {
                    container.Add(new EntitySet(entity.Name, entity));
                }
            }

            foreach (AssociationType association in model.Associations.Where(assoc => !container.AssociationSets.Any(assocSet => assocSet.AssociationType == assoc)))
            {
                if (!association.Annotations.OfType <FixupNoSetAnnotation>().Any())
                {
                    container.Add(new AssociationSet(association.Name, association)
                    {
                        Ends =
                        {
                            new AssociationSetEnd(association.Ends[0], container.EntitySets.First(es => association.Ends[0].EntityType.IsKindOf(es.EntityType))),
                            new AssociationSetEnd(association.Ends[1], container.EntitySets.First(es => association.Ends[1].EntityType.IsKindOf(es.EntityType))),
                        }
                    });
                }
            }
        }
        /// <summary>
        /// Improve the model if goals not yet met
        /// </summary>
        /// <param name="model">model to improve</param>
        public override void Improve(EntityModelSchema model)
        {
            var roots = this.GetInheritanceRoots(model);

            int numberOfRootsToAdd = this.MinNumberOfInheritanceRoots - roots.Count();

            for (int i = 0; i < numberOfRootsToAdd; i++)
            {
                var root = new EntityType();
                model.Add(root);
                model.Add(new EntityType()
                {
                    BaseType = root
                });
            }
        }
        private void AddWebInvokeServiceOperations(EntityModelSchema model)
        {
            model.Add(
                new Function("WebInvokeGetCustomer")
            {
                ReturnType  = DataTypes.CollectionType.WithElementDataType(DataTypes.EntityType.WithName("Customer")),
                Annotations =
                {
                    new LegacyServiceOperationAnnotation
                    {
                        Method = HttpVerb.Post,
                        ReturnTypeQualifier = ServiceOperationReturnTypeQualifier.IQueryable,
                    },
                    AddRootServiceOperationsFixup.BuildReturnEntitySetFunctionBody("Customer"),
                },
            });

            model.Add(
                new Function("WebInvokeGetOrder")
            {
                ReturnType  = DataTypes.CollectionType.WithElementDataType(DataTypes.EntityType.WithName("Order")),
                Annotations =
                {
                    new LegacyServiceOperationAnnotation
                    {
                        Method = HttpVerb.Post,
                        ReturnTypeQualifier = ServiceOperationReturnTypeQualifier.IQueryable,
                    },
                    AddRootServiceOperationsFixup.BuildReturnEntitySetFunctionBody("Order"),
                },
            });

            model.Add(
                new Function("WebInvokeGetOrderLine")
            {
                ReturnType  = DataTypes.CollectionType.WithElementDataType(DataTypes.EntityType.WithName("OrderLine")),
                Annotations =
                {
                    new LegacyServiceOperationAnnotation
                    {
                        Method = HttpVerb.Post,
                        ReturnTypeQualifier = ServiceOperationReturnTypeQualifier.IQueryable,
                    },
                    AddRootServiceOperationsFixup.BuildReturnEntitySetFunctionBody("OrderLine"),
                },
            });
        }
        /// <summary>
        /// Improve the model if goals not yet met
        /// </summary>
        /// <param name="model">model to improve</param>
        public override void Improve(EntityModelSchema model)
        {
            var baseType = new EntityType();

            model.Add(baseType);

            for (int i = 0; i < this.MinNumberOfInheritanceLevels; i++)
            {
                var derivedType = new EntityType()
                {
                    BaseType = baseType
                };
                model.Add(derivedType);

                baseType = derivedType;
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Parses a single csdl file.
        /// </summary>
        /// <param name="model">the entity model schema which the csdl file parses to</param>
        /// <param name="schemaElement">the top level schema element in the csdl file</param>
        protected override void ParseSingleXsdl(EntityModelSchema model, XElement schemaElement)
        {
            base.ParseSingleXsdl(model, schemaElement);

            foreach (var complexTypeElement in schemaElement.Elements().Where(el => this.IsXsdlElement(el, "ComplexType")))
            {
                model.Add(this.ParseComplexType(complexTypeElement));
            }

            foreach (var enumTypeElement in schemaElement.Elements().Where(el => this.IsXsdlElement(el, "EnumType")))
            {
                model.Add(this.ParseEnumType(enumTypeElement));
            }

            this.ProcessAllContainersWithExtends(
                model,
                schemaElement.Elements().Where(el => this.IsXsdlElement(el, "EntityContainer") && el.Attributes().Any(a => a.Name == "Extends")));
        }
Exemplo n.º 11
0
        /// <summary>
        /// Creates a new entity container with the specified name.
        /// </summary>
        /// <param name="model">The <see cref="EntityModelSchema"/> to create the entity container in.</param>
        /// <param name="containerName">The local name (without namespace) for the entity container to create.</param>
        /// <param name="namespaceName">The namespce name for the entity container to create.</param>
        /// <returns>The newly created entity container instance.</returns>
        public static EntityContainer EntityContainer(this EntityModelSchema model, string containerName, string namespaceName = null)
        {
            ExceptionUtilities.CheckArgumentNotNull(model, "model");
            ExceptionUtilities.CheckStringArgumentIsNotNullOrEmpty(containerName, "containerName");

            EntityContainer entityContainer = new EntityContainer(namespaceName ?? ModelNamespace, containerName);

            model.Add(entityContainer);
            return(entityContainer);
        }
Exemplo n.º 12
0
        protected EntityContainer AddContainer(EntityModelSchema schema, string namespaceName)
        {
            EntityContainer container = new EntityContainer("TestContainer");

            schema.Add(container);
            new ApplyDefaultNamespaceFixup(namespaceName).Fixup(schema);
            new ResolveReferencesFixup().Fixup(schema);
            this.PrimitiveTypeResolver.ResolveProviderTypes(schema, this.EdmDataTypeResolver);

            return(container);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Creates a new complex type with the specified name.
        /// </summary>
        /// <param name="model">The <see cref="EntityModelSchema"/> to create the complex type in.</param>
        /// <param name="localName">The local name (without namespace) for the complex type to create.</param>
        /// <param name="namespaceName">The (optional) namespace name for the type to create.</param>
        /// <returns>The newly created complex type instance.</returns>
        public static ComplexType ComplexType(this EntityModelSchema model, string localName, string namespaceName = null)
        {
            ExceptionUtilities.CheckArgumentNotNull(model, "model");

            namespaceName = namespaceName ?? ModelNamespace;
            ComplexType complexType = new ComplexType(namespaceName, localName)
            {
                Annotations = { new EntityModelSchemaAnnotation(model) }
            };

            model.Add(complexType);
            return(complexType);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Creates a new entity type with the specified name.
        /// </summary>
        /// <param name="model">The <see cref="EntityModelSchema"/> to create the entity type in.</param>
        /// <param name="localName">The local name (without namespace) for the entity type to create.</param>
        /// <param name="namespaceName">The (optional) namespace name for the type to create.</param>
        /// <returns>The newly created entity type instance.</returns>
        public static EntityType EntityType(this EntityModelSchema model, string localName, string namespaceName = null)
        {
            ExceptionUtilities.CheckArgumentNotNull(model, "model");
            ExceptionUtilities.CheckStringArgumentIsNotNullOrEmpty(localName, "localName");

            namespaceName = namespaceName ?? ModelNamespace;
            EntityType entityType = new EntityType(namespaceName, localName)
            {
                Annotations = { new EntityModelSchemaAnnotation(model) }
            };

            model.Add(entityType);
            return(entityType);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Improve the model if goals not yet met
        /// </summary>
        /// <param name="model">model to improve</param>
        public override void Improve(EntityModelSchema model)
        {
            var baseTypes = model.EntityTypes.Where(e => model.EntityTypes.Any(d => d.BaseType == e)).ToList();

            foreach (var baseType in baseTypes)
            {
                int numberOfSiblingsToAdd = this.MinNumberOfInheritanceSiblings - model.EntityTypes.Count(d => d.BaseType == baseType);

                for (int i = 0; i < numberOfSiblingsToAdd; i++)
                {
                    var derivedType = new EntityType()
                    {
                        BaseType = baseType
                    };
                    model.Add(derivedType);
                }
            }
        }
        /// <summary>
        /// Adds a Function for each base entity type, representing a service operation
        /// </summary>
        /// <param name="model">the entity model</param>
        public void Fixup(EntityModelSchema model)
        {
            foreach (var entityType in model.EntityTypes.Where(type => type.BaseType == null))
            {
                var entityName = entityType.Name;

                model.Add(
                    new Function("Get" + entityName)
                {
                    ReturnType  = DataTypes.CollectionType.WithElementDataType(DataTypes.EntityType.WithName(entityName)),
                    Annotations =
                    {
                        new LegacyServiceOperationAnnotation
                        {
                            Method = HttpVerb.Get,
                            ReturnTypeQualifier = ServiceOperationReturnTypeQualifier.IQueryable,
                        },
                        AddRootServiceOperationsFixup.BuildReturnEntitySetFunctionBody(entityName),
                    },
                });
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// This adds service operations that take arguments of type Spatial to the given model.
        /// </summary>
        /// <param name="model">The model to which the service operations will be added</param>
        /// <param name="runStability">The stability of the tests where this model is being used. Operations will only be added to unstable runs to prevent failures in BVTs</param>
        public static void AddServiceOperationsWithSpatialArguments(EntityModelSchema model, RunStability runStability)
        {
            // The run stability is a parameter to allow unit tests to call this, for code coverage
            if (runStability == RunStability.Unstable)
            {
                // TODO: Remove check for test stability when product supports Service Operations and Properties of Derived Types
                new AddRootServiceOperationsFixup().Fixup(model);

                // TODO: Remove check for test stability when product supports Service Operations with Spatial Arguments
                model.Add(CreateSimpleServiceOperation("Function00", EdmDataTypes.Geography.WithSrid(SpatialConstants.VariableSrid)));
                model.Add(CreateSimpleServiceOperation("Function01", EdmDataTypes.GeographyLineString.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.Geography.WithSrid(SpatialConstants.VariableSrid)));
                model.Add(CreateSimpleServiceOperation("Function02", EdmDataTypes.GeographyMultiLineString.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyLineString.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.Geography.WithSrid(SpatialConstants.VariableSrid)));
                model.Add(CreateSimpleServiceOperation("Function03", EdmDataTypes.GeographyMultiPoint.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyMultiLineString.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyLineString.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.Geography.WithSrid(SpatialConstants.VariableSrid)));
                model.Add(CreateSimpleServiceOperation("Function04", EdmDataTypes.GeographyMultiPolygon.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyMultiPoint.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyMultiLineString.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyLineString.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.Geography.WithSrid(SpatialConstants.VariableSrid)));
                model.Add(CreateSimpleServiceOperation("Function05", EdmDataTypes.GeographyPoint.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyMultiPolygon.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyMultiPoint.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyMultiLineString.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyLineString.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.Geography.WithSrid(SpatialConstants.VariableSrid)));
                model.Add(CreateSimpleServiceOperation("Function06", EdmDataTypes.GeographyPolygon.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyPoint.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyMultiPolygon.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyMultiPoint.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyMultiLineString.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyLineString.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.Geography.WithSrid(SpatialConstants.VariableSrid)));
                model.Add(CreateSimpleServiceOperation("Function07", EdmDataTypes.GeometryCollection.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyPolygon.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyPoint.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyMultiPolygon.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyMultiPoint.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyMultiLineString.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyLineString.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.Geography.WithSrid(SpatialConstants.VariableSrid)));
                model.Add(CreateSimpleServiceOperation("Function08", EdmDataTypes.GeometryLineString.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeometryCollection.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyPolygon.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyPoint.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyMultiPolygon.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyMultiPoint.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyMultiLineString.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyLineString.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.Geography.WithSrid(SpatialConstants.VariableSrid)));
                model.Add(CreateSimpleServiceOperation("Function09", EdmDataTypes.GeometryMultiLineString.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeometryLineString.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeometryCollection.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyPolygon.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyPoint.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyMultiPolygon.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyMultiPoint.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyMultiLineString.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyLineString.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.Geography.WithSrid(SpatialConstants.VariableSrid)));
                model.Add(CreateSimpleServiceOperation("Function10", EdmDataTypes.GeometryMultiPoint.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeometryMultiLineString.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeometryLineString.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeometryCollection.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyPolygon.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyPoint.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyMultiPolygon.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyMultiPoint.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyMultiLineString.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyLineString.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.Geography.WithSrid(SpatialConstants.VariableSrid)));
                model.Add(CreateSimpleServiceOperation("Function11", EdmDataTypes.GeometryMultiPolygon.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeometryMultiPoint.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeometryMultiLineString.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeometryLineString.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeometryCollection.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyPolygon.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyPoint.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyMultiPolygon.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyMultiPoint.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyMultiLineString.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyLineString.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.Geography.WithSrid(SpatialConstants.VariableSrid)));
                model.Add(CreateSimpleServiceOperation("Function12", EdmDataTypes.GeometryPoint.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeometryMultiPolygon.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeometryMultiPoint.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeometryMultiLineString.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeometryLineString.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeometryCollection.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyPolygon.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyPoint.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyMultiPolygon.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyMultiPoint.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyMultiLineString.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyLineString.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.Geography.WithSrid(SpatialConstants.VariableSrid)));
                model.Add(CreateSimpleServiceOperation("Function13", EdmDataTypes.GeometryPolygon.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeometryPoint.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeometryMultiPolygon.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeometryMultiPoint.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeometryMultiLineString.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeometryLineString.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeometryCollection.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyPolygon.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyPoint.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyMultiPolygon.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyMultiPoint.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyMultiLineString.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.GeographyLineString.WithSrid(SpatialConstants.VariableSrid), EdmDataTypes.Geography.WithSrid(SpatialConstants.VariableSrid)));
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// Adds and updates existing types in the default model to use Primitive and Complex Collections
        /// </summary>
        /// <param name="model">Model to add fixup to.</param>
        public void Fixup(EntityModelSchema model)
        {
            // Create entityType with all PrimitiveTypes lists
            EntityType allPrimitiveCollectionTypesEntity = new EntityType("AllPrimitiveCollectionTypesEntity");

            allPrimitiveCollectionTypesEntity.Add(new MemberProperty("Key", EdmDataTypes.Int32));
            allPrimitiveCollectionTypesEntity.Properties[0].IsPrimaryKey = true;
            for (int i = 0; i < primitiveTypes.Length; i++)
            {
                DataType t = DataTypes.CollectionType.WithElementDataType(primitiveTypes[i]);
                allPrimitiveCollectionTypesEntity.Add(new MemberProperty("Property" + i, t));
            }

            model.Add(allPrimitiveCollectionTypesEntity);

            // Create a complexType  with all PrimitiveTypes Bags and primitive properties in it
            ComplexType additionalComplexType = new ComplexType("AdditionalComplexType");

            additionalComplexType.Add(new MemberProperty("Bag1", DataTypes.CollectionType.WithElementDataType(EdmDataTypes.DateTime())));
            additionalComplexType.Add(new MemberProperty("Bag3", EdmDataTypes.String()));
            model.Add(additionalComplexType);

            // Create a complexType  with all PrimitiveTypes Bags in it
            ComplexType complexPrimitiveCollectionsType = new ComplexType("ComplexTypePrimitiveCollections");

            for (int i = 0; i < primitiveTypes.Length; i++)
            {
                DataType t = DataTypes.CollectionType.WithElementDataType(primitiveTypes[i]);
                complexPrimitiveCollectionsType.Add(new MemberProperty("Property" + i, t));
            }

            complexPrimitiveCollectionsType.Add(new MemberProperty("ComplexTypeBag", DataTypes.CollectionType.WithElementDataType(DataTypes.ComplexType.WithDefinition(additionalComplexType))));
            model.Add(complexPrimitiveCollectionsType);

            // Add the complexPrimitiveCollectionsType to an entity
            EntityType complexBagsEntity = new EntityType("ComplexBagsEntity");

            complexBagsEntity.Add(new MemberProperty("Key", EdmDataTypes.Int32));
            complexBagsEntity.Properties[0].IsPrimaryKey = true;
            DataType complexDataType = DataTypes.ComplexType.WithDefinition(complexPrimitiveCollectionsType);

            complexBagsEntity.Add(new MemberProperty("CollectionComplexTypePrimitiveCollections", DataTypes.CollectionType.WithElementDataType(complexDataType)));
            complexBagsEntity.Add(new MemberProperty("ComplexTypePrimitiveCollections", complexDataType));

            model.Add(complexBagsEntity);

            int numberOfComplexCollections = 0;

            // Update existing model so that every 3rd complexType is a Collection of ComplexTypes
            foreach (EntityType t in model.EntityTypes)
            {
                foreach (MemberProperty complexProperty in t.Properties.Where(p => p.PropertyType is ComplexDataType).ToList())
                {
                    // Remove existing one
                    t.Properties.Remove(complexProperty);

                    // Add new one
                    t.Properties.Add(new MemberProperty(complexProperty.Name + "Collection", DataTypes.CollectionType.WithElementDataType(complexProperty.PropertyType)));
                    numberOfComplexCollections++;

                    if (numberOfComplexCollections > 4)
                    {
                        break;
                    }
                }

                if (numberOfComplexCollections > 4)
                {
                    break;
                }
            }

            new ResolveReferencesFixup().Fixup(model);

            // ReApply the previously setup namespace on to the new types
            new ApplyDefaultNamespaceFixup(model.EntityTypes.First().NamespaceName).Fixup(model);
            new AddDefaultContainerFixup().Fixup(model);
            new SetDefaultCollectionTypesFixup().Fixup(model);
        }
Exemplo n.º 19
0
        private void AddEntityTypeDrivenToggleActions(EntityModelSchema schema, EntitySet entitySet)
        {
            int functionCount = 0;

            var entityType = entitySet.EntityType;

            // Create a bunch of functions based on the entityType provided
            var toggleProperty = this.Random.ChooseFrom(entityType.AllProperties.Where(p => typeof(BooleanDataType).IsAssignableFrom(p.PropertyType.GetType())));

            var properties = entityType.Properties.Where(p => !p.IsStream()).AsEnumerable();

            var navigationProperties = entityType.NavigationProperties;

            var bindingTypes = new DataType[] { DataTypes.EntityType.WithDefinition(entityType), DataTypes.CollectionOfEntities(entityType) };

            // Create a function where this type is returned and a input parameter
            foreach (var memberProperty in properties)
            {
                if (memberProperty == toggleProperty)
                {
                    continue;
                }

                // Skip if we have used a datatype already
                if (this.useDataTypes.ContainsKey(memberProperty.PropertyType))
                {
                    continue;
                }
                else
                {
                    this.useDataTypes.Add(memberProperty.PropertyType, true);
                }

                foreach (var bindingDataType in bindingTypes)
                {
                    string funcNameString = bindingDataType is CollectionDataType ? "_FuncCollectionBound_" : "_Func_";
                    var    function       = new Function(entityType.NamespaceName, entityType.Name + "_" + memberProperty.Name + funcNameString + functionCount)
                    {
                        ReturnType = memberProperty.PropertyType,
                        Parameters =
                        {
                            new FunctionParameter(entityType.Name,     bindingDataType),
                            new FunctionParameter(memberProperty.Name, memberProperty.PropertyType)
                        },
                        Annotations =
                        {
                            new ServiceOperationAnnotation()
                            {
                                IsAction = true, BindingKind = OperationParameterBindingKind.Sometimes
                            },
                            new ActionWithSingleParameterReturnedAnnotation(),
                        }
                    };

                    schema.Add(function);
                    functionCount++;

                    var noReturnFunction = new Function(entityType.NamespaceName, entityType.Name + "_" + memberProperty.Name + funcNameString + functionCount)
                    {
                        Parameters =
                        {
                            new FunctionParameter(entityType.Name,     bindingDataType),
                            new FunctionParameter(memberProperty.Name, memberProperty.PropertyType)
                        },
                        Annotations =
                        {
                            new ServiceOperationAnnotation()
                            {
                                IsAction = true
                            },
                            new ToggleBoolPropertyValueActionAnnotation()
                            {
                                ToggleProperty = toggleProperty.Name,
                            }
                        }
                    };

                    schema.Add(noReturnFunction);
                    functionCount++;

                    var noParameterFunction = new Function(entityType.NamespaceName, entityType.Name + "_" + memberProperty.Name + funcNameString + functionCount)
                    {
                        ReturnType = memberProperty.PropertyType,
                        Parameters =
                        {
                            new FunctionParameter(entityType.Name, bindingDataType),
                        },
                        Annotations =
                        {
                            new ServiceOperationAnnotation()
                            {
                                IsAction = true
                            },
                            new ToggleBoolPropertyValueActionAnnotation()
                            {
                                ToggleProperty = toggleProperty.Name,
                                ReturnProperty = memberProperty.Name,
                            }
                        }
                    };

                    schema.Add(noParameterFunction);
                    functionCount++;
                }
            }

            // Create a function where this type is returned and a input parameter
            foreach (var navigationProperty in navigationProperties)
            {
                var      navigationEntityType = navigationProperty.ToAssociationEnd.EntityType;
                DataType returnType           = DataTypes.EntityType.WithDefinition(navigationEntityType);
                if (navigationProperty.ToAssociationEnd.Multiplicity == EndMultiplicity.Many)
                {
                    returnType = DataTypes.CollectionType.WithElementDataType(returnType);
                }

                // Skip if we have used a datatype already
                if (this.useDataTypes.ContainsKey(returnType))
                {
                    continue;
                }
                else
                {
                    this.useDataTypes.Add(returnType, true);
                }

                foreach (var bindingDataType in bindingTypes)
                {
                    string funcNameString     = bindingDataType is CollectionDataType ? "_FuncCollectionBound_" : "_Func_";
                    var    navigationFunction = new Function(entityType.NamespaceName, entityType.Name + "_" + navigationProperty.Name + funcNameString + functionCount)
                    {
                        ReturnType = returnType,
                        Parameters =
                        {
                            new FunctionParameter(entityType.Name, bindingDataType),
                        },
                        Annotations =
                        {
                            new ServiceOperationAnnotation()
                            {
                                IsAction = true
                            },
                            new ToggleBoolPropertyValueActionAnnotation()
                            {
                                ToggleProperty = toggleProperty.Name,
                                ReturnProperty = navigationProperty.Name,
                            }
                        }
                    };

                    schema.Add(navigationFunction);
                    functionCount++;

                    var noReturnNavigationFunction = new Function(entityType.NamespaceName, entityType.Name + "_" + navigationProperty.Name + funcNameString + functionCount)
                    {
                        Parameters =
                        {
                            new FunctionParameter(entityType.Name, bindingDataType),
                        },
                        Annotations =
                        {
                            new ServiceOperationAnnotation()
                            {
                                IsAction = true
                            },
                            new ToggleBoolPropertyValueActionAnnotation()
                            {
                                ToggleProperty = toggleProperty.Name,
                            }
                        }
                    };

                    schema.Add(noReturnNavigationFunction);
                    functionCount++;
                }
            }
        }
Exemplo n.º 20
0
        public EntityModelSchema GenerateModel()
        {
            this.useDataTypes = new Dictionary <DataType, bool>();

            var model = new EntityModelSchema()
            {
                new EntityType("Movie")
                {
                    Annotations =
                    {
                        new HasStreamAnnotation(),
                    },
                    Properties =
                    {
                        new MemberProperty("Id",               EdmDataTypes.Int32)
                        {
                            IsPrimaryKey = true
                        },
                        new MemberProperty("Name",             EdmDataTypes.String()),
                        new MemberProperty("LengthInMinutes",  EdmDataTypes.Int32)
                        {
                            Annotations = { new ConcurrencyTokenAnnotation() }
                        },
                        new MemberProperty("ReleaseYear",      EdmDataTypes.DateTime()),
                        new MemberProperty("Trailer",          EdmDataTypes.Stream),
                        new MemberProperty("FullMovie",        EdmDataTypes.Stream),
                        new MemberProperty("IsAwardWinner",    EdmDataTypes.Boolean),
                        new MemberProperty("AddToQueueValue",  EdmDataTypes.Boolean),
                        new MemberProperty("AddToQueueValue2", EdmDataTypes.Boolean),
                        new MemberProperty("MovieHomePage",    EdmDataTypes.String()).WithDataGenerationHints(DataGenerationHints.NoNulls,DataGenerationHints.AnsiString,  DataGenerationHints.MinLength(10)),
                        new MemberProperty("Description",      EdmDataTypes.String()).WithDataGenerationHints(DataGenerationHints.NoNulls,DataGenerationHints.AnsiString,  DataGenerationHints.MinLength(10)),
                    },

                    NavigationProperties =
                    {
                        new NavigationProperty("MovieRatings", "MovieRating_Movie", "Movie",  "MovieRating"),
                        new NavigationProperty("Actors",       "Movies_Actors",     "Movies", "Actors"),
                    }
                },
                new ComplexType("Phone")
                {
                    new MemberProperty("PhoneNumber", EdmDataTypes.String()),
                    new MemberProperty("Extension", EdmDataTypes.String().Nullable(true)),
                },
                new ComplexType("ContactDetails")
                {
                    new MemberProperty("PhoneMultiValue", DataTypes.CollectionOfComplex("Phone")),
                },
                new ComplexType("Rating")
                {
                    new MemberProperty("Comments", EdmDataTypes.String()),
                    new MemberProperty("FiveStarRating", EdmDataTypes.Byte),
                    new MemberProperty("Tags", DataTypes.CollectionType.WithElementDataType(DataTypes.String)),
                },
                new ComplexType("AllSpatialTypesComplex")
                {
                    new MemberProperty("Geog", EdmDataTypes.Geography.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeogPoint", EdmDataTypes.GeographyPoint.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeogLine", EdmDataTypes.GeographyLineString.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeogPolygon", EdmDataTypes.GeographyPolygon.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeogCollection", EdmDataTypes.GeographyCollection.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeogMultiPoint", EdmDataTypes.GeographyMultiPoint.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeogMultiLine", EdmDataTypes.GeographyMultiLineString.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeogMultiPolygon", EdmDataTypes.GeographyMultiPolygon.WithSrid(SpatialConstants.VariableSrid)),

                    new MemberProperty("Geom", EdmDataTypes.Geometry.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeomPoint", EdmDataTypes.GeometryPoint.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeomLine", EdmDataTypes.GeometryLineString.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeomPolygon", EdmDataTypes.GeometryPolygon.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeomCollection", EdmDataTypes.GeometryCollection.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeomMultiPoint", EdmDataTypes.GeometryMultiPoint.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeomMultiLine", EdmDataTypes.GeometryMultiLineString.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeomMultiPolygon", EdmDataTypes.GeometryMultiPolygon.WithSrid(SpatialConstants.VariableSrid)),
                },
                new EntityType("MovieRating")
                {
                    new MemberProperty("Id", EdmDataTypes.Int32)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Rating", DataTypes.ComplexType.WithDefinition("Rating")),
                    new MemberProperty("IsCreatedByCustomer", EdmDataTypes.Boolean),
                    new NavigationProperty("Movie", "MovieRating_Movie", "MovieRating", "Movie"),
                },
                new EntityType("Actor")
                {
                    new MemberProperty("Id", EdmDataTypes.Int32)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("FirstName", EdmDataTypes.String()),
                    new MemberProperty("LastName", EdmDataTypes.String()),
                    new MemberProperty("Age", EdmDataTypes.Int32),
                    new MemberProperty("IsAwardWinner", EdmDataTypes.Boolean),
                    new MemberProperty("ContactDetails", DataTypes.ComplexType.WithName("ContactDetails")),
                    new MemberProperty("PrimaryPhoneNumber", DataTypes.ComplexType.WithName("Phone")),
                    new MemberProperty("AdditionalPhoneNumbers", DataTypes.CollectionOfComplex("Phone")),
                    new MemberProperty("AlternativeNames", DataTypes.CollectionType.WithElementDataType(DataTypes.String)),
                    new NavigationProperty("Movies", "Movies_Actors", "Actors", "Movies"),
                },
                new EntityType("Producer")
                {
                    new MemberProperty("Id", EdmDataTypes.Int32)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("FirstName", EdmDataTypes.String()),
                    new MemberProperty("LastName", EdmDataTypes.String()),
                    new MemberProperty("Toggle", EdmDataTypes.Boolean),
                },
                new EntityType("ExecutiveProducer")
                {
                    BaseType = "Producer"
                },
                new EntityType("ActorMovieRating")
                {
                    new MemberProperty("Id", EdmDataTypes.Int32)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("IsStar", EdmDataTypes.Boolean),
                    new MemberProperty("Rating", DataTypes.ComplexType.WithDefinition("Rating")),
                    new NavigationProperty("Actor", "ActorMovieRating_Actor", "ActorMovieRating", "Actor"),
                    new NavigationProperty("Movie", "ActorMovieRating_Movie", "ActorMovieRating", "Movie"),
                },
                new EntityType("AllTypes")
                {
                    // This EntityType contains only primitive properties
                    new MemberProperty("Id", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("ToggleProperty", EdmDataTypes.Boolean),
                    new MemberProperty("BooleanProperty", EdmDataTypes.Boolean),
                    new MemberProperty("StringProperty", EdmDataTypes.String()).WithDataGenerationHints(DataGenerationHints.NoNulls),
                    new MemberProperty("ByteProperty", EdmDataTypes.Byte),
                    new MemberProperty("DateTimeProperty", EdmDataTypes.DateTime()),
                    new MemberProperty("DecimalProperty", EdmDataTypes.Decimal()),
                    new MemberProperty("DoubleProperty", EdmDataTypes.Double),
                    new MemberProperty("GuidProperty", EdmDataTypes.Guid),
                    new MemberProperty("Int16Property", EdmDataTypes.Int16),
                    new MemberProperty("Int32Property", EdmDataTypes.Int32),
                    new MemberProperty("Int64Property", EdmDataTypes.Int64),
                    new MemberProperty("SingleProperty", EdmDataTypes.Single),
                    new MemberProperty("BinaryProperty", EdmDataTypes.Binary()),
                    new MemberProperty("DateTimeOffsetProperty", EdmDataTypes.DateTimeOffset().NotNullable()),
                    new MemberProperty("TimeSpanProperty", EdmDataTypes.Time().NotNullable()),
                    new MemberProperty("NullableDateTimeOffsetProperty", EdmDataTypes.DateTimeOffset().Nullable()),
                    new MemberProperty("NullableTimeSpanProperty", EdmDataTypes.Time().Nullable()),

                    new MemberProperty("ByteCollectionProperty", DataTypes.CollectionType.WithElementDataType(EdmDataTypes.Byte)).WithDataGenerationHints(DataGenerationHints.NoNulls, DataGenerationHints.MaxCount(0)),
                    new MemberProperty("DoubleCollectionProperty", DataTypes.CollectionType.WithElementDataType(EdmDataTypes.Double)).WithDataGenerationHints(DataGenerationHints.NoNulls),
                    new MemberProperty("Int32CollectionProperty", DataTypes.CollectionType.WithElementDataType(EdmDataTypes.Int32)).WithDataGenerationHints(DataGenerationHints.NoNulls),
                    new MemberProperty("StringCollectionProperty", DataTypes.CollectionType.WithElementDataType(EdmDataTypes.String())).WithDataGenerationHints(DataGenerationHints.NoNulls),
                    new MemberProperty("DateTimeOffsetCollectionProperty", DataTypes.CollectionType.WithElementDataType(EdmDataTypes.DateTimeOffset())).WithDataGenerationHints(DataGenerationHints.NoNulls),
                    new MemberProperty("TimeSpanCollectionProperty", DataTypes.CollectionType.WithElementDataType(EdmDataTypes.Time())).WithDataGenerationHints(DataGenerationHints.NoNulls),

                    //// TODO: add the following
                    ////new MemberProperty("NullStringProperty", DataTypes.String).WithDataGenerationHints(DataGenerationHints.AllNulls),
                    ////new MemberProperty("NullBinaryProperty", DataTypes.Binary.WithMaxLength(500)).WithDataGenerationHints(DataGenerationHints.AllNulls),
                },
                new EntityType("AllSpatialTypes")
                {
                    new MemberProperty("Id", EdmDataTypes.Int32)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("ToggleProperty", EdmDataTypes.Boolean),
                    new MemberProperty("Int32Property", EdmDataTypes.Int32),

                    new MemberProperty("Geog", EdmDataTypes.Geography.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeogPoint", EdmDataTypes.GeographyPoint.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeogLine", EdmDataTypes.GeographyLineString.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeogPolygon", EdmDataTypes.GeographyPolygon.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeogCollection", EdmDataTypes.GeographyCollection.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeogMultiPoint", EdmDataTypes.GeographyMultiPoint.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeogMultiLine", EdmDataTypes.GeographyMultiLineString.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeogMultiPolygon", EdmDataTypes.GeographyMultiPolygon.WithSrid(SpatialConstants.VariableSrid)),

                    new MemberProperty("Geom", EdmDataTypes.Geometry.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeomPoint", EdmDataTypes.GeometryPoint.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeomLine", EdmDataTypes.GeometryLineString.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeomPolygon", EdmDataTypes.GeometryPolygon.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeomCollection", EdmDataTypes.GeometryCollection.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeomMultiPoint", EdmDataTypes.GeometryMultiPoint.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeomMultiLine", EdmDataTypes.GeometryMultiLineString.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeomMultiPolygon", EdmDataTypes.GeometryMultiPolygon.WithSrid(SpatialConstants.VariableSrid)),

                    new MemberProperty("Complex", DataTypes.ComplexType.WithName("AllSpatialTypesComplex")),
                },
                new EntityType("DVDCustomer")
                {
                    new MemberProperty("Id", EdmDataTypes.Int32)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Name", EdmDataTypes.String()),
                    new MemberProperty("EMail", EdmDataTypes.String()),
                    new MemberProperty("Visa", EdmDataTypes.Int32),
                    new MemberProperty("BalancePaid", EdmDataTypes.Boolean),
                    new NavigationProperty("DVDShipActivities", "DVDCustomer_DVDShipActivities", "DVDCustomer", "DVDShipActivity"),
                },
                new EntityType("DVDShipActivity")
                {
                    new MemberProperty("Id", EdmDataTypes.Int32)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("OrderDescription", EdmDataTypes.String()),
                    new MemberProperty("Title", EdmDataTypes.String()),
                    new MemberProperty("ShipTime", EdmDataTypes.DateTime()),
                    new MemberProperty("ReturnTime", EdmDataTypes.DateTime()),
                    new MemberProperty("ProblemReport", EdmDataTypes.String()),
                    new NavigationProperty("DVDCustomer", "DVDCustomer_DVDShipActivities", "DVDShipActivity", "DVDCustomer"),
                },
                new AssociationType("DVDCustomer_DVDShipActivities")
                {
                    new AssociationEnd("DVDCustomer", "DVDCustomer", EndMultiplicity.One),
                    new AssociationEnd("DVDShipActivity", "DVDShipActivity", EndMultiplicity.Many),
                },
                new AssociationType("Movies_Actors")
                {
                    new AssociationEnd("Movies", "Movie", EndMultiplicity.Many),
                    new AssociationEnd("Actors", "Actor", EndMultiplicity.Many),
                },
                new AssociationType("ActorMovieRating_Movie")
                {
                    new AssociationEnd("Movie", "Movie", EndMultiplicity.ZeroOne),
                    new AssociationEnd("ActorMovieRating", "ActorMovieRating", EndMultiplicity.Many),
                },
                new AssociationType("ActorMovieRating_Actor")
                {
                    new AssociationEnd("Actor", "Actor", EndMultiplicity.ZeroOne),
                    new AssociationEnd("ActorMovieRating", "ActorMovieRating", EndMultiplicity.Many),
                },
                new AssociationType("MovieRating_Movie")
                {
                    new AssociationEnd("MovieRating", "MovieRating", EndMultiplicity.Many),
                    new AssociationEnd("Movie", "Movie", EndMultiplicity.ZeroOne),
                },
                new Function("CheckoutFirstMovie")
                {
                    new ToggleBoolPropertyValueActionAnnotation()
                    {
                        SourceEntitySet = "Movie", ToggleProperty = "IsAwardWinner"
                    },
                    new ServiceOperationAnnotation()
                    {
                        BindingKind = OperationParameterBindingKind.Never, IsAction = true
                    }
                },
                new Function("PayCustomerBalance")
                {
                    Annotations =
                    {
                        new ToggleBoolPropertyValueActionAnnotation()
                        {
                            ToggleProperty = "BalancePaid", ReturnProperty = "DVDShipActivities"
                        },
                        new ServiceOperationAnnotation()
                        {
                            IsAction      = true,
                            EntitySetPath = "customer/DVDShipActivities",
                        }
                    },

                    Parameters =
                    {
                        new FunctionParameter("customer", DataTypes.EntityType.WithDefinition("DVDCustomer")),
                    },

                    ReturnType = DataTypes.CollectionOfEntities("DVDShipActivity"),
                },
                new Function("AddToQueue")
                {
                    Annotations =
                    {
                        new ToggleBoolPropertyValueActionAnnotation()
                        {
                            ToggleProperty = "AddToQueueValue", ReturnProperty = "Id"
                        },
                        new ServiceOperationAnnotation()
                        {
                            IsAction = true,
                        }
                    },

                    Parameters =
                    {
                        new FunctionParameter("movie", DataTypes.EntityType.WithDefinition("Movie")),
                    },

                    ReturnType = EdmDataTypes.Int32
                },
                new Function("UpVoteExecutiveProducer")
                {
                    Annotations =
                    {
                        new ToggleBoolPropertyValueActionAnnotation()
                        {
                            ToggleProperty = "Toggle", ReturnProperty = "FirstName"
                        },
                        new ServiceOperationAnnotation()
                        {
                            IsAction    = true,
                            BindingKind = OperationParameterBindingKind.Sometimes
                        }
                    },

                    Parameters =
                    {
                        new FunctionParameter("executiveProducer", DataTypes.EntityType.WithDefinition("ExecutiveProducer")),
                    },

                    ReturnType = EdmDataTypes.String()
                },
                new Function("UpVoteProducer")
                {
                    Annotations =
                    {
                        new ToggleBoolPropertyValueActionAnnotation()
                        {
                            ToggleProperty = "Toggle", ReturnProperty = "FirstName"
                        },
                        new ServiceOperationAnnotation()
                        {
                            IsAction    = true,
                            BindingKind = OperationParameterBindingKind.Sometimes
                        }
                    },

                    Parameters =
                    {
                        new FunctionParameter("producer", DataTypes.EntityType.WithDefinition("Producer")),
                    },

                    ReturnType = EdmDataTypes.String()
                },
                new Function("AddToQueue2")
                {
                    Annotations =
                    {
                        new ToggleBoolPropertyValueActionAnnotation()
                        {
                            ToggleProperty = "AddToQueueValue2", ReturnProperty = "Id"
                        },
                        new ServiceOperationAnnotation()
                        {
                            IsAction    = true,
                            BindingKind = OperationParameterBindingKind.Sometimes
                        }
                    },

                    Parameters =
                    {
                        new FunctionParameter("movie", DataTypes.EntityType.WithDefinition("Movie")),
                    },

                    ReturnType = EdmDataTypes.Int32
                },
                new Function("AddToQueueThrowError")
                {
                    Annotations =
                    {
                        new ThrowDataServiceExceptionAnnotation()
                        {
                            ErrorStatusCode = 500, ErrorMessage = "Throwing error in AddToQueueThrowError function"
                        },
                        new ToggleBoolPropertyValueActionAnnotation()
                        {
                            ToggleProperty = "AddToQueueValue", ReturnProperty = "Id"
                        },
                        new ServiceOperationAnnotation()
                        {
                            IsAction = true,
                        }
                    },

                    Parameters =
                    {
                        new FunctionParameter("movie", DataTypes.EntityType.WithDefinition("Movie")),
                    },

                    ReturnType = EdmDataTypes.Int32
                },

                new Function("MultiParameterFunction")
                {
                    Annotations =
                    {
                        new ToggleBoolPropertyValueActionAnnotation()
                        {
                            ToggleProperty = "AddToQueueValue", ReturnProperty = "Id"
                        },
                        new ServiceOperationAnnotation()
                        {
                            IsAction = true,
                        }
                    },

                    Parameters =
                    {
                        new FunctionParameter("movie",    DataTypes.EntityType.WithDefinition("Movie")),
                        new FunctionParameter("author",   EdmDataTypes.String()),
                        new FunctionParameter("comments", DataTypes.CollectionType.WithElementDataType(EdmDataTypes.String())),
                    },

                    ReturnType = EdmDataTypes.Int32
                },
                //// Declaring an action in the Actor Entity that will have a name collision with the 'Age' property
                new Function("Age")
                {
                    Annotations =
                    {
                        new ToggleBoolPropertyValueActionAnnotation()
                        {
                            ToggleProperty = "IsAwardWinner", ReturnProperty = "FirstName"
                        },
                        new ServiceOperationAnnotation()
                        {
                            IsAction = true,
                        }
                    },

                    Parameters =
                    {
                        new FunctionParameter("actor", DataTypes.EntityType.WithDefinition("Actor")),
                    },

                    ReturnType = EdmDataTypes.String()
                }
            };

            this.AddServiceOperationsToModel(model);

            new ResolveReferencesFixup().Fixup(model);
            new ApplyDefaultNamespaceFixup("NetflixActions").Fixup(model);
            new AddDefaultContainerFixup().Fixup(model);

            // add MEST scenarios in the model
            if (this.DataProviderSettings.SupportsMest)
            {
                EntityContainer ec = model.EntityContainers.Single();
                EntityType      customerEntityType            = ec.EntitySets.Single(es => es.Name == "DVDCustomer").EntityType;
                EntitySet       instantWatchCustomerEntitySet = new EntitySet("InstantWatchCustomer", customerEntityType);
                ec.Add(instantWatchCustomerEntitySet);

                EntityType activityEntityType            = ec.EntitySets.Single(es => es.Name == "DVDShipActivity").EntityType;
                EntitySet  instantWatchActivityEntitySet = new EntitySet("InstantWatchActivity", activityEntityType);
                ec.Add(instantWatchActivityEntitySet);

                AssociationType at = model.Associations.Single(a => a.Name == "DVDCustomer_DVDShipActivities");
                ec.Add(new AssociationSet("InstantWatchCustomer_InstantWatchActivities", at)
                {
                    Ends =
                    {
                        new AssociationSetEnd(at.Ends[0], instantWatchCustomerEntitySet),
                        new AssociationSetEnd(at.Ends[1], instantWatchActivityEntitySet),
                    }
                });
            }

            // Only add these actions if its not using the model for call order tests
            if (!this.AdaptModelForCallOrderTests)
            {
                this.AddEntityTypeDrivenToggleActions(model, model.EntityContainers.First().EntitySets.Single(es => es.Name == "ActorMovieRating"));
                this.AddEntityTypeDrivenToggleActions(model, model.EntityContainers.First().EntitySets.Single(es => es.Name == "Movie"));
                this.AddEntityTypeDrivenToggleActions(model, model.EntityContainers.First().EntitySets.Single(es => es.Name == "Actor"));
                this.AddEntityTypeDrivenToggleActions(model, model.EntityContainers.First().EntitySets.Single(es => es.Name == "AllTypes"));

                if (this.DataProviderSettings.SupportsSpatial)
                {
                    this.AddEntityTypeDrivenToggleActions(model, model.EntityContainers.First().EntitySets.Single(es => es.Name == "AllSpatialTypes"));
                }

                this.AddIncrementIntegerPropertyActions(model, model.EntityContainers.First().EntitySets.Single(es => es.Name == "AllTypes"), "Int32Property");

                if (this.DataProviderSettings.SupportsSpatial)
                {
                    this.AddIncrementIntegerPropertyActions(model, model.EntityContainers.First().EntitySets.Single(es => es.Name == "AllSpatialTypes"), "Int32Property");
                }

                this.AddIncrementIntegerPropertyActions(model, model.EntityContainers.First().EntitySets.Single(es => es.Name == "Actor"), "Age");
                this.AddIncrementIntegerPropertyActions(model, model.EntityContainers.First().EntitySets.Single(es => es.Name == "Movie"), "LengthInMinutes");
            }

            // Add page size = 1 for all exposed entity sets in the model
            var movieEntitySet = model.EntityContainers.First().EntitySets.Single(es => es.Name == "Movie");

            movieEntitySet.Annotations.Add(new PageSizeAnnotation()
            {
                PageSize = 1
            });

            this.SetupBindingParameterCollectionTypeAnnotation(model);

            if (this.RemoveHigherVersionModelFeaturesExceptActionWithMultiValue)
            {
                new AddDefaultContainerFixup().Fixup(model);
                new SetDefaultDataServiceConfigurationBehaviors()
                {
                    MaxProtocolVersion = DataServiceProtocolVersion.V4
                }.Fixup(model);

                var functionsToSave = model.Functions.Where(f => f.IsAction() && f.ReturnType != null && f.Parameters.Count > 0);
                var functionToSave  = functionsToSave.Where(f => f.Parameters.Any(p => p.DataType is CollectionDataType && !(((CollectionDataType)p.DataType).ElementDataType is EntityDataType))).ToArray().FirstOrDefault();
                new RemoveHigherVersionFeaturesFixup(DataServiceProtocolVersion.V4).Fixup(model);

                model.Add(functionToSave);
            }

            // Remove streams from the model if this is being used for call order tests
            if (this.AdaptModelForCallOrderTests)
            {
                new RemoveNamedStreamsFixup().Fixup(model);
                model.EntityTypes.ForEach(et => et.Annotations.RemoveAll(a => a.GetType() == typeof(HasStreamAnnotation)));

                // Add Query Interceptors for all sets so they will be triggered when running via call order
                model.EntityContainers.Single().EntitySets.ForEach(es => es.Annotations.Add(new ConstantInterceptorAnnotation()
                {
                    FilterConstant = true
                }));
            }

            return(model);
        }
Exemplo n.º 21
0
        private void PushPropertiesToDerivedType(EntityModelSchema model, GenericTypeLookupGraph graph, EntityType unmappedBaseType, List <AssociationSet> oldAssociationSetsToRemove, EntityType derivedType, Dictionary <EntitySet, EntitySet> oldNewMap)
        {
            // Push primitive properties into derived classes.
            foreach (var property in unmappedBaseType.AllProperties)
            {
                var newProperty = this.ResolveProperty(graph, property, derivedType);
                derivedType.Properties.Add(newProperty);
            }

            // Push navigation properties into derived classes and add a new AssociationType.
            foreach (var navigationProperty in unmappedBaseType.AllNavigationProperties)
            {
                var oldAssociationType = navigationProperty.Association;
                var oldThisEnd         = navigationProperty.FromAssociationEnd;
                var oldOtherEnd        = navigationProperty.ToAssociationEnd;

                var associationTypeEndLookup = new Dictionary <AssociationEnd, AssociationEnd>();
                var thisEnd  = associationTypeEndLookup[oldThisEnd] = new AssociationEnd(derivedType.Name, derivedType, oldThisEnd.Multiplicity, oldThisEnd.DeleteBehavior);
                var otherEnd = associationTypeEndLookup[oldOtherEnd] = new AssociationEnd(oldOtherEnd.RoleName, oldOtherEnd.EntityType, oldOtherEnd.Multiplicity, oldOtherEnd.DeleteBehavior);

                // Assumes combination of the derived type name and the old association type name is unique.
                var associationType = new AssociationType(oldAssociationType.NamespaceName, derivedType.Name + "_" + oldAssociationType.Name)
                {
                    associationTypeEndLookup[oldThisEnd],
                    associationTypeEndLookup[oldOtherEnd]
                };

                if (oldAssociationType.ReferentialConstraint != null)
                {
                    associationType.ReferentialConstraint = new ReferentialConstraint()
                                                            .WithDependentProperties(associationTypeEndLookup[oldAssociationType.ReferentialConstraint.DependentAssociationEnd], oldAssociationType.ReferentialConstraint.DependentProperties.ToArray())
                                                            .ReferencesPrincipalProperties(associationTypeEndLookup[oldAssociationType.ReferentialConstraint.PrincipalAssociationEnd], oldAssociationType.ReferentialConstraint.PrincipalProperties.ToArray());
                }

                var newNavigationProperty = new NavigationProperty(navigationProperty.Name, associationType, thisEnd, otherEnd);
                derivedType.NavigationProperties.Add(newNavigationProperty);

                model.Add(associationType);

                // Update the association sets for this association type.
                var oldAssociationSets = model.EntityContainers.SelectMany(e => e.AssociationSets).Where(a => a.AssociationType == oldAssociationType).ToArray();
                foreach (var oldAssociationSet in oldAssociationSets)
                {
                    EntitySet firstEntitySet;
                    if (!oldNewMap.TryGetValue(oldAssociationSet.Ends[0].EntitySet, out firstEntitySet))
                    {
                        firstEntitySet = oldAssociationSet.Ends[0].EntitySet;
                    }

                    EntitySet secondEntitySet;
                    if (!oldNewMap.TryGetValue(oldAssociationSet.Ends[1].EntitySet, out secondEntitySet))
                    {
                        secondEntitySet = oldAssociationSet.Ends[1].EntitySet;
                    }

                    var associationSet = new AssociationSet(associationType.Name + "_" + oldAssociationSet.Name, associationType)
                    {
                        new AssociationSetEnd(associationTypeEndLookup[oldAssociationSet.Ends[0].AssociationEnd], firstEntitySet),
                        new AssociationSetEnd(associationTypeEndLookup[oldAssociationSet.Ends[1].AssociationEnd], secondEntitySet),
                    };

                    oldAssociationSet.Container.Add(associationSet);
                }

                // Can't remove these yet, because we have to wait until the original has been copied for all derived entity types.
                oldAssociationSetsToRemove.AddRange(oldAssociationSets);
            }
        }
Exemplo n.º 22
0
        public static IEdmModel BuildTestMetadata(IEntityModelPrimitiveTypeResolver primitiveTypeResolver, IDataServiceProviderFactory provider)
        {
            var schema = new EntityModelSchema()
            {
                new ComplexType("TestNS", "Address")
                {
                    new MemberProperty("City", DataTypes.String.Nullable()),
                    new MemberProperty("Zip", DataTypes.Integer),
                    new ClrTypeAnnotation(typeof(Address))
                },
                new EntityType("TestNS", "Customer")
                {
                    new MemberProperty("ID", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Name", DataTypes.String.Nullable()),
                    new MemberProperty("Emails", DataTypes.CollectionType.WithElementDataType(DataTypes.String.Nullable())),
                    new MemberProperty("Address", DataTypes.ComplexType.WithName("TestNS", "Address")),
                    new ClrTypeAnnotation(typeof(Customer))
                },
                new EntityType("TestNS", "MultiKey")
                {
                    new MemberProperty("KeyB", DataTypes.FloatingPoint)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("KeyA", DataTypes.String.Nullable())
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Keya", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("NonKey", DataTypes.String.Nullable()),
                    new ClrTypeAnnotation(typeof(MultiKey))
                },
                new EntityType("TestNS", "TypeWithPrimitiveProperties")
                {
                    new MemberProperty("ID", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("StringProperty", DataTypes.String.Nullable()),
                    new MemberProperty("BoolProperty", DataTypes.Boolean),
                    new MemberProperty("NullableBoolProperty", DataTypes.Boolean.Nullable()),
                    new MemberProperty("ByteProperty", EdmDataTypes.Byte),
                    new MemberProperty("NullableByteProperty", EdmDataTypes.Byte.Nullable()),
                    new MemberProperty("DateTimeProperty", DataTypes.DateTime.WithTimeZoneOffset(true)),
                    new MemberProperty("NullableDateTimeProperty", DataTypes.DateTime.WithTimeZoneOffset(true).Nullable()),
                    new MemberProperty("DecimalProperty", EdmDataTypes.Decimal()),
                    new MemberProperty("NullableDecimalProperty", EdmDataTypes.Decimal().Nullable()),
                    new MemberProperty("DoubleProperty", EdmDataTypes.Double),
                    new MemberProperty("NullableDoubleProperty", EdmDataTypes.Double.Nullable()),
                    new MemberProperty("GuidProperty", DataTypes.Guid),
                    new MemberProperty("NullableGuidProperty", DataTypes.Guid.Nullable()),
                    new MemberProperty("Int16Property", EdmDataTypes.Int16),
                    new MemberProperty("NullableInt16Property", EdmDataTypes.Int16.Nullable()),
                    new MemberProperty("Int32Property", DataTypes.Integer),
                    new MemberProperty("NullableInt32Property", DataTypes.Integer.Nullable()),
                    new MemberProperty("Int64Property", EdmDataTypes.Int64),
                    new MemberProperty("NullableInt64Property", EdmDataTypes.Int64.Nullable()),
                    new MemberProperty("SByteProperty", EdmDataTypes.SByte),
                    new MemberProperty("NullableSByteProperty", EdmDataTypes.SByte.Nullable()),
                    new MemberProperty("SingleProperty", EdmDataTypes.Single),
                    new MemberProperty("NullableSingleProperty", EdmDataTypes.Single.Nullable()),
                    new MemberProperty("BinaryProperty", DataTypes.Binary.Nullable()),
                    new ClrTypeAnnotation(typeof(TypeWithPrimitiveProperties))
                }
            };

            List <FunctionParameter> defaultParameters = new List <FunctionParameter>()
            {
                new FunctionParameter("soParam", DataTypes.Integer)
            };

            EntitySet       customersSet = new EntitySet("Customers", "Customer");
            EntityContainer container    = new EntityContainer("BinderTestMetadata")
            {
                customersSet,
                new EntitySet("MultiKeys", "MultiKey"),
                new EntitySet("TypesWithPrimitiveProperties", "TypeWithPrimitiveProperties")
            };

            schema.Add(container);

            EntityDataType customerType = DataTypes.EntityType.WithName("TestNS", "Customer");
            EntityDataType multiKeyType = DataTypes.EntityType.WithName("TestNS", "MultiKey");
            EntityDataType entityTypeWithPrimitiveProperties = DataTypes.EntityType.WithName("TestNS", "TypeWithPrimitiveProperties");

            ComplexDataType addressType = DataTypes.ComplexType.WithName("TestNS", "Address");

            addressType.Definition.Add(new ClrTypeAnnotation(typeof(Address)));
            customerType.Definition.Add(new ClrTypeAnnotation(typeof(Customer)));
            multiKeyType.Definition.Add(new ClrTypeAnnotation(typeof(MultiKey)));
            entityTypeWithPrimitiveProperties.Definition.Add(new ClrTypeAnnotation(typeof(TypeWithPrimitiveProperties)));

            //container.Add(CreateServiceOperation("VoidServiceOperation", defaultParameters, null, ODataServiceOperationResultKind.Void));
            //container.Add(CreateServiceOperation("DirectValuePrimitiveServiceOperation", defaultParameters, DataTypes.Integer, ODataServiceOperationResultKind.DirectValue));
            //container.Add(CreateServiceOperation("DirectValueComplexServiceOperation", defaultParameters, addressType, ODataServiceOperationResultKind.DirectValue));
            //container.Add(CreateServiceOperation("DirectValueEntityServiceOperation", defaultParameters, customerType, customersSet, ODataServiceOperationResultKind.DirectValue));

            //container.Add(CreateServiceOperation("EnumerationPrimitiveServiceOperation", defaultParameters, DataTypes.CollectionType.WithElementDataType(DataTypes.Integer), ODataServiceOperationResultKind.Enumeration));
            //container.Add(CreateServiceOperation("EnumerationComplexServiceOperation", defaultParameters, addressType, ODataServiceOperationResultKind.Enumeration));
            //container.Add(CreateServiceOperation("EnumerationEntityServiceOperation", defaultParameters, DataTypes.CollectionOfEntities(customerType.Definition), customersSet, ODataServiceOperationResultKind.Enumeration));

            //container.Add(CreateServiceOperation("QuerySinglePrimitiveServiceOperation", defaultParameters, DataTypes.Integer, ODataServiceOperationResultKind.QueryWithSingleResult));
            //container.Add(CreateServiceOperation("QuerySingleComplexServiceOperation", defaultParameters, addressType, ODataServiceOperationResultKind.QueryWithSingleResult));
            //container.Add(CreateServiceOperation("QuerySingleEntityServiceOperation", defaultParameters, customerType, customersSet, ODataServiceOperationResultKind.QueryWithSingleResult));

            //container.Add(CreateServiceOperation("QueryMultiplePrimitiveServiceOperation", defaultParameters, DataTypes.Integer, ODataServiceOperationResultKind.QueryWithMultipleResults));
            //container.Add(CreateServiceOperation("QueryMultipleComplexServiceOperation", defaultParameters, addressType, ODataServiceOperationResultKind.QueryWithMultipleResults));
            //container.Add(CreateServiceOperation("QueryMultipleEntityServiceOperation", defaultParameters, DataTypes.CollectionOfEntities(customerType.Definition), customersSet, ODataServiceOperationResultKind.QueryWithMultipleResults));

            //container.Add(CreateServiceOperation("ServiceOperationWithNoParameters", new List<FunctionParameter>(), DataTypes.CollectionOfEntities(customerType.Definition), customersSet, ODataServiceOperationResultKind.QueryWithMultipleResults));
            //container.Add(CreateServiceOperation(
            //                        "ServiceOperationWithMultipleParameters",
            //                         new List<FunctionParameter>()
            //                         {
            //                             new FunctionParameter("paramInt", DataTypes.Integer),
            //                             new FunctionParameter("paramString", DataTypes.String.Nullable()),
            //                             new FunctionParameter("paramNullableBool", DataTypes.Boolean.Nullable())
            //                         },
            //                         DataTypes.CollectionOfEntities(customerType.Definition),
            //                         customersSet,
            //                         ODataServiceOperationResultKind.QueryWithMultipleResults));

            new ApplyDefaultNamespaceFixup("TestNS").Fixup(schema);
            new ResolveReferencesFixup().Fixup(schema);
            primitiveTypeResolver.ResolveProviderTypes(schema, new EdmDataTypeResolver());

            return(provider.CreateMetadataProvider(schema));
        }
Exemplo n.º 23
0
        private void AddServiceOperationsToModel(EntityModelSchema model)
        {
            model.Add(new Function("GetActor")
            {
                ReturnType  = DataTypes.CollectionType.WithElementDataType(DataTypes.EntityType.WithName("Actor")),
                Annotations =
                {
                    new LegacyServiceOperationAnnotation
                    {
                        Method = HttpVerb.Get,
                        ReturnTypeQualifier = ServiceOperationReturnTypeQualifier.IQueryable,
                    },
                    new FunctionBodyAnnotation
                    {
                        //// Enable the following line to add this to root query for cross feature testing
                        //// IsRoot = true,
                        FunctionBodyGenerator = (schema) =>
                        {
                            var entitySet = schema.GetDefaultEntityContainer().EntitySets.Single(es => es.Name.Equals("Actor"));
                            return(CommonQueryBuilder.Root(entitySet));
                        },
                    },
                }
            });

            model.Add(new Function("GetPrimitiveString")
            {
                ReturnType  = EdmDataTypes.String().NotNullable(),
                Annotations =
                {
                    new LegacyServiceOperationAnnotation
                    {
                        Method = HttpVerb.Get,
                    },
                    new FunctionBodyAnnotation
                    {
                        FunctionBody = CommonQueryBuilder.Constant("Foo"),
                    },
                },
            });

            // Add a service operation that requires parameter
            model.Add(new Function("GetArgumentPlusOne")
            {
                ReturnType  = EdmDataTypes.Int32.NotNullable(),
                Annotations =
                {
                    new LegacyServiceOperationAnnotation
                    {
                        Method = HttpVerb.Get,
                    },
                    new FunctionBodyAnnotation
                    {
                        FunctionBody = CommonQueryBuilder.Add(CommonQueryBuilder.FunctionParameterReference("arg1"), CommonQueryBuilder.Constant((int)1)),
                    },
                },
                Parameters =
                {
                    new FunctionParameter("arg1", EdmDataTypes.Int32.NotNullable()),
                },
            });

            // Add a WebInvoke service operation
            model.Add(
                new Function("WebInvokeGetMovie")
            {
                ReturnType  = DataTypes.CollectionType.WithElementDataType(DataTypes.EntityType.WithName("Movie")),
                Annotations =
                {
                    new LegacyServiceOperationAnnotation
                    {
                        Method = HttpVerb.Post,
                        ReturnTypeQualifier = ServiceOperationReturnTypeQualifier.IQueryable,
                    },

                    new FunctionBodyAnnotation
                    {
                        //// Enable the following line to add this to root query for cross feature testing
                        //// IsRoot = true,
                        FunctionBodyGenerator = (schema) =>
                        {
                            var entitySet = schema.GetDefaultEntityContainer().EntitySets.Single(es => es.Name.Equals("Movie"));
                            return(CommonQueryBuilder.Root(entitySet));
                        },
                    }
                },
            });

            model.Add(
                new Function("WebInvokeGetMovieWithParameter")
            {
                ReturnType  = DataTypes.CollectionType.WithElementDataType(DataTypes.EntityType.WithName("Movie")),
                Annotations =
                {
                    new LegacyServiceOperationAnnotation
                    {
                        Method = HttpVerb.Post,
                        ReturnTypeQualifier = ServiceOperationReturnTypeQualifier.IQueryable,
                    },

                    new FunctionBodyAnnotation
                    {
                        FunctionBodyGenerator = (schema) =>
                        {
                            var entitySet = schema.GetDefaultEntityContainer().EntitySets.Single(es => es.Name.Equals("Movie"));
                            return(CommonQueryBuilder.Root(entitySet));
                        },
                    }
                },
                Parameters =
                {
                    new FunctionParameter("arg1", EdmDataTypes.Int32.NotNullable()),
                    new FunctionParameter("arg2", EdmDataTypes.String().NotNullable()),
                },
            });
        }
Exemplo n.º 24
0
        /// <summary>
        /// Build a test model shared across several tests.
        /// </summary>
        /// <returns>Returns the test model.</returns>
        public static EntityModelSchema BuildTestModel()
        {
            // The metadata model
            EntityModelSchema model = new EntityModelSchema().MinimumVersion(ODataVersion.V4);

            ComplexType addressType = model.ComplexType("Address")
                                      .Property("Street", EdmDataTypes.String().Nullable())
                                      .Property("Zip", EdmDataTypes.Int32);

            EntityType officeType = model.EntityType("OfficeType")
                                    .KeyProperty("Id", EdmDataTypes.Int32)
                                    .Property("Address", DataTypes.ComplexType.WithDefinition(addressType));

            EntityType officeWithNumberType = model.EntityType("OfficeWithNumberType")
                                              .WithBaseType(officeType)
                                              .Property("Number", EdmDataTypes.Int32);

            EntityType cityType = model.EntityType("CityType")
                                  .KeyProperty("Id", EdmDataTypes.Int32)
                                  .Property("Name", EdmDataTypes.String().Nullable())
                                  .NavigationProperty("CityHall", officeType)
                                  .NavigationProperty("DOL", officeType)
                                  .NavigationProperty("PoliceStation", officeType, true)
                                  .StreamProperty("Skyline")
                                  .Property("MetroLanes", DataTypes.CollectionType.WithElementDataType(EdmDataTypes.String().Nullable()));

            EntityType cityWithMapType = model.EntityType("CityWithMapType")
                                         .WithBaseType(cityType)
                                         .DefaultStream();

            EntityType cityOpenType = model.EntityType("CityOpenType")
                                      .WithBaseType(cityType)
                                      .OpenType();

            EntityType personType = model.EntityType("Person")
                                    .KeyProperty("Id", EdmDataTypes.Int32);

            personType = personType.NavigationProperty("Friend", personType);

            EntityType employeeType = model.EntityType("Employee")
                                      .WithBaseType(personType)
                                      .Property("CompanyName", EdmDataTypes.String().Nullable());

            EntityType managerType = model.EntityType("Manager")
                                     .WithBaseType(employeeType)
                                     .Property("Level", EdmDataTypes.Int32);

            model.Add(new EntityContainer("DefaultContainer"));

            model.EntitySet("Offices", officeType);
            model.EntitySet("Cities", cityType);
            model.EntitySet("Persons", personType);

            model.Fixup();

            // Fixed up models will have entity sets for all base entity types.
            model.EntitySet("Employee", employeeType);
            model.EntitySet("Manager", managerType);

            EntityContainer container = model.EntityContainers.Single();

            // NOTE: Function import parameters and return types must be nullable as per current CSDL spec
            FunctionImport serviceOp = container.FunctionImport("ServiceOperation1")
                                       .Parameter("a", EdmDataTypes.Int32.Nullable())
                                       .Parameter("b", EdmDataTypes.String().Nullable())
                                       .ReturnType(EdmDataTypes.Int32.Nullable());

            container.FunctionImport("PrimitiveResultOperation")
            .ReturnType(EdmDataTypes.Int32.Nullable());
            container.FunctionImport("ComplexResultOperation")
            .ReturnType(DataTypes.ComplexType.WithDefinition(addressType).Nullable());
            container.FunctionImport("PrimitiveCollectionResultOperation")
            .ReturnType(DataTypes.CollectionType.WithElementDataType(EdmDataTypes.Int32.Nullable()));
            container.FunctionImport("ComplexCollectionResultOperation")
            .ReturnType(DataTypes.CollectionType.WithElementDataType(DataTypes.ComplexType.WithDefinition(addressType).Nullable()));

            // Overload with 0 Param
            container.FunctionImport("FunctionImportWithOverload");

            // Overload with 1 Param
            container.FunctionImport("FunctionImportWithOverload")
            .Parameter("p1", DataTypes.EntityType.WithDefinition(cityWithMapType));

            // Overload with 2 Params
            container.FunctionImport("FunctionImportWithOverload")
            .Parameter("p1", DataTypes.EntityType.WithDefinition(cityType))
            .Parameter("p2", EdmDataTypes.String().Nullable());

            // Overload with 5 Params
            container.FunctionImport("FunctionImportWithOverload")
            .Parameter("p1", DataTypes.CollectionOfEntities(cityType))
            .Parameter("p2", DataTypes.CollectionType.WithElementDataType(EdmDataTypes.String().Nullable()))
            .Parameter("p3", EdmDataTypes.String().Nullable())
            .Parameter("p4", DataTypes.ComplexType.WithDefinition(addressType).Nullable())
            .Parameter("p5", DataTypes.CollectionType.WithElementDataType(DataTypes.ComplexType.WithDefinition(addressType).Nullable()));

            return(model);
        }
Exemplo n.º 25
0
        public EntityModelSchema GenerateModel()
        {
            var model = new EntityModelSchema()
            {
                new EntityType("KatmaiEntity_DTO")
                {
                    new MemberProperty("Id", DataTypes.DateTime.WithTimeZoneOffset(true))
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("ETag", DataTypes.DateTime.Nullable().WithTimeZoneOffset(true))
                    {
                        Annotations = { new ConcurrencyTokenAnnotation() }
                    },
                    new MemberProperty("Published", DataTypes.DateTime.NotNullable().WithTimeZoneOffset(true)),
                    new MemberProperty("Complex", DataTypes.ComplexType.WithName("KatmaiComplex_DTO")).WithDataGenerationHints(DataGenerationHints.NoNulls),
                    new MemberProperty("Collection", DataTypes.CollectionType.WithElementDataType(DataTypes.DateTime.WithTimeZoneOffset(true))),
                    new MemberProperty("ComplexCollection", DataTypes.CollectionOfComplex("KatmaiComplex_DTO")),

                    new NavigationProperty("Ref", "KatmaiLink_DTO", "DTO", "Link"),
                },
                new ComplexType("KatmaiComplex_DTO")
                {
                    new MemberProperty("Updated", DataTypes.DateTime.NotNullable().WithTimeZoneOffset(true)),
                    new MemberProperty("Nullable", DataTypes.DateTime.Nullable().WithTimeZoneOffset(true)),
                    new MemberProperty("Collection", DataTypes.CollectionType.WithElementDataType(DataTypes.DateTime.WithTimeZoneOffset(true))),
                },
                new EntityType("KatmaiEntity_TS")
                {
                    new MemberProperty("Id", DataTypes.TimeOfDay)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("ETag", DataTypes.TimeOfDay.Nullable())
                    {
                        Annotations = { new ConcurrencyTokenAnnotation() }
                    },
                    new MemberProperty("Title", DataTypes.TimeOfDay),
                    new MemberProperty("Complex", DataTypes.ComplexType.WithName("KatmaiComplex_TS")).WithDataGenerationHints(DataGenerationHints.NoNulls),
                    new MemberProperty("Collection", DataTypes.CollectionType.WithElementDataType(DataTypes.TimeOfDay)),
                    new MemberProperty("ComplexCollection", DataTypes.CollectionOfComplex("KatmaiComplex_TS")),

                    new NavigationProperty("Ref", "KatmaiLink_TS", "TS", "Link"),
                },
                new ComplexType("KatmaiComplex_TS")
                {
                    new MemberProperty("Summary", DataTypes.TimeOfDay),
                    new MemberProperty("Nullable", DataTypes.TimeOfDay.Nullable()),
                    new MemberProperty("Collection", DataTypes.CollectionType.WithElementDataType(DataTypes.TimeOfDay)),
                },
                new EntityType("KatmaiLink")
                {
                    new MemberProperty("DTO", DataTypes.DateTime.WithTimeZoneOffset(true))
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("TS", DataTypes.TimeOfDay)
                    {
                        IsPrimaryKey = true
                    },

                    new NavigationProperty("DTOEntity", "KatmaiLink_DTO", "Link", "DTO"),
                    new NavigationProperty("TSEntity", "KatmaiLink_TS", "Link", "TS"),
                },
                new AssociationType("KatmaiLink_DTO")
                {
                    Ends =
                    {
                        new AssociationEnd("Link", "KatmaiLink",       EndMultiplicity.Many),
                        new AssociationEnd("DTO",  "KatmaiEntity_DTO", EndMultiplicity.One),
                    },
                    ReferentialConstraint =
                        new ReferentialConstraint()
                        .WithDependentProperties("Link", "DTO")
                        .ReferencesPrincipalProperties("DTO", "Id"),
                },
                new AssociationType("KatmaiLink_TS")
                {
                    Ends =
                    {
                        new AssociationEnd("Link", "KatmaiLink",      EndMultiplicity.Many),
                        new AssociationEnd("TS",   "KatmaiEntity_TS", EndMultiplicity.One),
                    },
                    ReferentialConstraint =
                        new ReferentialConstraint()
                        .WithDependentProperties("Link", "TS")
                        .ReferencesPrincipalProperties("TS", "Id"),
                },
                new EntityType("Calendar")
                {
                    new MemberProperty("UID", DataTypes.Integer.NotNullable())
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Name", DataTypes.String.NotNullable().WithMaxLength(512)),
                    new MemberProperty("IsBaseCalendar", DataTypes.Boolean.NotNullable()),
                    new MemberProperty("WeekDays", DataTypes.CollectionOfComplex("WeekDay")),
                },
                new ComplexType("WeekDay")
                {
                    new MemberProperty("DayType", DataTypes.Integer),
                    new MemberProperty("DayWorking", DataTypes.Boolean),
                    new MemberProperty("TimePeriod", DataTypes.ComplexType.WithName("TimePeriod").NotNullable()),
                    new MemberProperty("WorkingTimes", DataTypes.CollectionOfComplex("WorkingTime")),
                },
                new ComplexType("TimePeriod")
                {
                    new MemberProperty("FromDate", DataTypes.DateTime.WithTimeZoneOffset(true).NotNullable()),
                    new MemberProperty("ToDate", DataTypes.DateTime.WithTimeZoneOffset(true).NotNullable()),
                },
                new ComplexType("WorkingTime")
                {
                    new MemberProperty("FromTime", DataTypes.DateTime.WithTimeZoneOffset(true).NotNullable()),
                    new MemberProperty("ToTime", DataTypes.DateTime.WithTimeZoneOffset(true).NotNullable()),
                },
                new EntityType("Footrace")
                {
                    new MemberProperty("Id", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Name", DataTypes.String),

                    new NavigationProperty("Times", "Footrace_Time", "Footrace", "Time"),
                },
                new EntityType("Person")
                {
                    new MemberProperty("Id", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Name", DataTypes.String),

                    new NavigationProperty("Calendars", "Person_Calendar", "Person", "Calendar"),
                    new NavigationProperty("RaceTimes", "Person_Time", "Person", "Time"),
                },
                new EntityType("FootraceTime")
                {
                    new MemberProperty("Id", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("StartTime", DataTypes.DateTime.WithTimeZoneOffset(true)),
                    new MemberProperty("ElapsedTime", DataTypes.TimeOfDay),
                    new MemberProperty("EndTime", DataTypes.DateTime.WithTimeZoneOffset(true)),

                    new NavigationProperty("Person", "Person_Time", "Time", "Person"),
                    new NavigationProperty("FootRace", "Footrace_Time", "Time", "Footrace"),
                },
                new AssociationType("Person_Calendar")
                {
                    Ends =
                    {
                        new AssociationEnd("Person",   "Person",   EndMultiplicity.One),
                        new AssociationEnd("Calendar", "Calendar", EndMultiplicity.Many),
                    },
                },
                new AssociationType("Person_Time")
                {
                    Ends =
                    {
                        new AssociationEnd("Person", "Person",       EndMultiplicity.One),
                        new AssociationEnd("Time",   "FootraceTime", EndMultiplicity.Many),
                    },
                },
                new AssociationType("Footrace_Time")
                {
                    Ends =
                    {
                        new AssociationEnd("Footrace", "Footrace",     EndMultiplicity.One),
                        new AssociationEnd("Time",     "FootraceTime", EndMultiplicity.Many),
                    },
                },
                new EntityContainer("KatmaiTypeContainer")
                {
                    new DataServiceConfigurationAnnotation()
                    {
                        UseVerboseErrors = true,
                    },
                    new DataServiceBehaviorAnnotation()
                    {
                        MaxProtocolVersion = DataServiceProtocolVersion.V4,
                    },
                    new EntitySet("DateTimeOffsets", "KatmaiEntity_DTO")
                    {
                        new PageSizeAnnotation()
                        {
                            PageSize = 3
                        },
                    },
                    new EntitySet("TimeSpans", "KatmaiEntity_TS")
                    {
                        new PageSizeAnnotation()
                        {
                            PageSize = 7
                        },
                    },
                    new EntitySet("KatmaiLinks", "KatmaiLink"),
                    new AssociationSet("KatmaiLinks_DTO")
                    {
                        AssociationType = "KatmaiLink_DTO",
                        Ends            =
                        {
                            new AssociationSetEnd("Link", "KatmaiLinks"),
                            new AssociationSetEnd("DTO",  "DateTimeOffsets"),
                        }
                    },
                    new AssociationSet("KatmaiLinks_TS")
                    {
                        AssociationType = "KatmaiLink_TS",
                        Ends            =
                        {
                            new AssociationSetEnd("Link", "KatmaiLinks"),
                            new AssociationSetEnd("TS",   "TimeSpans"),
                        }
                    },
                    new EntitySet("Calendars", "Calendar"),
                    new EntitySet("People", "Person"),
                    new EntitySet("Footraces", "Footrace"),
                    new EntitySet("FootraceTimes", "FootraceTime"),
                    new AssociationSet("People_Calendars")
                    {
                        AssociationType = "Person_Calendar",
                        Ends            =
                        {
                            new AssociationSetEnd("Person",   "People"),
                            new AssociationSetEnd("Calendar", "Calendars"),
                        }
                    },
                    new AssociationSet("People_Times")
                    {
                        AssociationType = "Person_Time",
                        Ends            =
                        {
                            new AssociationSetEnd("Person", "People"),
                            new AssociationSetEnd("Time",   "FootraceTimes"),
                        }
                    },
                    new AssociationSet("Footraces_Times")
                    {
                        AssociationType = "Footrace_Time",
                        Ends            =
                        {
                            new AssociationSetEnd("Footrace", "Footraces"),
                            new AssociationSetEnd("Time",     "FootraceTimes"),
                        }
                    },
                }
            };

            // TODO: re-enable when product bug for service ops with type segments are fixed
            ////new AddRootServiceOperationsFixup().Fixup(model);

            model.Add(CreateSimpleServiceOperation("GetDateTimeOffset", DataTypes.DateTime.WithTimeZoneOffset(true).NotNullable()));
            model.Add(CreateSimpleServiceOperation("GetNullableDateTimeOffset", DataTypes.DateTime.WithTimeZoneOffset(true).Nullable()));
            model.Add(CreateSimpleServiceOperation("GetTimeSpan", DataTypes.TimeOfDay.NotNullable()));
            model.Add(CreateSimpleServiceOperation("GetNullableTimeSpan", DataTypes.TimeOfDay.Nullable()));

            model.Add(CreateCollectionServiceOperation("GetDateTimeOffsets", DataTypes.DateTime.WithTimeZoneOffset(true).NotNullable()));
            model.Add(CreateCollectionServiceOperation("GetNullableDateTimeOffsets", DataTypes.DateTime.WithTimeZoneOffset(true).Nullable()));
            model.Add(CreateCollectionServiceOperation("GetTimeSpans", DataTypes.TimeOfDay.NotNullable()));
            model.Add(CreateCollectionServiceOperation("GetNullableTimeSpans", DataTypes.TimeOfDay.Nullable()));

            model.Add(CreateSingleEntityServiceOperation("GetFirstDTOEntityGreaterThan", "DateTimeOffsets", "KatmaiEntity_DTO", "Published", DataTypes.DateTime.WithTimeZoneOffset(true).NotNullable()));
            model.Add(CreateSingleEntityServiceOperation("GetFirstNullableDTOEntityGreaterThan", "DateTimeOffsets", "KatmaiEntity_DTO", "ETag", DataTypes.DateTime.WithTimeZoneOffset(true).Nullable()));
            model.Add(CreateSingleEntityServiceOperation("GetFirstTSEntityGreaterThan", "TimeSpans", "KatmaiEntity_TS", "Title", DataTypes.TimeOfDay.NotNullable()));
            model.Add(CreateSingleEntityServiceOperation("GetFirstNullableTSEntityGreaterThan", "TimeSpans", "KatmaiEntity_TS", "ETag", DataTypes.TimeOfDay.Nullable()));

            model.Add(CreateMultipleEntityServiceOperation("GetDTOEntitiesGreaterThan", "DateTimeOffsets", "KatmaiEntity_DTO", "Published", DataTypes.DateTime.WithTimeZoneOffset(true).NotNullable()));
            model.Add(CreateMultipleEntityServiceOperation("GetNullableDTOEntitiesGreaterThan", "DateTimeOffsets", "KatmaiEntity_DTO", "ETag", DataTypes.DateTime.WithTimeZoneOffset(true).Nullable()));
            model.Add(CreateMultipleEntityServiceOperation("GetTSEntitiesGreaterThan", "TimeSpans", "KatmaiEntity_TS", "Title", DataTypes.TimeOfDay.NotNullable()));
            model.Add(CreateMultipleEntityServiceOperation("GetNullableTSEntitiesGreaterThan", "TimeSpans", "KatmaiEntity_TS", "ETag", DataTypes.TimeOfDay.Nullable()));

            new ResolveReferencesFixup().Fixup(model);
            new ApplyDefaultNamespaceFixup("KatmaiTypes").Fixup(model);

            return(model);
        }