public void TestAnnotationsWithModelReferencesAnnotationsInTheModel() { var vocabulary = new FunctionalUtilities.ModelWithRemovableElements <EdmModel>(CreateModel()); vocabulary.RemoveElement(vocabulary.EntityContainer); vocabulary.RemoveElement(vocabulary.FindEntityType("NS1.Customer")); IEnumerable <EdmError> errors; Assert.IsTrue(vocabulary.Validate(out errors), "validate vocabulary"); var model = new FunctionalUtilities.ModelWithRemovableElements <EdmModel>(CreateModel()); model.RemoveElement(model.FindValueTerm("NS1.Title")); model.RemoveElement(model.FindEntityType("NS1.Person")); model.WrappedModel.AddReferencedModel(vocabulary); var vterm = vocabulary.FindValueTerm("NS1.Title"); var tterm = vocabulary.FindEntityType("NS1.Person"); var customer = model.FindEntityType("NS1.Customer"); var vannotation = new EdmAnnotation( customer, vterm, "q1", new EdmStringConstant("Hello world!")); model.WrappedModel.AddVocabularyAnnotation(vannotation); var sw = new StringWriter(); var w = XmlWriter.Create(sw, new XmlWriterSettings() { Indent = true }); model.TryWriteCsdl(w, out errors); w.Close(); Assert.AreEqual( @"<?xml version=""1.0"" encoding=""utf-16""?> <Schema Namespace=""NS1"" xmlns=""http://docs.oasis-open.org/odata/ns/edm""> <EntityType Name=""Customer""> <Key> <PropertyRef Name=""CustomerID"" /> </Key> <Property Name=""CustomerID"" Type=""Edm.String"" Nullable=""false"" /> </EntityType> <EntityContainer Name=""Container""> <EntitySet Name=""Customers"" EntityType=""NS1.Customer"" /> </EntityContainer> <Annotations Target=""NS1.Customer""> <Annotation Term=""NS1.Title"" Qualifier=""q1"" String=""Hello world!"" /> </Annotations> </Schema>", sw.ToString(), "model.WriteCsdl(w)"); }
public void CreateSimpleValueTermAnnotation() { var model = new FunctionalUtilities.ModelWithRemovableElements <EdmModel>(CreateModel()); var term = model.FindValueTerm("NS1.Title"); var customer = model.FindEntityType("NS1.Customer"); var annotation = new EdmAnnotation( customer, term, "q1", new EdmStringConstant("Hello world!")); model.WrappedModel.AddVocabularyAnnotation(annotation); var annotation2 = new EdmAnnotation( customer, term, "q2", new EdmStringConstant("Hello world2!")); model.WrappedModel.AddVocabularyAnnotation(annotation2); var annotations = customer.VocabularyAnnotations(model).ToList(); Assert.AreEqual(2, annotations.Count, "customer.VocabularyAnnotations(model).Count"); Assert.IsTrue(annotations.Contains(annotation), "annotations.Contains(annotation)"); Assert.IsTrue(annotations.Contains(annotation2), "annotations.Contains(annotation)"); IEnumerable <EdmError> errors; Assert.IsTrue(model.Validate(out errors), "validate"); var sw = new StringWriter(); var w = XmlWriter.Create(sw, new XmlWriterSettings() { Indent = true }); model.TryWriteCsdl(w, out errors); w.Close(); Assert.AreEqual( @"<?xml version=""1.0"" encoding=""utf-16""?> <Schema Namespace=""NS1"" xmlns=""http://docs.oasis-open.org/odata/ns/edm""> <EntityType Name=""Customer""> <Key> <PropertyRef Name=""CustomerID"" /> </Key> <Property Name=""CustomerID"" Type=""Edm.String"" Nullable=""false"" /> </EntityType> <Term Name=""Title"" Type=""Edm.String"" /> <EntityType Name=""Person""> <Key> <PropertyRef Name=""ID"" /> </Key> <Property Name=""ID"" Type=""Edm.String"" Nullable=""false"" /> </EntityType> <EntityContainer Name=""Container""> <EntitySet Name=""Customers"" EntityType=""NS1.Customer"" /> </EntityContainer> <Annotations Target=""NS1.Customer""> <Annotation Term=""NS1.Title"" Qualifier=""q1"" String=""Hello world!"" /> <Annotation Term=""NS1.Title"" Qualifier=""q2"" String=""Hello world2!"" /> </Annotations> </Schema>", sw.ToString(), "model.WriteCsdl(w)"); model.RemoveVocabularyAnnotation(annotation); Assert.IsTrue(model.Validate(out errors), "validate2"); sw = new StringWriter(); w = XmlWriter.Create(sw, new XmlWriterSettings() { Indent = true }); model.TryWriteCsdl(w, out errors); w.Close(); Assert.AreEqual( @"<?xml version=""1.0"" encoding=""utf-16""?> <Schema Namespace=""NS1"" xmlns=""http://docs.oasis-open.org/odata/ns/edm""> <EntityType Name=""Customer""> <Key> <PropertyRef Name=""CustomerID"" /> </Key> <Property Name=""CustomerID"" Type=""Edm.String"" Nullable=""false"" /> </EntityType> <Term Name=""Title"" Type=""Edm.String"" /> <EntityType Name=""Person""> <Key> <PropertyRef Name=""ID"" /> </Key> <Property Name=""ID"" Type=""Edm.String"" Nullable=""false"" /> </EntityType> <EntityContainer Name=""Container""> <EntitySet Name=""Customers"" EntityType=""NS1.Customer"" /> </EntityContainer> <Annotations Target=""NS1.Customer""> <Annotation Term=""NS1.Title"" Qualifier=""q2"" String=""Hello world2!"" /> </Annotations> </Schema>", sw.ToString(), "model.WriteCsdl(w) 2"); }
public void CreateSimpleValueTermAnnotation() { var model = new FunctionalUtilities.ModelWithRemovableElements<EdmModel>(CreateModel()); var term = model.FindValueTerm("NS1.Title"); var customer = model.FindEntityType("NS1.Customer"); var annotation = new EdmAnnotation( customer, term, "q1", new EdmStringConstant("Hello world!")); model.WrappedModel.AddVocabularyAnnotation(annotation); var annotation2 = new EdmAnnotation( customer, term, "q2", new EdmStringConstant("Hello world2!")); model.WrappedModel.AddVocabularyAnnotation(annotation2); var annotations = customer.VocabularyAnnotations(model).ToList(); Assert.AreEqual(2, annotations.Count, "customer.VocabularyAnnotations(model).Count"); Assert.IsTrue(annotations.Contains(annotation), "annotations.Contains(annotation)"); Assert.IsTrue(annotations.Contains(annotation2), "annotations.Contains(annotation)"); IEnumerable<EdmError> errors; Assert.IsTrue(model.Validate(out errors), "validate"); var sw = new StringWriter(); var w = XmlWriter.Create(sw, new XmlWriterSettings() { Indent = true }); model.TryWriteCsdl(w, out errors); w.Close(); Assert.AreEqual( @"<?xml version=""1.0"" encoding=""utf-16""?> <Schema Namespace=""NS1"" xmlns=""http://docs.oasis-open.org/odata/ns/edm""> <EntityType Name=""Customer""> <Key> <PropertyRef Name=""CustomerID"" /> </Key> <Property Name=""CustomerID"" Type=""Edm.String"" Nullable=""false"" /> </EntityType> <Term Name=""Title"" Type=""Edm.String"" /> <EntityType Name=""Person""> <Key> <PropertyRef Name=""ID"" /> </Key> <Property Name=""ID"" Type=""Edm.String"" Nullable=""false"" /> </EntityType> <EntityContainer Name=""Container""> <EntitySet Name=""Customers"" EntityType=""NS1.Customer"" /> </EntityContainer> <Annotations Target=""NS1.Customer""> <Annotation Term=""NS1.Title"" Qualifier=""q1"" String=""Hello world!"" /> <Annotation Term=""NS1.Title"" Qualifier=""q2"" String=""Hello world2!"" /> </Annotations> </Schema>", sw.ToString(), "model.WriteCsdl(w)"); model.RemoveVocabularyAnnotation(annotation); Assert.IsTrue(model.Validate(out errors), "validate2"); sw = new StringWriter(); w = XmlWriter.Create(sw, new XmlWriterSettings() { Indent = true }); model.TryWriteCsdl(w, out errors); w.Close(); Assert.AreEqual( @"<?xml version=""1.0"" encoding=""utf-16""?> <Schema Namespace=""NS1"" xmlns=""http://docs.oasis-open.org/odata/ns/edm""> <EntityType Name=""Customer""> <Key> <PropertyRef Name=""CustomerID"" /> </Key> <Property Name=""CustomerID"" Type=""Edm.String"" Nullable=""false"" /> </EntityType> <Term Name=""Title"" Type=""Edm.String"" /> <EntityType Name=""Person""> <Key> <PropertyRef Name=""ID"" /> </Key> <Property Name=""ID"" Type=""Edm.String"" Nullable=""false"" /> </EntityType> <EntityContainer Name=""Container""> <EntitySet Name=""Customers"" EntityType=""NS1.Customer"" /> </EntityContainer> <Annotations Target=""NS1.Customer""> <Annotation Term=""NS1.Title"" Qualifier=""q2"" String=""Hello world2!"" /> </Annotations> </Schema>", sw.ToString(), "model.WriteCsdl(w) 2"); }
public void TestAnnotationsWithModelReferencesAnnotationsInTheModel() { var vocabulary = new FunctionalUtilities.ModelWithRemovableElements<EdmModel>(CreateModel()); vocabulary.RemoveElement(vocabulary.EntityContainer); vocabulary.RemoveElement(vocabulary.FindEntityType("NS1.Customer")); IEnumerable<EdmError> errors; Assert.IsTrue(vocabulary.Validate(out errors), "validate vocabulary"); var model = new FunctionalUtilities.ModelWithRemovableElements<EdmModel>(CreateModel()); model.RemoveElement(model.FindValueTerm("NS1.Title")); model.RemoveElement(model.FindEntityType("NS1.Person")); model.WrappedModel.AddReferencedModel(vocabulary); var vterm = vocabulary.FindValueTerm("NS1.Title"); var tterm = vocabulary.FindEntityType("NS1.Person"); var customer = model.FindEntityType("NS1.Customer"); var vannotation = new EdmAnnotation( customer, vterm, "q1", new EdmStringConstant("Hello world!")); model.WrappedModel.AddVocabularyAnnotation(vannotation); var sw = new StringWriter(); var w = XmlWriter.Create(sw, new XmlWriterSettings() { Indent = true }); model.TryWriteCsdl(w, out errors); w.Close(); Assert.AreEqual( @"<?xml version=""1.0"" encoding=""utf-16""?> <Schema Namespace=""NS1"" xmlns=""http://docs.oasis-open.org/odata/ns/edm""> <EntityType Name=""Customer""> <Key> <PropertyRef Name=""CustomerID"" /> </Key> <Property Name=""CustomerID"" Type=""Edm.String"" Nullable=""false"" /> </EntityType> <EntityContainer Name=""Container""> <EntitySet Name=""Customers"" EntityType=""NS1.Customer"" /> </EntityContainer> <Annotations Target=""NS1.Customer""> <Annotation Term=""NS1.Title"" Qualifier=""q1"" String=""Hello world!"" /> </Annotations> </Schema>", sw.ToString(), "model.WriteCsdl(w)"); }