Пример #1
0
        public void AttachTermAnnotation()
        {
            var entityType = new StubEdmEntityType("NS1", "Person");

            var valueTerm = new StubTerm("", "FullName")
            {
                Type = EdmCoreModel.Instance.GetString(false)
            };

            var valueAnnotation = new StubVocabularyAnnotation()
            {
                Term  = valueTerm,
                Value = new StubStringConstantExpression("Forever Young"),
            };

            entityType.AddVocabularyAnnotation(valueAnnotation);

            Assert.AreEqual(1, entityType.InlineVocabularyAnnotations.Count(), "annotation count");

            var actual = entityType.InlineVocabularyAnnotations.Single();

            Assert.AreEqual("", actual.Term.Namespace, "namespace");
            Assert.AreEqual("FullName", actual.Term.Name, "name");
            Assert.IsTrue(actual.Term.Type.IsString(), "Term type is string");
            Assert.AreEqual("Forever Young", ((IEdmStringConstantExpression)actual.Value).Value, "annotation value");
        }
        public void Annotations_On_NonEntityType_Should_Be_Generated()
        {
            var model = new StubEdmModel();

            var entity = new StubEdmEntityType("NS1", "Person");
            var vt     = new StubTerm("NS1", "MyValueTerm")
            {
                Type = EdmCoreModel.Instance.GetString(true)
            };
            var va1 = new StubVocabularyAnnotation()
            {
                Term = vt, Value = new StubStringConstantExpression("Great!!!")
            };

            entity.AddVocabularyAnnotation(va1);
            model.Add(entity);

            var entitySet = new StubEdmEntitySet("personSet", null);
            var va2       = new StubVocabularyAnnotation()
            {
                Term = vt, Value = new StubStringConstantExpression("Aha!!!")
            };

            entitySet.AddVocabularyAnnotation(va2);

            var container = new StubEdmEntityContainer("NS1", "myContainer")
            {
                entitySet
            };
            var va3 = new StubVocabularyAnnotation()
            {
                Term = vt, Value = new StubStringConstantExpression("Huh??")
            };

            container.AddVocabularyAnnotation(va3);
            model.Add(container);

            XElement result = this.generator.GenerateApplicationCsdl(EdmVersion.V40, model);

            string expected = @"
<Schema Namespace='Application.NS1' xmlns='http://docs.oasis-open.org/odata/ns/edm'>
  <Annotations Target='NS1.Person'>
    <Annotation Term='NS1.MyValueTerm' String='Great!!!' />
  </Annotations>
  <Annotations Target='NS1.myContainer'>
    <Annotation Term='NS1.MyValueTerm' String='Huh??' />
  </Annotations>
  <Annotations Target='NS1.myContainer/personSet'>
    <Annotation Term='NS1.MyValueTerm' String='Aha!!!' />
  </Annotations>
</Schema>";

            AssertHelper.AssertXElementEquals(expected, result);
        }
        public void Simple_VocabularyAnnotation_Should_Be_Generated()
        {
            var model = new StubEdmModel();

            var entity = new StubEdmEntityType("NS1", "Person");

            var vt = new StubTerm("NS1", "MyValueTerm")
            {
                Type = EdmCoreModel.Instance.GetString(true)
            };
            var va1 = new StubVocabularyAnnotation()
            {
                Term = vt, Value = new StubStringConstantExpression("Great!!!")
            };
            var va2 = new StubVocabularyAnnotation()
            {
                Term = vt, Qualifier = "phone", Value = new StubStringConstantExpression("Fabulous!!!")
            };

            entity.AddVocabularyAnnotation(va1);
            entity.AddVocabularyAnnotation(va2);

            model.Add(entity);

            XElement result = this.generator.GenerateApplicationCsdl(EdmVersion.V40, model);

            string expected = @"
<Schema Namespace='Application.NS1' xmlns='http://docs.oasis-open.org/odata/ns/edm'>
  <Annotations Target='NS1.Person'>
    <Annotation Term='NS1.MyValueTerm' String='Great!!!' />
    <Annotation Term='NS1.MyValueTerm' Qualifier='phone' String='Fabulous!!!' />
  </Annotations>
</Schema>";

            AssertHelper.AssertXElementEquals(expected, result);
        }