Beispiel #1
0
 /// <summary>
 /// Removes an <see cref="FunctionImport"/> from <see cref="FunctionImports" /> collection.
 /// </summary>
 /// <param name="functionImport">FunctionImport to remove.</param>
 public void Remove(FunctionImport functionImport)
 {
     ExceptionUtilities.CheckArgumentNotNull(functionImport, "functionImport");
     ExceptionUtilities.Assert(functionImport.Container == this, "Function import set was not added to this container");
     ExceptionUtilities.Assert(this.functionImportsList.Remove(functionImport), "Function import set was not added to this model");
     functionImport.Container = null;
 }
        /// <summary>
        /// Compares the actual function import against the expected.
        /// </summary>
        /// <param name="expectedFunctionImport">expected function import</param>
        /// <param name="actualFunctionImport">actual import</param>
        /// <remarks>This implementation also compares the annotations on the function import.</remarks>
        protected override void CompareFunctionImport(FunctionImport expectedFunctionImport, FunctionImport actualFunctionImport)
        {
            // TODO: Add support for checking annotations to the EntityModelSchemaComparer.CompareFunctionImport method.
            // We have overridden the base method because we wanted to minimize the impact of this change to other existing Taupo test cases.
            base.CompareFunctionImport(expectedFunctionImport, actualFunctionImport);

            if (!this.WriteErrorIfFalse(
                 expectedFunctionImport.Annotations.OfType<AttributeAnnotation>().Count() == actualFunctionImport.Annotations.OfType<AttributeAnnotation>().Count(),
                 "Expected and actual count of the FunctionImport annotations did not match."))
            {
                // verify annotations
                foreach (AttributeAnnotation expectedAnnotation in expectedFunctionImport.Annotations.OfType<AttributeAnnotation>())
                {
                    AttributeAnnotation actualAnnotation = actualFunctionImport.Annotations.OfType<AttributeAnnotation>().SingleOrDefault(
                        ann => ann.Content.Name.Equals(expectedAnnotation.Content.Name));
                        
                    if (!this.WriteErrorIfFalse(actualAnnotation != null, "The expected annotation named '{0}' was not found in the FunctionImport.", expectedAnnotation.Content.Name.LocalName))
                    {
                        this.WriteErrorIfFalse(
                            actualAnnotation.Content.Value == expectedAnnotation.Content.Value,
                            "FunctionImport annotation not equal. Expected {0}, Actual: {1}",
                            expectedAnnotation.Content.Value,
                            actualAnnotation.Content.Value);
                    }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Adds an <see cref="FunctionImport"/> to <see cref="FunctionImports" /> collection.
        /// </summary>
        /// <param name="functionImport">FunctionImport to add.</param>
        public void Add(FunctionImport functionImport)
        {
            ExceptionUtilities.CheckArgumentNotNull(functionImport, "functionImport");

            // NOTE: even though function import has an entity set property, it may not ever be set, so we need to record its container as well
            ExceptionUtilities.Assert(functionImport.Container == null, "Function import was already added to another container");
            functionImport.Container = this;
            this.functionImportsList.Add(functionImport);
        }
        /// <summary>
        /// Performs a deep copy of the specified <see cref="FunctionImport"/>.
        /// </summary>
        /// <param name="functionImport">The <see cref="FunctionImport"/> to deep copy.</param>
        /// <returns>A deep copy of the <see cref="FunctionImport"/>.</returns>
        private static FunctionImport Clone(this FunctionImport functionImport)
        {
            var clone = new FunctionImport(functionImport.Name)
            {
                IsComposable    = functionImport.IsComposable,
                IsBindable      = functionImport.IsBindable,
                IsSideEffecting = functionImport.IsSideEffecting,
            };

            CopyAnnotations(clone, functionImport.Annotations);

            foreach (var parameter in functionImport.Parameters)
            {
                clone.Add(parameter.Clone());
            }

            foreach (var returnType in functionImport.ReturnTypes)
            {
                clone.Add(new FunctionImportReturnType(returnType.DataType.Clone(), returnType.EntitySet.NameOrNull()));
            }

            return(clone);
        }
        /// <summary>
        /// Compares the actual function import against the expected.
        /// </summary>
        /// <param name="expectedFunctionImport">expected function import</param>
        /// <param name="actualFunctionImport">actual import</param>
        protected virtual void CompareFunctionImport(FunctionImport expectedFunctionImport, FunctionImport actualFunctionImport)
        {
            this.WriteErrorIfFalse(expectedFunctionImport.Name == actualFunctionImport.Name, "Wrong FunctionImport to compare.");
            
            // verify return type
            this.WriteErrorIfFalse(expectedFunctionImport.ReturnTypes.Count == actualFunctionImport.ReturnTypes.Count, "Wrong number of return type.");
            
            FunctionImportReturnType expectedReturnType = null;
            FunctionImportReturnType actualReturnType = null;
            if (expectedFunctionImport.ReturnTypes.Any())
            {
                expectedReturnType = expectedFunctionImport.ReturnTypes.Single();
                actualReturnType = actualFunctionImport.ReturnTypes.Single();
                this.WriteErrorIfFalse(expectedReturnType.DataType.GetType().Equals(actualReturnType.DataType.GetType()), "Expected Return Type {0} is not equal to actual Return Type {1}", expectedReturnType.DataType.GetType(), actualReturnType.DataType.GetType());
                if (expectedReturnType.EntitySet == null)
                {
                    this.WriteErrorIfFalse(actualReturnType.EntitySet == null, "Expected EntitySet {0} is not equal to actual EntitySet {1} {2}", expectedReturnType.EntitySet, actualReturnType.EntitySet, actualFunctionImport.Name);
                }
                else
                {
                    this.WriteErrorIfFalse(expectedReturnType.EntitySet.Name == actualReturnType.EntitySet.Name, "Expected EntitySet {0} is not equal to actual EntitySet {1} {2}", expectedReturnType.EntitySet, actualReturnType.EntitySet, actualFunctionImport.Name);
                }
            }

            // verify parameters
            ExceptionUtilities.Assert(expectedFunctionImport.Parameters.Count == actualFunctionImport.Parameters.Count, "Wrong number of parameters.");
            foreach (FunctionParameter expectedParameter in expectedFunctionImport.Parameters)
            {
                FunctionParameter actualParameter = actualFunctionImport.Parameters.Single(p => p.Name == expectedParameter.Name);
                this.WriteErrorIfFalse(expectedParameter.DataType.GetType().Equals(actualParameter.DataType.GetType()), "Wrong parameter type, Expected {0}, Actual {1}", expectedParameter.DataType.GetType(), actualParameter.DataType.GetType());
                this.WriteErrorIfFalse(expectedParameter.Mode == actualParameter.Mode, "Wrong parameter mode, Expected {0}, Actual {1}.", expectedParameter.Mode, actualParameter.Mode);
            }

            this.WriteErrorIfFalse(expectedFunctionImport.IsBindable == actualFunctionImport.IsBindable, "FunctionImport.IsBindable is not equal, Expected {0}, Actual: {1}", expectedFunctionImport.IsBindable, actualFunctionImport.IsBindable);
            this.WriteErrorIfFalse(expectedFunctionImport.IsComposable == actualFunctionImport.IsComposable, "FunctionImport.IsComposable is not equal, Expected {0}, Actual: {1}", expectedFunctionImport.IsComposable, actualFunctionImport.IsComposable);
            this.WriteErrorIfFalse(expectedFunctionImport.IsSideEffecting == actualFunctionImport.IsSideEffecting, "FunctionImport.IsSideEffecting is not equal, Expected {0}, Actual: {1}", expectedFunctionImport.IsSideEffecting, actualFunctionImport.IsSideEffecting);
        }
Beispiel #6
0
 /// <summary>
 /// Removes an <see cref="FunctionImport"/> from <see cref="FunctionImports" /> collection.
 /// </summary>
 /// <param name="functionImport">FunctionImport to remove.</param>
 public void Remove(FunctionImport functionImport)
 {
     ExceptionUtilities.CheckArgumentNotNull(functionImport, "functionImport");
     ExceptionUtilities.Assert(functionImport.Container == this, "Function import set was not added to this container");
     ExceptionUtilities.Assert(this.functionImportsList.Remove(functionImport), "Function import set was not added to this model");
     functionImport.Container = null;
 }
Beispiel #7
0
        /// <summary>
        /// Adds an <see cref="FunctionImport"/> to <see cref="FunctionImports" /> collection.
        /// </summary>
        /// <param name="functionImport">FunctionImport to add.</param>
        public void Add(FunctionImport functionImport)
        {
            ExceptionUtilities.CheckArgumentNotNull(functionImport, "functionImport");

            // NOTE: even though function import has an entity set property, it may not ever be set, so we need to record its container as well
            ExceptionUtilities.Assert(functionImport.Container == null, "Function import was already added to another container");
            functionImport.Container = this;
            this.functionImportsList.Add(functionImport);
        }
 /// <summary>
 /// Visit Function Import to convert Mime Type annotations on it
 /// </summary>
 /// <param name="functionImport">function import to convert annotations on</param>
 protected override void VisitFunctionImport(FunctionImport functionImport)
 {
     this.ConvertMimeTypeAnnotations(functionImport);
 }
        private XElement GenerateFunctionImport(XNamespace xmlNamespace, FunctionImport functionImport)
        {
            MethodAccessModifierAnnotation annotation = functionImport.Annotations.OfType<MethodAccessModifierAnnotation>().SingleOrDefault();
            EntitySetPathAnnotation entitySetPathAnnotation = functionImport.Annotations.OfType<EntitySetPathAnnotation>().SingleOrDefault();

            return new XElement(
                xmlNamespace + "FunctionImport",
                new XAttribute("Name", functionImport.Name),
                this.GenerateDocumentation(xmlNamespace, functionImport),
                this.CsdlDataTypeGenerator.GenerateReturnTypeForFunctionImport(functionImport.ReturnTypes, xmlNamespace),
                functionImport.IsComposable ? new XAttribute("IsComposable", true) : null,
                functionImport.IsSideEffecting ? null : new XAttribute("IsSideEffecting", false),
                functionImport.IsBindable ? new XAttribute("IsBindable", true) : null,
                entitySetPathAnnotation != null ? new XAttribute("EntitySetPath", entitySetPathAnnotation.EntitySetPath) : null,
                this.GenerateFunctionImportParameters(functionImport.Parameters, xmlNamespace),
                this.GenerateAnnotations(xmlNamespace, functionImport),
                GenerateMethodAccessModifier(annotation));
        }
        private FunctionImport ConvertToTaupoFunctionImport(IEdmOperationImport edmFunctionImport)
        {
            var taupoFunctionImport = new FunctionImport(edmFunctionImport.Name);
            var functionImportReturnType = new FunctionImportReturnType();
            var addReturnType = false;
            if (edmFunctionImport.EntitySet != null)
            {
                IEdmEntitySet entitySet;
                if (edmFunctionImport.TryGetStaticEntitySet(out entitySet))
                {
                    functionImportReturnType.EntitySet = new EntitySetReference(entitySet.Name);
                    addReturnType = true;
                }
                else
                {
                    throw new NotSupportedException("Function import with entity set path is not supported.");
                }
            }

            if (edmFunctionImport.Operation.ReturnType != null)
            {
                functionImportReturnType.DataType = this.ConvertToTaupoDataType(edmFunctionImport.Operation.ReturnType);
                addReturnType = true;
            }

            if (addReturnType)
            {
                taupoFunctionImport.Add(functionImportReturnType);
            }

            foreach (var edmFunctionParameter in edmFunctionImport.Operation.Parameters)
            {
                FunctionParameter taupoFunctionParameter = this.ConvertToTaupoFunctionParameter(edmFunctionParameter);
                taupoFunctionImport.Parameters.Add(taupoFunctionParameter);
            }

            this.ConvertAnnotationsIntoTaupo(edmFunctionImport, taupoFunctionImport);
            return taupoFunctionImport;
        }
        private bool FunctionImportSignaturesAreSame(FunctionImport f1, FunctionImport f2)
        {
            if (f1.Name != f2.Name)
            {
                return false;
            }

            return this.ParametersMatch(f1.Parameters, f2.Parameters);
        }
        private void CompareFunctionImport(FunctionImport expectedFunctionImport, FunctionImport actualFunctionImport)
        {
            this.SatisfiesCondition(expectedFunctionImport.ReturnTypes.Count == actualFunctionImport.ReturnTypes.Count, "FunctionImport '{0}' has the wrong number of return types. Expected:{1} Actual:{2}.", expectedFunctionImport.Name, expectedFunctionImport.ReturnTypes.Count, actualFunctionImport.ReturnTypes.Count);
            for (int i = 0; i < expectedFunctionImport.ReturnTypes.Count; i++)
            {
                var expectedReturnType = expectedFunctionImport.ReturnTypes[i];
                var actualReturnType = actualFunctionImport.ReturnTypes[i];
                if (expectedReturnType.EntitySet == null)
                {
                    this.SatisfiesCondition(actualReturnType.EntitySet == null, "FunctionImport '{0}' should not have EntitySet.", expectedFunctionImport.Name);
                }
                else
                {
                    this.SatisfiesEquals(
                        expectedReturnType.EntitySet.Name,
                        actualReturnType.EntitySet.Name,
                        "EntitySet on FunctionImport '{0}' does not match.",
                        expectedFunctionImport.Name);
                }

                this.CompareReturnType(
                    expectedReturnType.DataType,
                    actualReturnType.DataType,
                    string.Format(CultureInfo.InvariantCulture, "FunctionImport '{0}'", expectedFunctionImport.Name));
            }

            this.CompareParameters(
                expectedFunctionImport.Parameters,
                actualFunctionImport.Parameters,
                string.Format(CultureInfo.InvariantCulture, "FunctionImport '{0}'", expectedFunctionImport.Name));
        }
Beispiel #13
0
        private void CloneContainerContents(EntityContainer baseContainer, EntityContainer extendedContainer)
        {
            foreach (var entitySet in baseContainer.EntitySets)
            {
                var clonedEntitySet = new EntitySet(entitySet.Name, entitySet.EntityType);
                extendedContainer.Add(clonedEntitySet);
            }

            foreach (var associationSet in baseContainer.AssociationSets)
            {
                var clonedAssociationSet = new AssociationSet(associationSet.Name, associationSet.AssociationType);
                foreach (var setEnd in associationSet.Ends)
                {
                    clonedAssociationSet.Add(new AssociationSetEnd(setEnd.AssociationEnd, setEnd.EntitySet.Name));
                }

                extendedContainer.Add(clonedAssociationSet);
            }

            foreach (var functionImport in baseContainer.FunctionImports)
            {
                var clonedFunctionImport = new FunctionImport(functionImport.Name);
                foreach (var returnType in functionImport.ReturnTypes)
                {
                    clonedFunctionImport.ReturnTypes.Add(returnType);
                }

                foreach (var parameter in functionImport.Parameters)
                {
                    clonedFunctionImport.Add(new FunctionParameter(parameter.Name, parameter.DataType, parameter.Mode));
                }

                extendedContainer.Add(clonedFunctionImport);
            }
        }
Beispiel #14
0
        private FunctionImport ParseFunctionImport(XElement functionImportElement)
        {
            string functionImportName = functionImportElement.GetRequiredAttributeValue("Name");

            var functionImport = new FunctionImport(functionImportName);

            bool isComposable = XmlConvert.ToBoolean(functionImportElement.GetOptionalAttributeValue("IsComposable", "false"));
            functionImport.IsComposable = isComposable;

            bool isBindable = XmlConvert.ToBoolean(functionImportElement.GetOptionalAttributeValue("IsBindable", "false"));
            functionImport.IsBindable = isBindable;

            bool isSideEffecting = XmlConvert.ToBoolean(functionImportElement.GetOptionalAttributeValue("IsSideEffecting", "true"));
            functionImport.IsSideEffecting = isSideEffecting;

            string entitySetPath = functionImportElement.GetOptionalAttributeValue("EntitySetPath", null);
            if (entitySetPath != null)
            {
                functionImport.Annotations.Add(new EntitySetPathAnnotation(entitySetPath));
            }

            foreach (var parameterElement in functionImportElement.Elements().Where(el => this.IsXsdlElement(el, "Parameter")))
            {
                functionImport.Parameters.Add(this.ParseFunctionParameter(parameterElement));
            }

            string returnTypeName = functionImportElement.GetOptionalAttributeValue("ReturnType", null);

            if (returnTypeName != null)
            {
                bool isNullable = XmlConvert.ToBoolean(functionImportElement.GetOptionalAttributeValue("Nullable", "true"));
                var returnType = new FunctionImportReturnType(this.ParseType(returnTypeName, isNullable, null));
                string entitySetName = functionImportElement.GetOptionalAttributeValue("EntitySet", null);
                if (entitySetName != null)
                {
                    returnType.EntitySet = new EntitySetReference(entitySetName);
                }

                functionImport.Add(returnType);
            }

            foreach (var returnTypeElement in functionImportElement.Elements().Where(el => this.IsXsdlElement(el, "ReturnType")))
            {
                var type = returnTypeElement.GetRequiredAttributeValue("Type");
                var returnType = new FunctionImportReturnType(this.ParseType(type, true, null));
                var entitySet = returnTypeElement.GetOptionalAttributeValue("EntitySet", null);
                if (entitySet != null)
                {
                    returnType.EntitySet = new EntitySetReference(entitySet);
                }

                functionImport.ReturnTypes.Add(returnType);
            }

            string methodaccess = functionImportElement.GetOptionalAttributeValue(EdmConstants.CodegenNamespace + "MethodAccess", null);
            if (methodaccess != null)
            {
                functionImport.Annotations.Add(new MethodAccessModifierAnnotation(this.GetAccessModifier(methodaccess)));
            }

            this.ParseAnnotations(functionImport, functionImportElement);
            return functionImport;
        }
Beispiel #15
0
        /// <summary>
        /// Resolves the specified entity model function import and returns the Edm model function import for it.
        /// </summary>
        /// <param name="model">The model to get the type from.</param>
        /// <param name="functionImport">The entity model function import to resolve.</param>
        /// <returns>The resolved function import for the specified <paramref name="functionImport"/>.</returns>
        public static IEdmOperationImport ResolveEntityModelSchemaFunctionImport(IEdmModel model, FunctionImport functionImport)
        {
            if (functionImport == null)
            {
                return null;
            }

            if (model == null)
            {
                return null;
            }

            IEdmEntityContainer edmEntityContainer = model.FindEntityContainer(functionImport.Container.FullName);
            if (edmEntityContainer == null)
            {
                ExceptionUtilities.Assert(
                    edmEntityContainer != null,
                    "The entity container '{0}' for function import '{1}' was not found in the model.",
                    functionImport.Container.FullName,
                    functionImport.Name);
            }

            IEnumerable<IEdmOperationImport> edmFunctionImports = edmEntityContainer.FindOperationImports(functionImport.Name);
            ExceptionUtilities.Assert(
                edmFunctionImports.Count() == 1,
                "There's either no or more than one function import with name '{0}' in the entity container '{1}'.",
                functionImport.Name,
                functionImport.Container.FullName);

            return edmFunctionImports.Single();
        }
        /// <summary>
        /// Visit function import
        /// </summary>
        /// <param name="functionImport">function import to visit</param>
        protected virtual void VisitFunctionImport(FunctionImport functionImport)
        {
            this.VisitAnnotatedItem(functionImport);

            foreach (var parameter in functionImport.Parameters)
            {
                this.VisitFunctionParameter(parameter);
            }
        }