Exemple #1
0
        public static EdmModel OutOfLineValueAnnotationWithAnnotationModel()
        {
            EdmModel model = new EdmModel();

            EdmComplexType simpleType = new EdmComplexType("DefaultNamespace", "SimpleType");

            simpleType.AddStructuralProperty("Data", EdmCoreModel.Instance.GetString(true));
            model.AddElement(simpleType);

            EdmTerm note = new EdmTerm("DefaultNamespace", "Note", EdmCoreModel.Instance.GetString(true));

            model.AddElement(note);

            EdmAnnotation valueAnnotation = new EdmAnnotation(
                simpleType,
                note,
                new EdmStringConstant("ComplexTypeNote"));

            valueAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.OutOfLine);
            model.AddVocabularyAnnotation(valueAnnotation);

            XElement annotationElement =
                new XElement("{http://foo}Annotation", "1");
            var annotation = new EdmStringConstant(EdmCoreModel.Instance.GetString(false), annotationElement.ToString());

            annotation.SetIsSerializedAsElement(model, true);
            model.SetAnnotationValue(valueAnnotation, "http://foo", "Annotation", annotation);

            return(model);
        }
Exemple #2
0
        public void EdmSingletonAnnotationTests()
        {
            EdmModel model = new EdmModel();

            EdmStructuralProperty customerProperty = new EdmStructuralProperty(customerType, "Name", EdmCoreModel.Instance.GetString(false));

            customerType.AddProperty(customerProperty);
            model.AddElement(this.customerType);

            EdmSingleton vipCustomer = new EdmSingleton(this.entityContainer, "VIP", this.customerType);

            EdmTerm term       = new EdmTerm(myNamespace, "SingletonAnnotation", EdmPrimitiveTypeKind.String);
            var     annotation = new EdmAnnotation(vipCustomer, term, new EdmStringConstant("Singleton Annotation"));

            model.AddVocabularyAnnotation(annotation);

            var singletonAnnotation = vipCustomer.VocabularyAnnotations(model).Single();

            Assert.Equal(vipCustomer, singletonAnnotation.Target);
            Assert.Equal("SingletonAnnotation", singletonAnnotation.Term.Name);

            singletonAnnotation = model.FindDeclaredVocabularyAnnotations(vipCustomer).Single();
            Assert.Equal(vipCustomer, singletonAnnotation.Target);
            Assert.Equal("SingletonAnnotation", singletonAnnotation.Term.Name);

            EdmTerm propertyTerm       = new EdmTerm(myNamespace, "SingletonPropertyAnnotation", EdmPrimitiveTypeKind.String);
            var     propertyAnnotation = new EdmAnnotation(customerProperty, propertyTerm, new EdmStringConstant("Singleton Property Annotation"));

            model.AddVocabularyAnnotation(propertyAnnotation);

            var singletonPropertyAnnotation = customerProperty.VocabularyAnnotations(model).Single();

            Assert.Equal(customerProperty, singletonPropertyAnnotation.Target);
            Assert.Equal("SingletonPropertyAnnotation", singletonPropertyAnnotation.Term.Name);
        }
Exemple #3
0
        public static void SetSearchRestrictionsCapabilitiesAnnotation(this EdmModel model, IEdmEntitySet entitySet, bool searchable, CapabilitiesSearchExpressions unsupported)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }
            if (entitySet == null)
            {
                throw new ArgumentNullException("entitySet");
            }

            var target     = entitySet;
            var term       = SearchRestrictionsTerm;
            var name       = new EdmEnumTypeReference(SearchExpressionsType, false).ToStringLiteral((long)unsupported);
            var properties = new IEdmPropertyConstructor[]
            {
                new EdmPropertyConstructor("Searchable", new EdmBooleanConstant(searchable)),
                new EdmPropertyConstructor("UnsupportedExpressions", new EdmEnumMemberReferenceExpression(SearchExpressionsType.Members.Single(m => m.Name == name))),
            };
            var record = new EdmRecordExpression(properties);

            var annotation = new EdmAnnotation(target, term, record);

            annotation.SetSerializationLocation(model, entitySet.ToSerializationLocation());
            model.AddVocabularyAnnotation(annotation);
        }
Exemple #4
0
        public static EdmModel FindVocabularyAnnotationAcrossModelValueAnnotationModel()
        {
            var model = new EdmModel();

            var containerOne = new EdmEntityContainer("DefaultNamespace", "ContainerOne");

            model.AddElement(containerOne);

            var termOne = new EdmTerm("DefaultNamespace", "TermOne", EdmCoreModel.Instance.GetString(true));

            model.AddElement(termOne);
            var termTwo = new EdmTerm("DefaultNamespace", "TermTwo", EdmCoreModel.Instance.GetString(true));

            model.AddElement(termTwo);

            var valueAnnotationOne = new EdmAnnotation(
                containerOne,
                termOne,
                new EdmStringConstant("1"));

            valueAnnotationOne.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
            model.AddVocabularyAnnotation(valueAnnotationOne);

            return(model);
        }
        private static void AddOptimisticConcurrencyAnnotation(this EdmModel model, IEdmVocabularyAnnotatable target,
                                                               EntityTypeConfiguration entityTypeConfig, EdmTypeMap edmTypeMap)
        {
            IEnumerable <StructuralPropertyConfiguration> concurrencyPropertyies =
                entityTypeConfig.Properties.OfType <StructuralPropertyConfiguration>().Where(property => property.ConcurrencyToken);

            IList <IEdmStructuralProperty> edmProperties = new List <IEdmStructuralProperty>();

            foreach (StructuralPropertyConfiguration property in concurrencyPropertyies)
            {
                IEdmProperty value;
                if (edmTypeMap.EdmProperties.TryGetValue(property.PropertyInfo, out value))
                {
                    var item = value as IEdmStructuralProperty;
                    if (item != null)
                    {
                        edmProperties.Add(item);
                    }
                }
            }

            if (edmProperties.Any())
            {
                // todo: fix SetOptimisticConcurrencyAnnotation to support setting concurrency annotations on singletons
                // https://github.com/OData/odata.net/issues/770
                // model.SetOptimisticConcurrencyAnnotation(target, edmProperties);

                IEdmCollectionExpression collectionExpression = new EdmCollectionExpression(edmProperties.Select(p => new EdmPropertyPathExpression(p.Name)).ToArray());
                IEdmValueTerm            term = Microsoft.OData.Edm.Vocabularies.V1.CoreVocabularyModel.ConcurrencyTerm;

                EdmAnnotation annotation = new EdmAnnotation(target, term, collectionExpression);
                annotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
                model.SetVocabularyAnnotation(annotation);
            }
        }
        private IEdmModel EntityTypeTermModel()
        {
            var model = new EdmModel();

            var entityTypeElement = new EdmEntityType("NS", "EntityTypeElement");

            entityTypeElement.AddKeys(entityTypeElement.AddStructuralProperty("KeyProperty", EdmCoreModel.Instance.GetInt32(false)));
            entityTypeElement.AddStructuralProperty("IntegerProperty", EdmCoreModel.Instance.GetInt32(true));
            entityTypeElement.AddStructuralProperty("StringProperty", EdmCoreModel.Instance.GetString(true));
            model.AddElement(entityTypeElement);

            var entityTypeTerm = new EdmTerm("NS", "EntityTypeTerm", new EdmEntityTypeReference(entityTypeElement, true));

            model.AddElement(entityTypeTerm);

            var inlineEntityTypeAnnotation = new EdmAnnotation(entityTypeElement, entityTypeTerm, new EdmRecordExpression(
                                                                   new EdmPropertyConstructor("KeyProperty", new EdmIntegerConstant(1)),
                                                                   new EdmPropertyConstructor("IntegerProperty", new EdmIntegerConstant(111)),
                                                                   new EdmPropertyConstructor("StringProperty", new EdmStringConstant("Inline String 111"))));

            inlineEntityTypeAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
            model.AddVocabularyAnnotation(inlineEntityTypeAnnotation);

            var outlineEntityTypeAnnotation = new EdmAnnotation(entityTypeTerm, entityTypeTerm, new EdmRecordExpression(
                                                                    new EdmPropertyConstructor("KeyProperty", new EdmIntegerConstant(2)),
                                                                    new EdmPropertyConstructor("IntegerProperty", new EdmIntegerConstant(222)),
                                                                    new EdmPropertyConstructor("StringProperty", new EdmStringConstant("Outline String 222"))));

            model.AddVocabularyAnnotation(outlineEntityTypeAnnotation);

            return(model);
        }
        public static IEdmModel InvalidPropertyTypeUsingIsTypeOnInlineAnnotationModel()
        {
            var model = new EdmModel();

            var bike = new EdmComplexType("NS", "Bike");

            bike.AddStructuralProperty("Color", EdmCoreModel.Instance.GetString(true));
            model.AddElement(bike);

            var car          = new EdmComplexType("NS", "Car");
            var carExpensive = car.AddStructuralProperty("Expensive", new EdmComplexTypeReference(bike, true));

            model.AddElement(car);

            var carTerm = new EdmTerm("NS", "CarTerm", new EdmComplexTypeReference(car, true));

            model.AddElement(carTerm);

            var valueAnnotation = new EdmAnnotation(
                car,
                carTerm,
                new EdmRecordExpression(
                    new EdmPropertyConstructor(carExpensive.Name, new EdmIsTypeExpression(new EdmStringConstant("foo"), EdmCoreModel.Instance.GetString(true)))));

            valueAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
            model.AddVocabularyAnnotation(valueAnnotation);

            return(model);
        }
Exemple #8
0
        private static void CustomTermDemo()
        {
            Console.WriteLine("CustomTermDemo");

            var model = new EdmModel();

            model.SetNamespaceAlias("ns", "Alias1");
            var term = new EdmTerm("ns", "ErrorCodes",
                                   new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(false))));

            model.AddElement(term);
            var entity1 = new EdmEntityType("ns", "entity1");

            entity1.AddKeys(entity1.AddStructuralProperty("id", EdmPrimitiveTypeKind.Guid));
            model.AddElement(entity1);
            var container = new EdmEntityContainer("ns", "default");

            model.AddElement(container);
            var e1 = container.AddSingleton("E1", entity1);

            var annotation = new EdmAnnotation(e1, term,
                                               new EdmCollectionExpression(
                                                   new EdmStringConstant("Entity Not Found"),
                                                   new EdmStringConstant("Deleting link failed")));

            model.AddVocabularyAnnotation(annotation);

            ShowModel(model);
        }
        public static IEdmModel CastNullableToNonNullableOnInlineAnnotationModel()
        {
            var model = new EdmModel();

            var address = new EdmComplexType("NS", "Address");

            address.AddStructuralProperty("StreetNumber", EdmCoreModel.Instance.GetInt32(true));
            address.AddStructuralProperty("StreetName", EdmCoreModel.Instance.GetString(true));
            model.AddElement(address);

            var friend = new EdmComplexType("NS", "Friend");

            friend.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(true));
            friend.AddStructuralProperty("NickNames", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetString(true)));
            friend.AddStructuralProperty("Address", new EdmComplexTypeReference(address, true));
            model.AddElement(friend);

            var friendInfo = new EdmTerm("NS", "FriendInfo", EdmCoreModel.GetCollection(new EdmComplexTypeReference(friend, true)));

            model.AddElement(friendInfo);

            var valueAnnotationCast = new EdmCastExpression(new EdmCollectionExpression(new EdmStringConstant("foo"), new EdmStringConstant("bar")), new EdmComplexTypeReference(friend, true));
            var valueAnnotation     = new EdmAnnotation(
                friendInfo,
                friendInfo,
                valueAnnotationCast);

            valueAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
            model.AddVocabularyAnnotation(valueAnnotation);

            return(model);
        }
Exemple #10
0
            public async Task <IEdmModel> GetModelAsync(ModelContext context, CancellationToken cancellationToken)
            {
                var model = await InnerHandler.GetModelAsync(context, cancellationToken);

                // Set computed annotation
                var tripType           = (EdmEntityType)model.SchemaElements.Single(e => e.Name == "Trip");
                var trackGuidProperty  = tripType.DeclaredProperties.Single(prop => prop.Name == "TrackGuid");
                var timeStampValueProp = model.EntityContainer.FindEntitySet("Airlines").EntityType().FindProperty("TimeStampValue");
                var term  = new EdmTerm("Org.OData.Core.V1", "Computed", EdmPrimitiveTypeKind.Boolean);
                var anno1 = new EdmAnnotation(trackGuidProperty, term, new EdmBooleanConstant(true));
                var anno2 = new EdmAnnotation(timeStampValueProp, term, new EdmBooleanConstant(true));

                ((EdmModel)model).SetVocabularyAnnotation(anno1);
                ((EdmModel)model).SetVocabularyAnnotation(anno2);

                var personType = (EdmEntityType)model.SchemaElements.Single(e => e.Name == "Person");
                var type       = personType.FindProperty("PersonId").Type;

                var isNullableField = typeof(EdmTypeReference).GetField("isNullable", BindingFlags.Instance | BindingFlags.NonPublic);

                if (isNullableField != null)
                {
                    isNullableField.SetValue(type, false);
                }

                return(model);
            }
        public static IEdmModel InterfaceCriticalKindValueUnexpectedWithOtherErrorsModel()
        {
            var model     = new EdmModel();
            var valueTerm = new EdmTerm("DefaultNamespace", "Note", EdmCoreModel.Instance.GetString(true));

            model.AddElement(valueTerm);
            model.AddElement(valueTerm);

            var entity = new EdmEntityType("DefaultNamespace", "foo");

            model.AddElement(entity);

            var entityContainer = new EdmEntityContainer("DefaultNamespace", "container");

            model.AddElement(entityContainer);

            var badString = new CustomStringConstant("foo", EdmExpressionKind.None, EdmValueKind.String);

            var valueAnnotation = new EdmAnnotation(
                valueTerm,
                valueTerm,
                badString);

            model.AddVocabularyAnnotation(valueAnnotation);

            var valueAnnotation2 = new EdmAnnotation(
                valueTerm,
                valueTerm,
                new EdmStringConstant("foo"));

            model.AddVocabularyAnnotation(valueAnnotation2);

            return(model);
        }
Exemple #12
0
        public void FindVocabularyAnnotationInParallel()
        {
            int annotationCount = 30;
            var edmModel        = new EdmParModel().Model as EdmModel;
            var container       = edmModel.EntityContainer;

            for (int i = 0; i < annotationCount; i++)
            {
                EdmTerm term = new EdmTerm("NS", "Test" + i, EdmPrimitiveTypeKind.String);
                EdmVocabularyAnnotation annotation = new EdmAnnotation(
                    container,
                    term,
                    new EdmStringConstant("desc" + i));
                edmModel.AddVocabularyAnnotation(annotation);
            }

            IEdmModel loadedEdmModel = null;

            using (var ms = new MemoryStream())
            {
                var xw = XmlWriter.Create(ms, new XmlWriterSettings {
                    Indent = true
                });

                IEnumerable <EdmError> errors;
                var res = EdmxWriter.TryWriteEdmx(edmModel, xw, EdmxTarget.OData, out errors);
                xw.Flush();
                ms.Flush();
                ms.Seek(0, SeekOrigin.Begin);
                using (var sr = new StreamReader(ms))
                {
                    var metadata = sr.ReadToEnd();
                    loadedEdmModel = EdmxReader.Parse(XmlReader.Create(new MemoryStream(Encoding.UTF8.GetBytes(metadata))));
                }
            }
            container = loadedEdmModel.EntityContainer;

            int errorCount           = 0;
            int totalAnnotationCount = 0;
            int taskCount            = 100;

            Parallel.ForEach(
                Enumerable.Range(0, taskCount),
                index =>
            {
                try
                {
                    var count = loadedEdmModel.FindVocabularyAnnotations(container).ToList().Count();
                    Interlocked.Add(ref totalAnnotationCount, count);
                }
                catch (Exception ew)
                {
                    Console.WriteLine(ew);
                    Interlocked.Increment(ref errorCount);
                }
            });

            Assert.AreEqual(0, errorCount);
            Assert.AreEqual(taskCount * annotationCount, totalAnnotationCount);
        }
Exemple #13
0
        private static void SetCapabilitiesAnnotation(this EdmModel model, IEdmVocabularyAnnotatable target, IEdmValueTerm term, bool value)
        {
            var expression = new EdmBooleanConstant(value);
            var annotation = new EdmAnnotation(target, term, expression);

            annotation.SetSerializationLocation(model, target.ToSerializationLocation());
            model.AddVocabularyAnnotation(annotation);
        }
Exemple #14
0
        private static void SetCoreAnnotation(this EdmModel model, IEdmVocabularyAnnotatable target, IEdmValueTerm term, string value)
        {
            var expression = new EdmStringConstant(value);
            var annotation = new EdmAnnotation(target, term, expression);

            annotation.SetSerializationLocation(model, target.ToSerializationLocation());
            model.AddVocabularyAnnotation(annotation);
        }
Exemple #15
0
        private static void SetComputedAnnotation(EdmModel model, IEdmProperty target)
        {
            // when 'target' is <Key> property, V4's 'Computed' also has the meaning of OData V3's 'Identity'.
            var val        = new EdmBooleanConstant(value: true);
            var annotation = new EdmAnnotation(target, CoreVocabularyModel.ComputedTerm, val);

            annotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
            model.SetVocabularyAnnotation(annotation);
        }
Exemple #16
0
        public void ExceptionThrowForInvalidPropertyPath()
        {
            EdmModel model = new EdmModel();

            EdmEntityType personType = new EdmEntityType("MyNs", "Person", null, false, false, true);

            personType.AddKeys(personType.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32));
            personType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(isNullable: true));

            var container = new EdmEntityContainer("MyNs", "Container");

            model.AddElement(personType);
            container.AddEntitySet("People", personType);
            model.AddElement(container);
            IEdmEntitySet peopleSet = model.FindDeclaredEntitySet("People");

            IEdmPathExpression nameExpression = new EdmPropertyPathExpression("NameName");

            IEdmCollectionExpression collection = new EdmCollectionExpression(new[] { nameExpression });
            IEdmValueTerm            term       = null;

            foreach (var referencedModel in model.ReferencedModels)
            {
                term = referencedModel.FindDeclaredValueTerm("Org.OData.Core.V1.OptimisticConcurrencyControl");

                if (term != null)
                {
                    break;
                }
            }

            Assert.IsNotNull(term);

            EdmAnnotation valueAnnotationOnEntitySet = new EdmAnnotation(peopleSet, term, collection);

            valueAnnotationOnEntitySet.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
            model.AddVocabularyAnnotation(valueAnnotationOnEntitySet);

            ODataEntry entry = new ODataEntry
            {
                Properties = new[]
                {
                    new ODataProperty {
                        Name = "ID", Value = 123
                    },
                    new ODataProperty {
                        Name = "Name", Value = "lucy"
                    },
                }
            };

            Action action = () => GetWriterOutputForContentTypeAndKnobValue(entry, model, peopleSet, personType);

            action.ShouldThrow <ODataException>().WithMessage(ErrorStrings.EdmValueUtils_PropertyDoesntExist("MyNs.Person", "NameName"));
        }
        public void TestAnnotationsWithModelReferencesAnnotationsInTheModel()
        {
            var vocabulary = new FunctionalUtilities.ModelWithRemovableElements <EdmModel>(CreateModel());

            vocabulary.RemoveElement(vocabulary.EntityContainer);
            vocabulary.RemoveElement(vocabulary.FindEntityType("NS1.Customer"));
            IEnumerable <EdmError> errors;

            Assert.IsTrue(vocabulary.Validate(out errors), "validate vocabulary");

            var model = new FunctionalUtilities.ModelWithRemovableElements <EdmModel>(CreateModel());

            model.RemoveElement(model.FindValueTerm("NS1.Title"));
            model.RemoveElement(model.FindEntityType("NS1.Person"));
            model.WrappedModel.AddReferencedModel(vocabulary);

            var vterm    = vocabulary.FindValueTerm("NS1.Title");
            var tterm    = vocabulary.FindEntityType("NS1.Person");
            var customer = model.FindEntityType("NS1.Customer");

            var vannotation = new EdmAnnotation(
                customer,
                vterm,
                "q1",
                new EdmStringConstant("Hello world!"));

            model.WrappedModel.AddVocabularyAnnotation(vannotation);

            var sw = new StringWriter();
            var w  = XmlWriter.Create(sw, new XmlWriterSettings()
            {
                Indent = true
            });

            model.TryWriteCsdl(w, out errors);
            w.Close();
            Assert.AreEqual(
                @"<?xml version=""1.0"" encoding=""utf-16""?>
<Schema Namespace=""NS1"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
  <EntityType Name=""Customer"">
    <Key>
      <PropertyRef Name=""CustomerID"" />
    </Key>
    <Property Name=""CustomerID"" Type=""Edm.String"" Nullable=""false"" />
  </EntityType>
  <EntityContainer Name=""Container"">
    <EntitySet Name=""Customers"" EntityType=""NS1.Customer"" />
  </EntityContainer>
  <Annotations Target=""NS1.Customer"">
    <Annotation Term=""NS1.Title"" Qualifier=""q1"" String=""Hello world!"" />
  </Annotations>
</Schema>", sw.ToString(), "model.WriteCsdl(w)");
        }
        private IEdmVocabularyAnnotation CreateAndAttachValueAnnotation(IEdmVocabularyAnnotatable target, IEdmValueTerm term, IEdmExpression value, string qualifier)
        {
            var annotation = new EdmAnnotation(
                target,
                term,
                qualifier,
                value);

            // ?? Unnatural API
            ((EdmModel)this.baseModel).AddVocabularyAnnotation(annotation);
            return(annotation);
        }
        private IEdmModel BuildValueAnnotationModelWithEdmValueKind(IEdmTypeReference valueKindType, IEdmExpression valueAnnotationValue)
        {
            var model = this.BuildBasicModelWithValueTerm(valueKindType);

            var valueAnnotation = new EdmAnnotation(
                model.FindEntityContainer("foo.Container"),
                model.FindValueTerm("foo.ValueTerm"),
                valueAnnotationValue);

            model.AddVocabularyAnnotation(valueAnnotation);

            return(model);
        }
Exemple #20
0
        private static void SetCapabilitiesAnnotation(this EdmModel model, IEdmVocabularyAnnotatable target, IEdmValueTerm term, IEnumerable <string> values)
        {
            if (values == null)
            {
                values = new string[0];
            }

            var expression = new EdmCollectionExpression(values.Select(function => new EdmStringConstant(function)));
            var annotation = new EdmAnnotation(target, term, expression);

            annotation.SetSerializationLocation(model, target.ToSerializationLocation());
            model.AddVocabularyAnnotation(annotation);
        }
        public void AnnotatedModelShouldSupportAddingStringAnnotations()
        {
            var primaryModel    = new EdmModel();
            var entityContainer = new EdmEntityContainer("Fake", "Container");

            primaryModel.AddElement(entityContainer);

            var testSubject = new VocabularyAnnotationCache(primaryModel);

            var annotation = new EdmAnnotation(entityContainer, new EdmTerm("fake", "foo", EdmPrimitiveTypeKind.String), new EdmStringConstant("bar"));

            testSubject.Add(annotation);
            testSubject.FindDeclaredVocabularyAnnotations(entityContainer).Should().Contain(annotation).And.HaveCount(1);
        }
Exemple #22
0
        public static void SetComputedAnnotation(EdmModel model, IEdmProperty target)
        {
            EdmUtil.CheckArgumentNull(model, "model");
            EdmUtil.CheckArgumentNull(target, "target");

            IEdmBooleanConstantExpression val = new EdmBooleanConstant(true);
            IEdmValueTerm term = CoreVocabularyModel.ComputedTerm;

            Debug.Assert(term != null, "term!=null");
            EdmAnnotation annotation = new EdmAnnotation(target, term, val);

            annotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
            model.SetVocabularyAnnotation(annotation);
        }
Exemple #23
0
        private static void SetVocabularyAnnotation(this EdmModel model, IEdmVocabularyAnnotatable target,
                                                    IList <IEdmPropertyConstructor> properties, string qualifiedName)
        {
            Contract.Assert(model != null);
            Contract.Assert(target != null);

            IEdmValueTerm term = model.FindValueTerm(qualifiedName);

            if (term != null)
            {
                IEdmRecordExpression record     = new EdmRecordExpression(properties);
                EdmAnnotation        annotation = new EdmAnnotation(target, term, record);
                annotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
                model.SetVocabularyAnnotation(annotation);
            }
        }
Exemple #24
0
        public static IEdmModel ValueAnnotationValidDefaultDurationConstantModel()
        {
            var model     = new EdmModel();
            var valueTerm = new EdmTerm("DefaultNamespace", "Note", EdmCoreModel.Instance.GetDuration(true));

            model.AddElement(valueTerm);

            var valueAnnotation = new EdmAnnotation(
                valueTerm,
                valueTerm,
                new EdmDurationConstant(new TimeSpan()));

            valueAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.OutOfLine);
            model.AddVocabularyAnnotation(valueAnnotation);

            return(model);
        }
Exemple #25
0
        public static IEdmModel ValueAnnotationInvalidTypeReferenceDurationConstantModel()
        {
            var model     = new EdmModel();
            var valueTerm = new EdmTerm("DefaultNamespace", "Note", EdmCoreModel.Instance.GetDuration(true));

            model.AddElement(valueTerm);

            var valueAnnotation = new EdmAnnotation(
                valueTerm,
                valueTerm,
                new EdmDurationConstant(EdmCoreModel.Instance.GetDateTimeOffset(false), new TimeSpan(1, 99, 99, 99, 999)));

            valueAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.OutOfLine);
            model.AddVocabularyAnnotation(valueAnnotation);

            return(model);
        }
Exemple #26
0
            public async Task <IEdmModel> GetModelAsync(ModelContext context, CancellationToken cancellationToken)
            {
                var model = await InnerHandler.GetModelAsync(context, cancellationToken);

                // Set computed annotation
                var tripType           = (EdmEntityType)model.SchemaElements.Single(e => e.Name == "Trip");
                var trackGuidProperty  = tripType.DeclaredProperties.Single(prop => prop.Name == "TrackGuid");
                var timeStampValueProp = model.EntityContainer.FindEntitySet("Airlines").EntityType().FindProperty("TimeStampValue");
                var term  = new EdmTerm("Org.OData.Core.V1", "Computed", EdmPrimitiveTypeKind.Boolean);
                var anno1 = new EdmAnnotation(trackGuidProperty, term, new EdmBooleanConstant(true));
                var anno2 = new EdmAnnotation(timeStampValueProp, term, new EdmBooleanConstant(true));

                ((EdmModel)model).SetVocabularyAnnotation(anno1);
                ((EdmModel)model).SetVocabularyAnnotation(anno2);

                return(model);
            }
        public static IEdmModel AllInterfaceCriticalModel()
        {
            var model     = new EdmModel();
            var valueTerm = new EdmTerm("DefaultNamespace", "Note", EdmCoreModel.Instance.GetString(true));

            model.AddElement(valueTerm);

            var badString = new CustomStringConstant("foo", EdmExpressionKind.None, EdmValueKind.Integer);

            var valueAnnotation = new EdmAnnotation(
                valueTerm,
                valueTerm,
                badString);

            model.AddVocabularyAnnotation(valueAnnotation);

            var mutableValueAnnotationueAnnotation = new MutableValueAnnotation()
            {
                Target = valueTerm
            };

            model.AddVocabularyAnnotation(mutableValueAnnotationueAnnotation);

            var customEntity = new CustomEntityType(new List <IEdmProperty>()
            {
                null
            });

            model.AddElement(customEntity);

            var entity      = new EdmEntityType("DefaultNamespace", "bar");
            var entity2     = new EdmEntityType("DefaultNamespace", "bar2");
            var navProperty = new StubEdmNavigationProperty("Nav")
            {
                DeclaringType = entity,
                Type          = new EdmEntityTypeReference(entity2, false)
            };

            navProperty.Partner = navProperty;
            entity.AddProperty(navProperty);
            model.AddElement(entity);
            model.AddElement(entity2);

            return(model);
        }
        public static IEdmModel IsTypeResultFalseEvaluationModel()
        {
            var model = new EdmModel();

            var booleanFlag = new EdmTerm("NS", "BooleanFlag", EdmCoreModel.Instance.GetBoolean(true));

            model.AddElement(booleanFlag);

            var valueAnnotation = new EdmAnnotation(
                booleanFlag,
                booleanFlag,
                new EdmIsTypeExpression(new EdmIntegerConstant(32), EdmCoreModel.Instance.GetString(true)));

            valueAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.OutOfLine);
            model.AddVocabularyAnnotation(valueAnnotation);

            return(model);
        }
        public static IEdmModel InterfaceCriticalPropertyValueMustNotBeNullUsingBinaryValueModel()
        {
            var model = new EdmModel();

            var valueTerm = new EdmTerm("NS", "Note", EdmCoreModel.Instance.GetBinary(true));

            model.AddElement(valueTerm);

            var badValue        = new CustomBinaryConstant(null);
            var valueAnnotation = new EdmAnnotation(
                valueTerm,
                valueTerm,
                badValue);

            model.AddVocabularyAnnotation(valueAnnotation);

            return(model);
        }
        public static IEdmModel EdmValueKindInterfaceCriticalKindValueUnexpectedOnlyModel()
        {
            var model     = new EdmModel();
            var valueTerm = new EdmTerm("DefaultNamespace", "Note", EdmCoreModel.Instance.GetString(true));

            model.AddElement(valueTerm);

            var badString = new CustomStringConstant("foo", EdmExpressionKind.StringConstant, (EdmValueKind)123);

            var valueAnnotation = new EdmAnnotation(
                valueTerm,
                valueTerm,
                badString);

            model.AddVocabularyAnnotation(valueAnnotation);

            return(model);
        }