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);
        }
Example #3
0
        public void Term_Annotation_Count_Not_Match_Should_Error()
        {
            var bazValueTerm    = this.definitionModel.SchemaElements.OfType <IEdmTerm>().FirstOrDefault(t => t.Name == "baz");
            var valueAnnotation = new StubVocabularyAnnotation()
            {
                Term = bazValueTerm, Value = new StubStringConstantExpression("zzz")
            };

            this.actualModel.SchemaElements.OfType <StubTerm>().First().AddVocabularyAnnotation(valueAnnotation);

            var errors = this.comparer.CompareModels(this.expectedModel, this.actualModel);

            this.DumpErrors(errors);

            Assert.AreNotEqual(0, errors.Count, "Should have error!");
            Assert.IsTrue(errors.Any(e => e.Contains("Wrong TermAnnotations count")));
        }
Example #4
0
        public void Term_Annotation_Value_Not_Match_Should_Error()
        {
            var barValueTerm    = this.definitionModel.SchemaElements.OfType <IEdmTerm>().FirstOrDefault(t => t.Name == "bar");
            var valueAnnotation = new StubVocabularyAnnotation()
            {
                Term = barValueTerm, Value = new StubStringConstantExpression("_not_exist_")
            };

            var target = this.actualModel.SchemaElements.OfType <StubTerm>().First();

            target.RemoveAnnotationsForTerm(barValueTerm);
            target.AddVocabularyAnnotation(valueAnnotation);

            var errors = this.comparer.CompareModels(this.expectedModel, this.actualModel);

            this.DumpErrors(errors);

            Assert.AreNotEqual(0, errors.Count, "Should have error!");
            Assert.IsTrue(errors.Any(e => e.Contains("Value expression mismatch")));
        }
Example #5
0
        private StubEdmModel CreateApplicationModel()
        {
            var model = new StubEdmModel();

            var valueTerm = new StubTerm("", "foo")
            {
                Type = EdmCoreModel.Instance.GetInt32(true)
            };

            model.Add(valueTerm);

            var barValueTerm    = this.definitionModel.SchemaElements.OfType <IEdmTerm>().FirstOrDefault(t => t.Name == "bar");
            var valueAnnotation = new StubVocabularyAnnotation()
            {
                Term = barValueTerm, Value = new StubStringConstantExpression("zzz")
            };

            valueTerm.AddVocabularyAnnotation(valueAnnotation);

            return(model);
        }
        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);
        }