public void AmbiguousEntitySetTest() { EdmEntityContainer container = new EdmEntityContainer("NS1", "Baz"); IEdmEntitySet set1 = new StubEdmEntitySet("Foo", container); IEdmEntitySet set2 = new StubEdmEntitySet("Foo", container); IEdmEntitySet set3 = new StubEdmEntitySet("Foo", container); container.AddElement(set1); Assert.AreNotEqual(set3, container.FindEntitySet("Foo"), "Checking the object equality."); Assert.AreEqual(set3.Name, container.FindEntitySet("Foo").Name, "Checking the object equality."); container.AddElement(set2); container.AddElement(set3); IEdmEntitySet ambiguous = container.FindEntitySet("Foo"); Assert.IsTrue(ambiguous.IsBad(), "Ambiguous binding is bad"); Assert.AreEqual(EdmContainerElementKind.EntitySet, ambiguous.ContainerElementKind, "Correct container element kind"); Assert.AreEqual("NS1.Baz", ambiguous.Container.FullName(), "Correct container name"); Assert.AreEqual("Foo", ambiguous.Name, "Correct Name"); Assert.IsTrue(ambiguous.EntityType().IsBad(), "Association is bad."); }
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"); }