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.");
        }
示例#3
0
        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 ReferencedModelDuplicateTypeValidationTest()
        {
            var mainModel = new FunctionalUtilities.ModelWithRemovableElements<EdmModel>(ValidationTestModelBuilder.ReferenceBasicTestMainModel() as EdmModel);
            var referencedModel = ValidationTestModelBuilder.ReferenceBasicTestReferencedModel();

            var regionType = new EdmComplexType("NS1", "Region");
            regionType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(false));
            mainModel.WrappedModel.AddElement(regionType);

            var expectedErrors = new EdmLibTestErrors();
            IEnumerable<EdmError> edmErrors;
            mainModel.Validate(out edmErrors);
            this.CompareErrors(edmErrors, expectedErrors);

            mainModel.WrappedModel.AddReferencedModel(referencedModel);
            expectedErrors = new EdmLibTestErrors()
            {
                { null, null, EdmErrorCode.AlreadyDefined },
            };
            mainModel.Validate(out edmErrors);
            this.CompareErrors(edmErrors, expectedErrors);

            mainModel.RemoveReference(referencedModel);
            expectedErrors = null;
            mainModel.Validate(out edmErrors);
            this.CompareErrors(edmErrors, expectedErrors);
        }
        public void ReferencedModelDuplicatePropertyValidationTest()
        {
            var mainModel = new FunctionalUtilities.ModelWithRemovableElements<EdmModel>(ValidationTestModelBuilder.ReferenceBasicTestMainModel() as EdmModel);
            var referencedModel = ValidationTestModelBuilder.ReferenceBasicTestReferencedModel();

            var partnerType = new EdmEntityType("NS1", "Partner", referencedModel.FindEntityType("NS1.Person"), false, true);
            var partnerId = partnerType.AddStructuralProperty("ID2", EdmCoreModel.Instance.GetString(false));
            EdmEntityType regionType = new EdmEntityType("NS1", "Region", null, false, true);
            var regionId = regionType.AddStructuralProperty("ID", EdmCoreModel.Instance.GetString(false));
            regionType.AddKeys(regionId);
            mainModel.WrappedModel.AddElement(partnerType);
            mainModel.WrappedModel.AddElement(regionType);

            var expectedErrors = new EdmLibTestErrors()
            {
                { null, null, EdmErrorCode.BadUnresolvedType },
            };
            IEnumerable<EdmError> edmErrors;
            mainModel.Validate(out edmErrors);
            this.CompareErrors(edmErrors, expectedErrors);

            mainModel.WrappedModel.AddReferencedModel(referencedModel);
            expectedErrors = new EdmLibTestErrors()
            {
                { null, null, EdmErrorCode.AlreadyDefined },
            };
            mainModel.Validate(out edmErrors);
            this.CompareErrors(edmErrors, expectedErrors);

            mainModel.RemoveReference(referencedModel);
            expectedErrors = new EdmLibTestErrors()
            {
                { null, null, EdmErrorCode.BadUnresolvedType },
            };
            mainModel.Validate(out edmErrors);
            this.CompareErrors(edmErrors, expectedErrors);
        }
        public void ReferencedModelUnresolvedTermValidationTest()
        {
            var mainModel = new FunctionalUtilities.ModelWithRemovableElements<EdmModel>(ValidationTestModelBuilder.ReferenceBasicTestMainModel() as EdmModel);
            var referencedModel = ValidationTestModelBuilder.ReferenceBasicTestReferencedModel();

            var valueAnnotation = new EdmAnnotation(
                mainModel.FindEntityType("NS1.Customer"),
                referencedModel.FindValueTerm("NS1.Title"),
                "q1",
                new EdmStringConstant("Hello world!"));
            mainModel.WrappedModel.AddVocabularyAnnotation(valueAnnotation);

            var expectedErrors = new EdmLibTestErrors()
            {
                { null, null, EdmErrorCode.BadUnresolvedTerm},
            };
            IEnumerable<EdmError> edmErrors;
            mainModel.Validate(out edmErrors);
            this.CompareErrors(edmErrors, expectedErrors);

            mainModel.WrappedModel.AddReferencedModel(referencedModel);
            expectedErrors = null;
            mainModel.Validate(out edmErrors);
            this.CompareErrors(edmErrors, expectedErrors);

            mainModel.RemoveReference(referencedModel);
            expectedErrors = new EdmLibTestErrors()
            {
                { null, null, EdmErrorCode.BadUnresolvedTerm},
            };
            mainModel.Validate(out edmErrors);
            this.CompareErrors(edmErrors, expectedErrors);
        }
        public void ReferencedModelUnresolvedTypeValidationTest()
        {
            var mainModel = new FunctionalUtilities.ModelWithRemovableElements<EdmModel>(ValidationTestModelBuilder.ReferenceBasicTestMainModel() as EdmModel);
            var referencedModel = ValidationTestModelBuilder.ReferenceBasicTestReferencedModel();

            var partnerType = new EdmEntityType("NS1", "Partner", referencedModel.FindEntityType("NS1.Person"), false, true);
            partnerType.AddStructuralProperty("CustomerID", EdmCoreModel.Instance.GetString(false));
            partnerType.AddStructuralProperty("Region", new EdmComplexTypeReference(referencedModel.FindType("NS1.Region") as EdmComplexType, false));
            mainModel.WrappedModel.AddElement(partnerType);

            IEnumerable<EdmError> edmErrors;
            mainModel.Validate(out edmErrors);
            var expectedErrors = new EdmLibTestErrors()
            {
                { "(NS1.Partner)", EdmErrorCode.BadUnresolvedType},
                { "([NS1.Region Nullable=False])", EdmErrorCode.BadUnresolvedType},
            };
            this.CompareErrors(edmErrors, expectedErrors);

            mainModel.WrappedModel.AddReferencedModel(referencedModel);
            mainModel.Validate(out edmErrors);
            expectedErrors = null;
            this.CompareErrors(edmErrors, expectedErrors);

            mainModel.RemoveReference(referencedModel);
            mainModel.Validate(out edmErrors);
            expectedErrors = new EdmLibTestErrors()
            {
                { "(NS1.Partner)", EdmErrorCode.BadUnresolvedType},
                { "([NS1.Region Nullable=False])", EdmErrorCode.BadUnresolvedType},
            };
            this.CompareErrors(edmErrors, expectedErrors);
        }
        public void CreateSimpleTermAnnotation()
        {
            var model = new FunctionalUtilities.ModelWithRemovableElements <EdmModel>(CreateModel());

            var term     = model.FindTerm("NS1.Title");
            var customer = model.FindEntityType("NS1.Customer");

            var annotation = new EdmVocabularyAnnotation(
                customer,
                term,
                "q1",
                new EdmStringConstant("Hello world!"));

            model.WrappedModel.AddVocabularyAnnotation(annotation);

            var annotation2 = new EdmVocabularyAnnotation(
                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.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>
  <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.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>
  <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 ConstructibleVocabularyRemovingInvalidAnnotation()
        {
            var model = new FunctionalUtilities.ModelWithRemovableElements<EdmModel>(VocabularyTestModelBuilder.InlineAnnotationSimpleModel());
            Assert.AreEqual(1, model.VocabularyAnnotations.Count(), "Invalid vocabulary annotation count.");

            var address = model.SchemaElements.Where(x => x.Name.Equals("Address")).SingleOrDefault() as EdmComplexType;
            var addressStreet = address.FindProperty("Street");
            Assert.IsNotNull(address, "Invalid complex type property.");
            Assert.AreEqual(0, addressStreet.VocabularyAnnotations(model).Count(), "Invalid vocabulary annotation count.");

            EdmEntityType petType = new EdmEntityType("DefaultNamespace", "Pet");
            EdmStructuralProperty petBreed = petType.AddStructuralProperty("Breed", EdmCoreModel.Instance.GetString(false));
            model.WrappedModel.AddElement(petType);

            var petTerm = new EdmTerm("DefaultNamespace", "PetTerm", new EdmEntityTypeReference(petType, false));
            model.WrappedModel.AddElement(petType);

            EdmAnnotation annotation = new EdmAnnotation(
                addressStreet,
                petTerm,
                new EdmRecordExpression(new EdmPropertyConstructor(petBreed.Name, new EdmStringConstant("Fluffy"))));
            annotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);

            model.RemoveVocabularyAnnotation(annotation);

            Assert.AreEqual(1, model.VocabularyAnnotations.Count(), "Invalid vocabulary annotation count.");
            Assert.AreEqual(0, addressStreet.VocabularyAnnotations(model).Count(), "Invalid vocabulary annotation count.");
        }
        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 ConstructibleVocabularyRemovingValueAnnotationToNewElement()
        {
            var model = new FunctionalUtilities.ModelWithRemovableElements<EdmModel>(VocabularyTestModelBuilder.InlineAnnotationSimpleModel());
            Assert.AreEqual(1, model.VocabularyAnnotations.Count(), "Invalid vocabulary annotation count.");

            var carType = model.FindEntityType("DefaultNamespace.Car");
            Assert.IsNotNull(carType, "Invalid entity type.");
            Assert.AreEqual(0, carType.VocabularyAnnotations(model).Count(), "Invalid vocabulary annotation count.");

            EdmTerm hiddenName = new EdmTerm("AnnotationNamespace", "HiddenName", EdmCoreModel.Instance.GetString(true));
            model.WrappedModel.AddElement(hiddenName);

            EdmAnnotation valueAnnotation = new EdmAnnotation(
                carType,
                hiddenName,
                new EdmStringConstant("Gray"));

            model.WrappedModel.AddVocabularyAnnotation(valueAnnotation);
            Assert.AreEqual(2, model.VocabularyAnnotations.Count(), "Invalid vocabulary annotation count.");
            Assert.AreEqual(1, carType.VocabularyAnnotations(model).Count(), "Invalid vocabulary annotation count.");

            var valueAnnotationFound = this.CheckForValueAnnotation(carType.VocabularyAnnotations(model), EdmExpressionKind.StringConstant, new List<PropertyValue> { new PropertyValue("Gray") });
            Assert.IsTrue(valueAnnotationFound, "Value annotation cannot be found.");

            model.RemoveVocabularyAnnotation(valueAnnotation);
            Assert.AreEqual(1, model.VocabularyAnnotations.Count(), "Invalid vocabulary annotation count.");
            Assert.AreEqual(0, carType.VocabularyAnnotations(model).Count(), "Invalid vocabulary annotation count.");
        }
        public void ConstructibleVocabularyRemovingAnnotationToExistElement()
        {
            var model = new FunctionalUtilities.ModelWithRemovableElements<EdmModel>(VocabularyTestModelBuilder.InlineAnnotationSimpleModel());
            Assert.AreEqual(1, model.VocabularyAnnotations.Count(), "Invalid vocabulary annotation count.");

            var carType = model.FindEntityType("DefaultNamespace.Car");
            Assert.IsNotNull(carType, "Invalid entity type.");
            var carWheels = carType.FindProperty("Wheels");
            Assert.IsNotNull(carWheels, "Invalid entity type property.");

            var carWheelsVocabularyAnnotations = carWheels.VocabularyAnnotations(model);
            Assert.AreEqual(1, carWheelsVocabularyAnnotations.Count(), "Invalid vocabulary annotation count.");

            var valueAnnotation = carWheelsVocabularyAnnotations.ElementAt(0);
            model.RemoveVocabularyAnnotation(valueAnnotation);
            Assert.AreEqual(0, carWheelsVocabularyAnnotations.Count(), "Invalid vocabulary annotation count.");
            Assert.AreEqual(0, model.VocabularyAnnotations.Count(), "Invalid vocabulary annotation count.");
        }
        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)");
        }