Exemple #1
0
        private void VerifyFindParameterMethod(XElement sourceCsdl, IEdmModel testModel)
        {
            var csdlNamespace = EdmLibCsdlContentGenerator.GetCsdlFullNamespace(this.EdmVersion);

            Assert.AreEqual(csdlNamespace, sourceCsdl.Name.Namespace, "The source CSDL's namespace should match the target EDM version of the test cases.");

            var namespaceValue     = sourceCsdl.Attribute("Namespace").Value;
            var schemaElementTypes = new string[] { "Parameter" };

            foreach (var schemaElementType in schemaElementTypes)
            {
                Console.WriteLine("Test CSDL:\n\r{0}", sourceCsdl.ToString());

                foreach (var parameterElement in sourceCsdl.Descendants().Elements(XName.Get(schemaElementType, csdlNamespace.NamespaceName)))
                {
                    IEdmOperationParameter parameterFound = null;
                    var paramterName = parameterElement.Attribute("Name").Value;
                    Assert.IsTrue(new string[] { "Function", "Action" }.Any(n => n == parameterElement.Parent.Name.LocalName), "<Parameter> is used in {0}", parameterElement.Parent.Name.LocalName);

                    IEdmOperation elementFound;

                    var schemaElementName = string.Format("{0}.{1}", namespaceValue, parameterElement.Parent.Attribute("Name").Value);
                    elementFound = testModel.FindOperations(schemaElementName).Where(n => n.FindParameter(paramterName) != null).FirstOrDefault();

                    parameterFound = elementFound.FindParameter(paramterName);

                    Assert.IsNotNull(parameterFound, "Faild to FindParameter for the parameter : {0}", paramterName);
                    Assert.AreEqual(parameterFound.Name, paramterName, "FindParameter returns a wrong parameter for {0}", parameterElement.Attribute("Name").Value);
                }
            }
        }
Exemple #2
0
        private void VerifyFindNavigationPropertyMethod(XElement sourceCsdl, IEdmModel testModel)
        {
            var csdlNamespace = EdmLibCsdlContentGenerator.GetCsdlFullNamespace(this.EdmVersion);

            Assert.AreEqual(csdlNamespace, sourceCsdl.Name.Namespace, "The source CSDL's namespace should match the target EDM version of the test cases.");

            var namespaceValue = sourceCsdl.Attribute("Namespace").Value;
            var elementTypes   = new string[] { "NavigationProperty" };

            foreach (var elementType in elementTypes)
            {
                var elementTypeFoundList = sourceCsdl.Descendants().Elements(XName.Get(elementType, csdlNamespace.NamespaceName));

                foreach (var elementTypeFound in elementTypeFoundList)
                {
                    Assert.IsTrue(new string[] { "EntityType" }.Any(n => n == elementTypeFound.Parent.Name.LocalName), "<NavigationProperty> is used in {0}", elementTypeFound.Parent.Name.LocalName);

                    var entityTypeName      = elementTypeFound.Parent.Attribute("Name").Value;
                    var entityType          = testModel.FindType(namespaceValue + "." + entityTypeName) as IEdmEntityType;
                    var entityTypeReference = new EdmEntityTypeReference(entityType, true);

                    var navigationFound = entityTypeReference.FindNavigationProperty(elementTypeFound.Attribute("Name").Value);

                    Assert.IsNotNull(navigationFound, "Navigation property cannot found.");
                }
            }
        }
Exemple #3
0
        private void VerifyFindPropertyMethod(XElement sourceCsdl, IEdmModel testModel)
        {
            var csdlNamespace = EdmLibCsdlContentGenerator.GetCsdlFullNamespace(this.EdmVersion);

            Assert.AreEqual(csdlNamespace, sourceCsdl.Name.Namespace, "The source CSDL's namespace should match the target EDM version of the test cases.");

            var namespaceValue     = sourceCsdl.Attribute("Namespace").Value;
            var schemaElementTypes = new string[] { "Property", "NavigationProperty" };

            foreach (var schemaElementType in schemaElementTypes)
            {
                Console.WriteLine("Test CSDL:\n\r{0}", sourceCsdl.ToString());
                foreach (var propertyElement in sourceCsdl.Descendants().Elements(XName.Get(schemaElementType, csdlNamespace.NamespaceName)))
                {
                    IEdmProperty foundProperty = null;
                    Assert.IsTrue(new string[] { "EntityType", "ComplexType", "RowType" }.Any(n => n == propertyElement.Parent.Name.LocalName), "<Property> is used in {0}", propertyElement.Parent.Name.LocalName);

                    if (propertyElement.Parent.Name.LocalName != "RowType")
                    {
                        var schemaElementName = string.Format("{0}.{1}", namespaceValue, propertyElement.Parent.Attribute("Name").Value);
                        var elementFound      = testModel.FindType(schemaElementName) as IEdmStructuredType;
                        foundProperty = elementFound.FindProperty(propertyElement.Attribute("Name").Value);
                    }
                    else if (propertyElement.Parent.Parent.Name.LocalName == "CollectionType")
                    {
                        // TODO: Make VerifyFindPropertyMethod support properties defined in RowType of CollectionType.
                        throw new NotImplementedException("VerifyFindPropertyMethod does not support properties defined in RowType of CollectionType.");
                    }

                    Assert.IsNotNull(foundProperty, "Failed to FindProperty for the property : {0}", propertyElement.Attribute("Name").Value);
                    Assert.AreEqual(foundProperty.Name, propertyElement.Attribute("Name").Value, "FindProperty returns a wrong property for {0}", propertyElement.Attribute("Name").Value);
                }
            }
        }
        private string FixupAllNamespacePlaceholders(string inputCsdlString)
        {
            string xmlNamespace = EdmLibCsdlContentGenerator.GetCsdlFullNamespace(this.EdmVersion).NamespaceName;

            return(inputCsdlString.Replace("$$XmlNamespace$$", xmlNamespace)
                   .Replace("$$DefaultSchemaNamespace$$", defaultSerializerSchemaNamespace));
        }
Exemple #5
0
        private void VerifyFindDerivedType(IEnumerable <XElement> sourceCsdls, IEdmModel testModel)
        {
            Func <IEdmStructuredType, string> getFullName = (type) =>
            {
                return(type as IEdmComplexType != null ? ((IEdmComplexType)type).FullName() : type as IEdmEntityType != null ? ((IEdmEntityType)type).FullName() : null);
            };

            Func <IEdmStructuredType, string> getNamespace = (type) =>
            {
                return(type as IEdmComplexType != null ? ((IEdmComplexType)type).Namespace : type as IEdmEntityType != null ? ((IEdmEntityType)type).Namespace : null);
            };

            Action <IEdmStructuredType, string> checkFindAllDerivedFunction = (structuredType, structuralTypeElementName) =>
            {
                var expectedResults = EdmLibCsdlContentGenerator.GetDerivedTypes(sourceCsdls, structuralTypeElementName, getFullName(structuredType));
                var actualResults   = testModel.FindAllDerivedTypes(structuredType).Select(n => getFullName(n));
                Assert.IsTrue(expectedResults.Count() == actualResults.Count() && !expectedResults.Except(actualResults).Any(),
                              "FindAllDerivedTypes returns unexpected results.");
            };

            Action <IEdmStructuredType, string> checkFindDirectlyDerivedFunction = (structuredType, structuralTypeElementName) =>
            {
                var expectedResults = EdmLibCsdlContentGenerator.GetDirectlyDerivedTypes(sourceCsdls, structuralTypeElementName, getFullName(structuredType));
                var actualResults   = testModel.FindDirectlyDerivedTypes(structuredType).Select(n => getFullName(n));

                Assert.IsTrue(expectedResults.Count() == actualResults.Count() && !expectedResults.Except(actualResults).Any(),
                              "FindDirectlyDerivedTypes returns unexpected results.");
            };

            IEnumerable <EdmError> edmErrors;

            testModel.Validate(out edmErrors);

            var structuredTypes = testModel.SchemaElements.OfType <IEdmStructuredType>();

            foreach (var structuredType in structuredTypes)
            {
                if (edmErrors.Any(n => n.ErrorCode == EdmErrorCode.BadCyclicEntity && n.ErrorMessage.Contains(getFullName(structuredType))))
                {
                    Assert.IsTrue(0 == testModel.FindDirectlyDerivedTypes(structuredType).Count(), "FindDirectlyDerivedTypes returns unexpected results.");
                    Assert.IsTrue(0 == testModel.FindAllDerivedTypes(structuredType).Count(), "FindAllDerivedTypes returns unexpected results.");
                }
                else
                {
                    if (structuredType is IEdmEntityType)
                    {
                        checkFindDirectlyDerivedFunction(structuredType, "EntityType");
                        checkFindAllDerivedFunction(structuredType, "EntityType");
                    }
                    else if (structuredType is IEdmComplexType)
                    {
                        checkFindDirectlyDerivedFunction(structuredType, "ComplexType");
                        checkFindAllDerivedFunction(structuredType, "ComplexType");
                    }
                }
            }
        }
Exemple #6
0
        protected void VerifyFindEntityContainerElement(XElement sourceCsdl, IEdmModel testModel)
        {
            var csdlNamespace = EdmLibCsdlContentGenerator.GetCsdlFullNamespace(this.EdmVersion);

            Assert.AreEqual(csdlNamespace, sourceCsdl.Name.Namespace, "The source CSDL's namespace should match the target EDM version of the test cases.");

            Console.WriteLine("Test CSDL:\n\r{0}", sourceCsdl.ToString());

            var entityContainers = from element in sourceCsdl.DescendantsAndSelf(XName.Get("EntityContainer", csdlNamespace.NamespaceName))
                                   select element;

            IEnumerable <string> entityContainerElementTypes = new string[] { "EntitySet", "FunctionImport" };

            foreach (var entityContainer in entityContainers)
            {
                var entityContainerElements = from element in entityContainer.Descendants()
                                              where entityContainerElementTypes.Select(n => XName.Get(n, csdlNamespace.NamespaceName)).Any(m => m == element.Name)
                                              select element;
                var entityContainerName = entityContainer.Attribute("Name").Value;
                var entityContainerObj  = testModel.FindEntityContainer(entityContainerName) as IEdmEntityContainer;

                foreach (var entityContainerElement in entityContainerElements)
                {
                    var entityContainerElementName = entityContainerElement.Attribute("Name").Value;
                    var entitySetFound             = entityContainerObj.FindEntitySet(entityContainerElementName);
                    var functionImportsFound       = entityContainerObj.FindOperationImports(entityContainerElementName);

                    IEdmEntityContainerElement entityContainerElementFound = null;
                    var elementsWithSameName = entityContainerElements.Where(n => n.Attribute("Name").Value.Equals(entityContainerElementName)).Count();

                    if (functionImportsFound != null && functionImportsFound.Count() == elementsWithSameName)
                    {
                        entityContainerElementFound = functionImportsFound.First();
                    }
                    else if (entitySetFound != null)
                    {
                        entityContainerElementFound = entitySetFound;
                    }

                    Assert.IsNotNull(entityContainerElementFound, "FindElement failed for {0}.{1}", entityContainerName, entityContainerElementName);
                    Assert.AreEqual
                    (
                        entityContainerElementName,
                        entityContainerElementFound.Name,
                        "FindElement returned a wrong result, {0}, for {1}", entityContainerElementFound.Name, entityContainerElementName
                    );
                    Assert.IsTrue
                    (
                        entityContainerElement.Name.LocalName == "EntitySet" || entityContainerElement.Name.LocalName == "FunctionImport",
                        "FoundElement for {0} returns a wrong element kind", entityContainerName
                    );
                }
            }
        }
Exemple #7
0
        protected void VerifyFindSchemaElementMethod(XElement sourceCsdl, IEdmModel testModel)
        {
            var csdlNamespace = EdmLibCsdlContentGenerator.GetCsdlFullNamespace(this.EdmVersion);

            Assert.AreEqual(csdlNamespace, sourceCsdl.Name.Namespace, "The source CSDL's namespace should match the target EDM version of the test cases.");

            IEnumerable <string> schemaElementTypes = new string[] { "EntityType", "ComplexType", "Function", "Term" };

            // TODO: Function should be filtered based on the CSDL version; It is supported from CSDL 2.0.
            // TODO: What is the expected behavior of the parser when a CSDL of 1.0 has Functions.
            var namespaceValue = sourceCsdl.Attribute("Namespace").Value;

            foreach (var schemaElementType in schemaElementTypes)
            {
                var schemaElements = from element in sourceCsdl.Elements(XName.Get(schemaElementType, csdlNamespace.NamespaceName))
                                     select element;
                Console.WriteLine("Test CSDL:\n\r{0}", sourceCsdl.ToString());

                foreach (var schemaElement in schemaElements)
                {
                    var elementNameExpected = string.Format("{0}.{1}", namespaceValue, schemaElement.Attribute("Name").Value);
                    Console.WriteLine("FindSchemaType for {0}", elementNameExpected);

                    var typeFound = testModel.FindType(elementNameExpected);
                    Assert.AreEqual(typeFound, testModel.FindDeclaredType(elementNameExpected), "The results between FindMethod and its declared version should be same.");

                    var operationGroup = testModel.FindOperations(elementNameExpected);
                    Assert.IsTrue(operationGroup.Count() == testModel.FindDeclaredOperations(elementNameExpected).Count() && !operationGroup.Except(testModel.FindDeclaredOperations(elementNameExpected)).Any(), "The results between FindMethod and its declared version should be same.");

                    var valueTermFound = testModel.FindValueTerm(elementNameExpected);
                    Assert.AreEqual(valueTermFound, testModel.FindDeclaredValueTerm(elementNameExpected), "The results between FindMethod and its declared version should be same.");

                    Assert.IsFalse((typeFound == null) && (operationGroup == null) && (valueTermFound == null), "Failed to FindSchemaType for {0}", elementNameExpected);

                    IEdmSchemaElement schemaElementFound = null;
                    if (operationGroup.Count() > 0)
                    {
                        schemaElementFound = (IEdmSchemaElement)operationGroup.First();
                    }
                    else if (typeFound != null)
                    {
                        schemaElementFound = typeFound;
                    }
                    else if (valueTermFound != null)
                    {
                        schemaElementFound = valueTermFound;
                    }

                    Assert.IsTrue(elementNameExpected.Equals(schemaElementFound.FullName(), System.StringComparison.Ordinal), "The found result {0} is different from {1}", schemaElementFound.FullName(), elementNameExpected);
                }
            }
        }
Exemple #8
0
        protected void VerifyFindEntityContainer(XElement sourceCsdl, IEdmModel testModel)
        {
            var csdlNamespace = EdmLibCsdlContentGenerator.GetCsdlFullNamespace(this.EdmVersion);

            Assert.AreEqual(csdlNamespace, sourceCsdl.Name.Namespace, "The source CSDL's namespace should match the target EDM version of the test cases.");

            var entityContainerNames = from element in sourceCsdl.Elements(XName.Get("EntityContainer", csdlNamespace.NamespaceName))
                                       select element.Attribute("Name").Value;

            Console.WriteLine("Test CSDL:\n\r{0}", sourceCsdl.ToString());

            foreach (var entityContainerName in entityContainerNames)
            {
                Console.WriteLine("FindEntityContainer for {0}", entityContainerName);

                var elementFound = testModel.FindEntityContainer(entityContainerName);

                Assert.AreEqual(elementFound, testModel.EntityContainer, "The results between FindMethod and its declared version should be same.");
                Assert.IsNotNull(elementFound, "Failed to FindEntityContainer for {0}", entityContainerName);
                Assert.IsTrue(entityContainerName.Equals(elementFound.Name, System.StringComparison.Ordinal),
                              "The found result {0} is different from {1}", elementFound.Name, entityContainerName);
            }
        }
Exemple #9
0
        public void SerializerTestEnumMemberReferenceExpression()
        {
            var expectedCsdlElements        = VocabularyTestModelBuilder.OutOfLineAnnotationNavigationProperty();
            IEnumerable <EdmError> edmError = null;
            var actualCsdlElements          = this.GetSerializerResult(this.GetParserResult(expectedCsdlElements), EdmLibCsdlContentGenerator.GetEdmVersion(expectedCsdlElements.First().Name.Namespace), out edmError).Select(n => XElement.Parse(n));

            Assert.IsTrue(!edmError.Any(), "Unexpected serializer errors.");
            new SerializerResultVerifierUsingXml().Verify(expectedCsdlElements, actualCsdlElements);
        }
        private IEnumerable <string> GetXsdValidationResults(XElement csdlElement, EdmVersion edmVersion)
        {
            var csdlEdmVersionUpdated = XElement.Parse(csdlElement.ToString().Replace(csdlElement.Name.NamespaceName, EdmLibCsdlContentGenerator.GetCsdlFullNamespace(edmVersion).NamespaceName));
            var errorMessages         = new List <string>();

            InitializeEdmLibCsdlSchemas();
            new XDocument(csdlEdmVersionUpdated).Validate(EdmLibXmlSchemas[edmVersion], (o, e) => { errorMessages.Add(e.Message); });
            return(errorMessages);
        }
        private void BasicXsdValidationTestForParserInputCsdl(IEnumerable <XElement> csdls, EdmVersion edmVersion)
        {
            IEdmModel edmModel;
            IEnumerable <EdmError> parserErrors;
            var csdlsEdmVersionUpdated = csdls.Select(n => XElement.Parse(n.ToString().Replace(n.Name.NamespaceName, EdmLibCsdlContentGenerator.GetCsdlFullNamespace(edmVersion).NamespaceName)));

            var isParsed = CsdlReader.TryParse(csdlsEdmVersionUpdated.Select(e => e.CreateReader()), out edmModel, out parserErrors);

            if (!isParsed)
            {
                // XSD verification is a sufficent condition, but not a necessary condition of EDMLib parser.
                Assert.IsTrue(this.GetXsdValidationResults(csdlsEdmVersionUpdated, edmVersion).Count() > 0, "It should be invalid for the CSDL {0} XSDs", edmVersion);
            }
            else
            {
                IEnumerable <EdmError> validationErrors;
                edmModel.Validate(toProductVersionlookup[edmVersion], out validationErrors);
                var xsdValidationErrors = new List <string>();

                xsdValidationErrors.AddRange(this.GetXsdValidationResults(csdlsEdmVersionUpdated, edmVersion));

                if (!validationErrors.Any() && xsdValidationErrors.Any())
                {
                    Assert.Fail("XSD validation must succeed when there is no semantic validation error.");
                }
                else if (validationErrors.Any() && !xsdValidationErrors.Any())
                {
                    foreach (var validationError in validationErrors)
                    {
                        Console.WriteLine("The test data has no XSD error, but it has a validation error : {0}", validationError.ErrorMessage);
                    }
                }
            }
        }