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 ConstructibleVocabularyAddingValueAnnotationAndDeleteTargetedElement() { var model = new FunctionalUtilities.ModelWithRemovableElements<EdmModel>(VocabularyTestModelBuilder.InlineAnnotationSimpleModel()); var vocabularyAnnotations = model.VocabularyAnnotations; Assert.AreEqual(1, vocabularyAnnotations.Count(), "Invalid vocabulary annotation count."); var container = model.FindEntityContainer("Container") as EdmEntityContainer; Assert.IsNotNull(container, "Invalid entity container name."); var stringTerm = model.FindValueTerm("AnnotationNamespace.StringTerm") as EdmTerm; Assert.IsNotNull(stringTerm, "Invalid value term."); EdmAnnotation valueAnnotation = new EdmAnnotation( container, stringTerm, new EdmStringConstant("foo")); valueAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline); model.WrappedModel.AddVocabularyAnnotation(valueAnnotation); Assert.AreEqual(2, vocabularyAnnotations.Count(), "Invalid vocabulary annotation count."); var valueAnnotationFound = this.CheckForValueAnnotation(vocabularyAnnotations, EdmExpressionKind.StringConstant, new List<PropertyValue> { new PropertyValue("foo") }); Assert.IsTrue(valueAnnotationFound, "Annotation can't be found."); var containerVocabularyAnnotations = container.VocabularyAnnotations(model); valueAnnotationFound = this.CheckForValueAnnotation(containerVocabularyAnnotations, EdmExpressionKind.StringConstant, new List<PropertyValue> { new PropertyValue("foo") }); Assert.IsTrue(valueAnnotationFound, "Annotation can't be found."); model.RemoveElement(container); model.FindDeclaredVocabularyAnnotations(container).ToList().ForEach(a => model.RemoveVocabularyAnnotation(a)); Assert.AreEqual(1, vocabularyAnnotations.Count(), "Invalid vocabulary annotation count."); }
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)"); }