コード例 #1
0
        public static EdmModel DefaultValueAnnotationWithTargetOnlyModel()
        {
            EdmModel model = VocabularyTestModelBuilder.SimpleModel();

            var valueAnnotation = new FunctionalTests.MutableValueAnnotation()
            {
                Target = new EdmEntityType("", "")
            };
            model.AddVocabularyAnnotation(valueAnnotation);

            return model;
        }
コード例 #2
0
        public void ConstructibleVocabularyEditingValueAnnotationToNewElement()
        {
            EdmModel model = 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.AddElement(hiddenName);

            var valueAnnotation = new FunctionalTests.MutableValueAnnotation()
            {
                Target = carType,
                Term = hiddenName,
                Value = new EdmStringConstant("Gray")
            };

            model.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.");

            var container = model.FindEntityContainer("Container");
            Assert.IsNotNull(container, "Invalid entity container name.");

            valueAnnotation.Target = container;
            valueAnnotation.Value = new EdmStringConstant("Blue");
            model.AddVocabularyAnnotation(valueAnnotation);

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

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

            Assert.AreEqual(1, carType.VocabularyAnnotations(model).Count(), "Invalid vocabulary annotation count.");
            Assert.AreEqual(1, container.VocabularyAnnotations(model).Count(), "Invalid vocabulary annotation count.");
            Assert.AreEqual(3, model.VocabularyAnnotations.Count(), "Invalid vocabulary annotation count.");
        }
コード例 #3
0
        public static EdmModel InlineAnnotationSimpleModel()
        {
            EdmModel model = new EdmModel();

            EdmEntityContainer container = new EdmEntityContainer("DefaultNamespace", "Container");
            model.AddElement(container);

            EdmEntityType carType = new EdmEntityType("DefaultNamespace", "Car");
            EdmStructuralProperty carOwnerId = carType.AddStructuralProperty("OwnerId", EdmCoreModel.Instance.GetInt32(false));
            carType.AddKeys(carOwnerId);
            EdmStructuralProperty carWheels = carType.AddStructuralProperty("Wheels", EdmCoreModel.Instance.GetInt32(true));
            model.AddElement(carType);

            EdmEntityType ownerType = new EdmEntityType("DefaultNamespace", "Owner");
            EdmStructuralProperty ownerId = ownerType.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(false));
            ownerType.AddKeys(ownerId);
            EdmStructuralProperty ownerName = ownerType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(true));
            model.AddElement(ownerType);

            EdmComplexType addressType = new EdmComplexType("DefaultNamespace", "Address");
            EdmStructuralProperty addressStreet = addressType.AddStructuralProperty("Street", EdmCoreModel.Instance.GetString(false));
            EdmStructuralProperty addressStreetNumber = addressType.AddStructuralProperty("StreetNumber", EdmCoreModel.Instance.GetInt32(false));
            model.AddElement(addressType);

            EdmTerm stringTerm = new EdmTerm("AnnotationNamespace", "StringTerm", EdmCoreModel.Instance.GetString(true));
            model.AddElement(stringTerm);

            var valueAnnotation = new FunctionalTests.MutableValueAnnotation()
            {
                Target = carWheels,
                Term = stringTerm,
                Value = new EdmStringConstant("foo")
            };
            valueAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
            model.AddVocabularyAnnotation(valueAnnotation);

            EdmEntityType personType = new EdmEntityType("AnnotationNamespace", "Person");
            EdmStructuralProperty personId = personType.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(false));
            personType.AddKeys(personId);
            EdmStructuralProperty personName = personType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(true));
            model.AddElement(personType);

            return model;
        }