public void Annotations_On_NonEntityType_Should_Be_Generated()
        {
            var model = new StubEdmModel();

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

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

            var container = new StubEdmEntityContainer("NS1", "myContainer") { entitySet };
            var va3 = new StubValueAnnotation() { 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_ValueAnnotation_Should_Be_Generated()
        {
            var model = new StubEdmModel();

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

            var vt = new StubValueTerm("NS1", "MyValueTerm") { Type = EdmCoreModel.Instance.GetString(true) };
            var va1 = new StubValueAnnotation() { Term = vt, Value = new StubStringConstantExpression("Great!!!") };
            var va2 = new StubValueAnnotation() { 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);
        }
        public static IEdmModel SimpleValueAnnotation()
        {
            StubEdmModel model = new StubEdmModel();
            CreateVocabularyDefinitions(model);

            var person = new StubEdmEntityType("NS1", "Person") 
            { 
                new StubEdmStructuralProperty("Id") { Type = EdmCoreModel.Instance.GetInt16(false) },
                new StubEdmStructuralProperty("FirstName") { Type = EdmCoreModel.Instance.GetString(false) },
                new StubEdmStructuralProperty("LastName") { Type = EdmCoreModel.Instance.GetString(false) },
            };

            var titleValueTerm = model.FindValueTerm("NS1.Title");
            var titleValueAnnotation = new StubValueAnnotation() { Term = titleValueTerm, Value = new StubStringConstantExpression("Sir") };
            person.AddVocabularyAnnotation(titleValueAnnotation);
            model.Add(person);

            return model;
        }
        public void AttachValueTermAnnotation()
        {
            var entityType = new StubEdmEntityType("NS1", "Person");

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

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

            entityType.AddVocabularyAnnotation(valueAnnotation);

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

            var actual = entityType.InlineVocabularyAnnotations.Single() as IEdmValueAnnotation;

            Assert.AreEqual("", actual.Term.Namespace, "namespace");
            Assert.AreEqual("FullName", actual.Term.Name, "name");
            Assert.IsTrue(((IEdmValueTerm)actual.Term).Type.IsString() , "value term type is string");
            Assert.AreEqual("Forever Young", ((IEdmStringConstantExpression)actual.Value).Value, "annotation value");
        }
        public static IEdmModel ModelWithEntityTypeWithComplexBaseType()
        {
            EdmModel model = new EdmModel();

            var entity1 = new StubEdmEntityType("Foo", "Bar");
            var id1 = new EdmStructuralProperty(entity1, "Id", EdmCoreModel.Instance.GetInt16(false), null, EdmConcurrencyMode.None);
            entity1.Add(id1);
            entity1.SetKey(id1);

            StubEdmComplexType complex1 = new StubEdmComplexType("Foo", "Baz");
            complex1.Add(new EdmStructuralProperty(complex1, "Data", EdmCoreModel.Instance.GetString(true)));
            entity1.BaseType = complex1;

            model.AddElement(entity1);
            model.AddElement(complex1);

            return model;
        }
        public static IEdmModel DeclaringTypeIncorrect()
        {
            var model = new EdmModel();
            var entity1 = new EdmEntityType("Foo", "Bar");
            var id = new EdmStructuralProperty(entity1, "Id", EdmCoreModel.Instance.GetInt16(false), null, EdmConcurrencyMode.None);
            entity1.AddKeys(id);
            var entity2 = new StubEdmEntityType("Foo", "Baz");
            var id2 = new EdmStructuralProperty(entity1, "badProp", EdmCoreModel.Instance.GetInt16(false), null, EdmConcurrencyMode.None);
            entity2.SetKey(id2);
            entity2.Add(id2);

            model.AddElement(entity1);
            model.AddElement(entity2);

            return model;
        }
        public static IEdmModel ValueAnnotationWithRecord()
        {
            StubEdmModel model = new StubEdmModel();
            CreateVocabularyDefinitions(model);

            var person = new StubEdmEntityType("NS1", "Person");
            model.Add(person);

            var reviewValueTerm = new StubValueTerm("NS1", "hReviewTerm");
            reviewValueTerm.Type = new StubEdmTypeReference() { Definition = model.FindType("NS1.hReviewEntity"), IsNullable = true };
            model.Add(reviewValueTerm);

            var recordExpression = new StubRecordExpression();
            recordExpression.AddProperty("Name", new StubStringConstantExpression("Young"));
            recordExpression.AddProperty("IdType", new StubStringConstantExpression("Driver License"));
            var reviewValueAnnotation = new StubValueAnnotation()
            {
                Term = reviewValueTerm,
                Value = recordExpression
            };

            person.AddVocabularyAnnotation(reviewValueAnnotation);

            return model;
        }
        private static void CreateVocabularyDefinitions(StubEdmModel model)
        {
            var reviewTypeTerm = new StubTypeTerm("NS1", "hReview")
            {
                new StubEdmStructuralProperty("summary") { Type = EdmCoreModel.Instance.GetString(false) },
                new StubEdmStructuralProperty("itemName") { Type = EdmCoreModel.Instance.GetString(false) },
                new StubEdmStructuralProperty("dateReviewed") { Type = EdmCoreModel.Instance.GetDateTimeOffset(false) },
                new StubEdmStructuralProperty("rating") { Type = EdmCoreModel.Instance.GetInt32(false) },
            };
            model.Add(reviewTypeTerm);

            var reviewEntityType = new StubEdmEntityType("NS1", "hReviewEntity")
            {
                new StubEdmStructuralProperty("summary") { Type = EdmCoreModel.Instance.GetString(false) },
                new StubEdmStructuralProperty("itemName") { Type = EdmCoreModel.Instance.GetString(false) },
                new StubEdmStructuralProperty("dateReviewed") { Type = EdmCoreModel.Instance.GetDateTimeOffset(false) },
                new StubEdmStructuralProperty("rating") { Type = EdmCoreModel.Instance.GetInt32(false) },
            };
            model.Add(reviewEntityType);

            var titleValueTerm = new StubValueTerm("NS1", "Title") { Type = EdmCoreModel.Instance.GetString(true) };
            model.Add(titleValueTerm);

            var displaySizeValueTerm = new StubValueTerm("NS1", "DisplaySize") { Type = EdmCoreModel.Instance.GetInt32(false) };
            model.Add(displaySizeValueTerm);
        }
        public static IEdmModel ValueTermOfStructuredDataType()
        {
            StubEdmModel model = new StubEdmModel();

            var person = new StubEdmEntityType("NS1", "Person") 
            { 
                new StubEdmStructuralProperty("Id") { Type = EdmCoreModel.Instance.GetInt16(false) },
                new StubEdmStructuralProperty("FirstName") { Type = EdmCoreModel.Instance.GetString(false) },
                new StubEdmStructuralProperty("LastName") { Type = EdmCoreModel.Instance.GetString(false) },
            };
            model.Add(person);

            var titleValueTerm = new StubValueTerm("NS1", "Title") { Type = person.ToTypeReference(false) };
            model.Add(titleValueTerm);

            return model;
        }
        public static IEdmModel StructuredValueAnnotation()
        {
            StubEdmModel model = new StubEdmModel();
            CreateVocabularyDefinitions(model);

            var person = new StubEdmEntityType("NS1", "Person");
            model.Add(person);

            var reviewValueTerm = new StubValueTerm("NS1", "hReviewTerm");
            reviewValueTerm.Type = new StubEdmTypeReference() { Definition = model.FindType("NS1.hReviewEntity"), IsNullable = true };
            model.Add(reviewValueTerm);

            var reviewValueAnnotation = new StubValueAnnotation()
            {
                Term = reviewValueTerm,
                Value = new StubStringConstantExpression("this should be Record"),
            };

            person.AddVocabularyAnnotation(reviewValueAnnotation);

            return model;
        }
        public static IEdmModel SimpleValueAnnotationOnContainerAndEntitySet()
        {
            StubEdmModel model = new StubEdmModel();
            CreateVocabularyDefinitions(model);

            var person = new StubEdmEntityType("NS1", "Person");
            var container = new StubEdmEntityContainer("NS1", "Container");
            var personSet = new StubEdmEntitySet("PersonSet", container) { Type = new EdmCollectionType(new EdmEntityTypeReference(person, false)) };
            container.Add(personSet);
            model.Add(container);
            model.Add(person);

            var titleValueTerm = model.FindValueTerm("NS1.Title");
            var titleValueAnnotation = new StubValueAnnotation() { Term = titleValueTerm, Value = new StubStringConstantExpression("Sir") };

            container.AddVocabularyAnnotation(titleValueAnnotation);
            personSet.AddVocabularyAnnotation(titleValueAnnotation);

            return model;
        }
        public static IEdmModel MultipleValueAnnotations()
        {
            StubEdmModel model = new StubEdmModel();
            CreateVocabularyDefinitions(model);

            var person = new StubEdmEntityType("NS1", "Person") 
            { 
                new StubEdmStructuralProperty("Id") { Type = EdmCoreModel.Instance.GetInt16(false) },
                new StubEdmStructuralProperty("FirstName") { Type = EdmCoreModel.Instance.GetString(false) },
                new StubEdmStructuralProperty("LastName") { Type = EdmCoreModel.Instance.GetString(false) },
            };

            var titleValueTerm = model.FindValueTerm("NS1.Title");
            var titleValueAnnotation = new StubValueAnnotation() { Term = titleValueTerm, Value = new StubStringConstantExpression("Sir") };
            person.AddVocabularyAnnotation(titleValueAnnotation);

            var displaySizeValueTerm = model.FindValueTerm("NS1.DisplaySize");
            var displaySizeValueAnnotation = new StubValueAnnotation() { Term = displaySizeValueTerm, Value = new StubStringConstantExpression("1024") };
            person.AddVocabularyAnnotation(displaySizeValueAnnotation);
            model.Add(person);

            var container = new StubEdmEntityContainer("NS1", "Container");
            var personSet = new StubEdmEntitySet("PersonSet", container) { Type = new EdmCollectionType(new EdmEntityTypeReference(person, false)) };
            personSet.AddVocabularyAnnotation(titleValueAnnotation);
            container.Add(personSet);
            model.Add(container);

            return model;
        }
        public static IEdmModel SimpleValueAnnotationConfict()
        {
            StubEdmModel model = new StubEdmModel();
            CreateVocabularyDefinitions(model);

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

            var titleValueTerm = model.FindValueTerm("NS1.Title");
            var titleValueAnnotation = new StubValueAnnotation() { Term = titleValueTerm, Value = new StubStringConstantExpression("Sir") };
            person.AddVocabularyAnnotation(titleValueAnnotation);
            var titleValueAnnotation2 = new StubValueAnnotation() { Term = titleValueTerm, Value = new StubStringConstantExpression("Senor") };
            person.AddVocabularyAnnotation(titleValueAnnotation2);

            model.Add(person);

            return model;
        }