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 #2
0
        public void AmbiguousEntitySetTest()
        {
            EdmEntityContainer container = new EdmEntityContainer("NS1", "Baz");

            IEdmEntitySet set1 = new StubEdmEntitySet("Foo", container);
            IEdmEntitySet set2 = new StubEdmEntitySet("Foo", container);
            IEdmEntitySet set3 = new StubEdmEntitySet("Foo", container);

            container.AddElement(set1);
            Assert.AreNotEqual(set3, container.FindEntitySet("Foo"), "Checking the object equality.");
            Assert.AreEqual(set3.Name, container.FindEntitySet("Foo").Name, "Checking the object equality.");

            container.AddElement(set2);
            container.AddElement(set3);

            IEdmEntitySet ambiguous = container.FindEntitySet("Foo");

            Assert.IsTrue(ambiguous.IsBad(), "Ambiguous binding is bad");

            Assert.AreEqual(EdmContainerElementKind.EntitySet, ambiguous.ContainerElementKind, "Correct container element kind");
            Assert.AreEqual("NS1.Baz", ambiguous.Container.FullName(), "Correct container name");
            Assert.AreEqual("Foo", ambiguous.Name, "Correct Name");
            Assert.IsTrue(ambiguous.EntityType().IsBad(), "Association is bad.");
        }