Exemplo n.º 1
0
        private void ValidateElement(IEdmElement element, IEnumerable <EdmError> expectedErrors)
        {
            if (expectedErrors.Count() > 0)
            {
                Assert.IsTrue(element.IsBad(), "Element is expected to be bad.");
            }
            else
            {
                Assert.IsFalse(element.IsBad(), "Element is not expected to be bad.");
            }

            var actualErrors = element.Errors();

            this.CompareErrors(actualErrors, expectedErrors);
        }
Exemplo n.º 2
0
        public void UnresolvedAnnotationTargetsTest()
        {
            string csdl = @"
<Schema Namespace=""DefaultNamespace"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
    <Term Name=""Term"" Type=""Edm.Int32"" />
    <EntityType Name=""Entity"" >
        <Key>
            <PropertyRef Name=""ID"" />
        </Key>
        <Property Name=""ID"" Type=""Edm.Int32"" Nullable=""False"" />
    </EntityType>
    <Function Name=""Function"">
        <Parameter Name=""Parameter"" Type=""Edm.String"" />
        <ReturnType Type=""Edm.Int32"" />
    </Function>
    <EntityContainer Name=""Container"">
        <FunctionImport Name=""FunctionImport"" Function=""DefaultNamespace.Function"" />
    </EntityContainer>
    <Annotations Target=""DefaultNamespace.Container/BadEntitySet"">
        <Annotation Term=""AnnotationNamespace.Term"">
            <Int>42</Int>
        </Annotation>
    </Annotations>
    <Annotations Target=""DefaultNamespace.Entity/BadProperty"">
        <Annotation Term=""AnnotationNamespace.Term"">
            <Int>42</Int>
        </Annotation>
    </Annotations>
    <Annotations Target=""DefaultNamespace.Function(Edm.String)/BadParameter"">
        <Annotation Term=""AnnotationNamespace.Annotation"">
            <Int>42</Int>
        </Annotation>
    </Annotations>
    <Annotations Target=""DefaultNamespace.BadEntity/BadProperty"">
        <Annotation Term=""AnnotationNamespace.Term"">
            <Int>42</Int>
        </Annotation>
    </Annotations>
    <Annotations Target=""Impossible/Target/With/Too/Long/A/Path"">
        <Annotation Term=""AnnotationNamespace.Term"">
            <Int>42</Int>
        </Annotation>
    </Annotations>
</Schema>";

            IEdmModel model;
            IEnumerable <EdmError> errors;
            bool parsed = SchemaReader.TryParse(new XmlReader[] { XmlReader.Create(new StringReader(csdl)) }, out model, out errors);

            Assert.IsTrue(parsed, "parsed");
            Assert.IsTrue(errors.Count() == 0, "No errors");

            Assert.AreEqual(5, model.VocabularyAnnotations.Count(), "Correct number of annotations");
            IEdmEntitySet          badEntitySet           = model.VocabularyAnnotations.ElementAt(0).Target as IEdmEntitySet;
            IEdmStructuralProperty badProperty            = model.VocabularyAnnotations.ElementAt(1).Target as IEdmStructuralProperty;
            IEdmOperationParameter badOperationParameter  = model.VocabularyAnnotations.ElementAt(2).Target as IEdmOperationParameter;
            IEdmStructuralProperty badPropertyWithBadType = model.VocabularyAnnotations.ElementAt(3).Target as IEdmStructuralProperty;
            IEdmElement            badElement             = model.VocabularyAnnotations.ElementAt(4).Target as IEdmElement;

            Assert.IsNotNull(badEntitySet, "Target not null");
            Assert.IsNotNull(badProperty, "Target not null");
            Assert.IsNotNull(badOperationParameter, "Target not null");
            Assert.IsNotNull(badPropertyWithBadType, "Target not null");
            Assert.IsNotNull(badElement, "Target not null");

            Assert.IsTrue(badEntitySet.IsBad(), "Target is bad");
            Assert.IsTrue(badProperty.IsBad(), "Target is bad");
            Assert.AreEqual("BadUnresolvedProperty:BadProperty:[UnknownType Nullable=True]", badProperty.ToString(), "Correct bad property to string");
            Assert.AreEqual("BadUnresolvedProperty:[UnknownType Nullable=True]", badProperty.Type.ToString(), "Correct bad property to string");
            Assert.IsTrue(badOperationParameter.IsBad(), "Target is bad");
            Assert.IsTrue(badPropertyWithBadType.IsBad(), "Target is bad");
            Assert.IsTrue(badElement.IsBad(), "Target is bad");
        }
Exemplo n.º 3
0
        private void ValidateElement(IEdmElement element, IEnumerable<EdmError> expectedErrors)
        {
            if (expectedErrors.Count() > 0)
            {
                Assert.IsTrue(element.IsBad(), "Element is expected to be bad.");
            }
            else
            {
                Assert.IsFalse(element.IsBad(), "Element is not expected to be bad.");
            }

            var actualErrors = element.Errors();
            this.CompareErrors(actualErrors, expectedErrors);
        }