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.FindTerm("NS1.Title")); model.RemoveElement(model.FindEntityType("NS1.Person")); model.WrappedModel.AddReferencedModel(vocabulary); var vterm = vocabulary.FindTerm("NS1.Title"); var tterm = vocabulary.FindEntityType("NS1.Person"); var customer = model.FindEntityType("NS1.Customer"); var vannotation = new EdmVocabularyAnnotation( 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.TryWriteSchema(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 ConstructibleModelRemoveElementDependencyBasicTest() { var model = new FunctionalUtilities.ModelWithRemovableElements<EdmModel>(this.GetStockModel(ModelBuilder.SimpleConstructiveApiTestModel())); var customer = (EdmEntityType)model.FindType("Westwind.Customer"); var entityTypeCount = model.SchemaElements.OfType<EdmEntityType>().Count(); Assert.IsTrue(entityTypeCount > 0, "The test model should have at least one entity type"); var entitySetCount = model.EntityContainer.Elements.OfType<EdmEntitySet>().Count(); IEnumerable<EdmError> errors; model.Validate(out errors); Assert.AreEqual(0, errors.Count(), "Model should pass validation."); model.RemoveElement(customer); Assert.AreEqual(model.SchemaElements.OfType<EdmEntityType>().Count(), entityTypeCount - 1, "The number of entity types should be decreased."); model.Validate(out errors); Assert.AreEqual(2, errors.Count(), "Model should now fail validation."); }
public void ConstructibleModelRemoveElementDependencyBasicTest() { var model = new FunctionalUtilities.ModelWithRemovableElements <EdmModel>(this.GetStockModel(ModelBuilder.SimpleConstructiveApiTestModel())); var customer = (EdmEntityType)model.FindType("Westwind.Customer"); var entityTypeCount = model.SchemaElements.OfType <EdmEntityType>().Count(); Assert.IsTrue(entityTypeCount > 0, "The test model should have at least one entity type"); var entitySetCount = model.EntityContainer.Elements.OfType <EdmEntitySet>().Count(); IEnumerable <EdmError> errors; model.Validate(out errors); Assert.AreEqual(0, errors.Count(), "Model should pass validation."); model.RemoveElement(customer); Assert.AreEqual(model.SchemaElements.OfType <EdmEntityType>().Count(), entityTypeCount - 1, "The number of entity types should be decreased."); model.Validate(out errors); Assert.AreEqual(2, errors.Count(), "Model should now fail validation."); }
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 TestAnnotationsWithModelReferencesAnnotationsInTheVocabulary() { var vocabulary = new FunctionalUtilities.ModelWithRemovableElements<EdmModel>(CreateModel()); vocabulary.RemoveElement(vocabulary.EntityContainer); vocabulary.RemoveElement(vocabulary.FindEntityType("NS1.Customer")); var model = new FunctionalUtilities.ModelWithRemovableElements<EdmModel>(CreateModel()); model.RemoveElement(model.FindValueTerm("NS1.Title")); model.RemoveElement(model.FindEntityType("NS1.Person")); vocabulary.WrappedModel.AddReferencedModel(model); model.WrappedModel.AddReferencedModel(vocabulary); IEnumerable<EdmError> errors; Assert.IsTrue(model.Validate(out errors), "validate model"); 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!")); vocabulary.WrappedModel.AddVocabularyAnnotation( vannotation); Assert.AreEqual(0, model.VocabularyAnnotations.Count(), "model.VocabularyAnnotations.Count()"); Assert.AreEqual(1, vocabulary.VocabularyAnnotations.Count(), "model.VocabularyAnnotations.Count()"); var annotations = customer.VocabularyAnnotations(model).ToList(); Assert.AreEqual(1, annotations.Count, "annotations.Count"); Assert.IsTrue(annotations.Contains(vannotation), "annotations.Contains(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> </Schema>", sw.ToString(), "model.WriteCsdl(w)"); sw = new StringWriter(); w = XmlWriter.Create(sw, new XmlWriterSettings() { Indent = true }); vocabulary.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""> <Term Name=""Title"" Type=""Edm.String"" /> <EntityType Name=""Person""> <Key> <PropertyRef Name=""ID"" /> </Key> <Property Name=""ID"" Type=""Edm.String"" Nullable=""false"" /> </EntityType> <Annotations Target=""NS1.Customer""> <Annotation Term=""NS1.Title"" Qualifier=""q1"" String=""Hello world!"" /> </Annotations> </Schema>", sw.ToString(), "vocabulary.WriteCsdl(w)"); }