コード例 #1
0
        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 EdmVocabularyAnnotation(
                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);
        }
コード例 #2
0
ファイル: ParallelTests.cs プロジェクト: zhonli/odata.net
        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 EdmVocabularyAnnotation(
                    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 = CsdlWriter.TryWriteCsdl(edmModel, xw, CsdlTarget.OData, out errors);
                xw.Flush();
                ms.Flush();
                ms.Seek(0, SeekOrigin.Begin);
                using (var sr = new StreamReader(ms))
                {
                    var metadata = sr.ReadToEnd();
                    loadedEdmModel = CsdlReader.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);
        }
コード例 #3
0
        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 EdmVocabularyAnnotation(
                friendInfo,
                friendInfo,
                valueAnnotationCast);

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

            return(model);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
ファイル: TrippinApi.cs プロジェクト: Walls/RESTier
            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);
            }
コード例 #6
0
ファイル: Program.cs プロジェクト: EricCote/WebApi2
        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);
        }
コード例 #7
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);
        }
コード例 #8
0
        public void AmbiguousValueTermTest()
        {
            EdmModel model = new EdmModel();

            IEdmValueTerm term1 = new EdmTerm("Foo", "Bar", EdmPrimitiveTypeKind.Byte);
            IEdmValueTerm term2 = new EdmTerm("Foo", "Bar", EdmPrimitiveTypeKind.Decimal);
            IEdmValueTerm term3 = new EdmTerm("Foo", "Bar", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Double, false));

            Assert.AreEqual(EdmTermKind.Value, term1.TermKind, "EdmTermKind is correct.");

            model.AddElement(term1);
            Assert.AreEqual(term1, model.FindValueTerm("Foo.Bar"), "Correct item.");

            model.AddElement(term2);
            model.AddElement(term3);

            IEdmValueTerm ambiguous = model.FindValueTerm("Foo.Bar");

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

            Assert.AreEqual(EdmSchemaElementKind.ValueTerm, ambiguous.SchemaElementKind, "Correct schema element kind.");
            Assert.AreEqual("Foo", ambiguous.Namespace, "Correct Namespace");
            Assert.AreEqual("Bar", ambiguous.Name, "Correct Name");
            Assert.AreEqual(EdmTermKind.Value, ambiguous.TermKind, "Correct term kind.");
            Assert.IsTrue(ambiguous.Type.IsBad(), "Type is bad.");
        }
コード例 #9
0
        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 EdmVocabularyAnnotation(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 EdmVocabularyAnnotation(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);
        }
コード例 #10
0
        public void ShouldWriteEdmPathTypeProperty()
        {
            string expected =
                "<?xml version=\"1.0\" encoding=\"utf-16\"?>" +
                "<edmx:Edmx Version=\"4.0\" xmlns:edmx=\"http://docs.oasis-open.org/odata/ns/edmx\">" +
                "<edmx:DataServices>" +
                "<Schema Namespace=\"NS\" xmlns=\"http://docs.oasis-open.org/odata/ns/edm\">" +
                "<ComplexType Name=\"SelectType\">" +
                "<Property Name=\"DefaultSelect\" Type=\"Collection(Edm.PropertyPath)\" />" +
                "<Property Name=\"DefaultHidden\" Type=\"Collection(Edm.NavigationPropertyPath)\" Nullable=\"false\" />" +
                "</ComplexType>" +
                "<Term Name=\"MyTerm\" Type=\"NS.SelectType\" />" +
                "</Schema>" +
                "</edmx:DataServices>" +
                "</edmx:Edmx>";

            EdmModel       model       = new EdmModel();
            EdmComplexType complexType = new EdmComplexType("NS", "SelectType");

            complexType.AddStructuralProperty("DefaultSelect", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetPropertyPath(true))));
            complexType.AddStructuralProperty("DefaultHidden", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetNavigationPropertyPath(false))));
            model.AddElement(complexType);
            EdmTerm term = new EdmTerm("NS", "MyTerm", new EdmComplexTypeReference(complexType, true));

            model.AddElement(term);
            string csdlStr = GetCsdl(model, CsdlTarget.OData);

            Assert.Equal(expected, csdlStr);
        }
コード例 #11
0
        private EdmModel CreateModelWithSillyNamespace()
        {
            var model = new EdmModel();

            var customer   = new EdmEntityType("Really.Way.Too.Long.Namespace.With.Lots.Of.Dots", "Customer");
            var customerId = customer.AddStructuralProperty("CustomerID", EdmCoreModel.Instance.GetString(false));

            customer.AddKeys(customerId);
            model.AddElement(customer);

            var title = new EdmTerm("Really.Way.Too.Long.Namespace.With.Lots.Of.Dots", "Title", EdmCoreModel.Instance.GetString(true));

            model.AddElement(title);

            var integerId = new EdmTerm("Really.Way.Too.Long.Namespace.With.Lots.Of.Dots", "integerId", EdmCoreModel.Instance.GetString(true));

            model.AddElement(integerId);

            var person = new EdmEntityType("Really.Way.Too.Long.Namespace.With.Lots.Of.Dots", "Person");
            var Id     = person.AddStructuralProperty("ID", EdmCoreModel.Instance.GetString(false));

            person.AddKeys(Id);
            model.AddElement(person);

            var container = new EdmEntityContainer("Really.Way.Too.Long.Namespace.With.Lots.Of.Dots", "Container");

            container.AddEntitySet("Customers", customer);
            model.AddElement(container);

            IEnumerable <EdmError> errors;

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

            return(model);
        }
コード例 #12
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 EdmVocabularyAnnotation(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 EdmVocabularyAnnotation(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);
        }
コード例 #13
0
        private EdmModel CreateModel()
        {
            var model = new EdmModel();

            var customer   = new EdmEntityType("NS1", "Customer");
            var customerId = new EdmStructuralProperty(customer, "CustomerID", EdmCoreModel.Instance.GetString(false));

            customer.AddProperty(customerId);
            customer.AddKeys(customerId);
            model.AddElement(customer);

            var title = new EdmTerm("NS1", "Title", EdmCoreModel.Instance.GetString(true));

            model.AddElement(title);

            var person = new EdmEntityType("NS1", "Person");
            var Id     = person.AddStructuralProperty("ID", EdmCoreModel.Instance.GetString(false));

            person.AddKeys(Id);
            model.AddElement(person);

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

            container.AddElement(new EdmEntitySet(container, "Customers", customer));
            model.AddElement(container);

            IEnumerable <EdmError> errors;

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

            return(model);
        }
コード例 #14
0
        public static EdmModel OutOfLineVocabularyAnnotationWithAnnotationModel()
        {
            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);

            EdmVocabularyAnnotation valueAnnotation = new EdmVocabularyAnnotation(
                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);
        }
コード例 #15
0
        private static void AddSelectTerm <T>(EdmModel model)
        {
            EdmComplexType complexType = new EdmComplexType("NS", "SelectType");

            complexType.AddStructuralProperty("DefaultSelect", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(true))));
            complexType.AddStructuralProperty("DefaultHidden", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(true))));
            model.AddElement(complexType);
            EdmTerm term = new EdmTerm("NS", "MyTerm", new EdmComplexTypeReference(complexType, true));

            model.AddElement(term);

            Type   type       = typeof(T);
            string name       = type.Name;
            var    entityType = model.SchemaElements.OfType <IEdmEntityType>().FirstOrDefault(c => c.Name == name);

            if (entityType == null)
            {
                return;
            }

            IList <string> defaultSelects = new List <string>();
            IList <string> defaultHiddens = new List <string>();
            var            properties     = type.GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);

            foreach (var property in properties)
            {
                var attrs = property.GetCustomAttributes(typeof(DefaultSelectAttribute), false);
                if (attrs != null && attrs.Any())
                {
                    defaultSelects.Add(property.Name);
                    continue;
                }

                attrs = property.GetCustomAttributes(typeof(DefaultHiddenAttribute), false);
                if (attrs != null && attrs.Any())
                {
                    defaultHiddens.Add(property.Name);
                    continue;
                }
            }

            if (defaultSelects.Any() && defaultHiddens.Any())
            {
                List <IEdmPropertyConstructor> edmPropertiesConstructors = new List <IEdmPropertyConstructor>
                {
                    new EdmPropertyConstructor("DefaultSelect", new EdmCollectionExpression(
                                                   defaultSelects.Select(e => new EdmPropertyPathExpression(e)))),
                    new EdmPropertyConstructor("DefaultHidden", new EdmCollectionExpression(
                                                   defaultHiddens.Select(e => new EdmPropertyPathExpression(e)))),
                };

                IEdmRecordExpression    record     = new EdmRecordExpression(edmPropertiesConstructors);
                EdmVocabularyAnnotation annotation = new EdmVocabularyAnnotation(entityType, term, record);
                annotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
                model.SetVocabularyAnnotation(annotation);
            }
        }
コード例 #16
0
        public static IEdmModel InterfaceCriticalPropertyValueMustNotBeNullUsingEntityReferenceTypeModel()
        {
            var model      = new EdmModel();
            var badTypeRef = new EdmEntityReferenceTypeReference(new CustomEntityReferenceType(null), true);
            var valueTerm  = new EdmTerm("NS", "Note", badTypeRef);

            model.AddElement(valueTerm);

            return(model);
        }
コード例 #17
0
        public static IEdmModel InterfaceCriticalKindValueMismatchOnlyUsingEntityReferenceTypeReferenceModel()
        {
            var model = new EdmModel();

            var badTypeRef = new CustomEntityReferenceTypeReference(new EdmComplexType("NS", "Complex"), true);
            var valueTerm  = new EdmTerm("NS", "Note", badTypeRef);

            model.AddElement(valueTerm);

            return(model);
        }
コード例 #18
0
        public static IEdmModel InterfaceCriticalKindValueMismatchOnlyUsingStringTypeReferenceModel()
        {
            var model = new EdmModel();

            var badTypeRef = new EdmStringTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Double), true);
            var valueTerm  = new EdmTerm("NS", "Note", badTypeRef);

            model.AddElement(valueTerm);

            return(model);
        }
コード例 #19
0
        public static IEdmModel InterfaceCriticalPropertyValueMustNotBeNullUsingCollectionTypeModel()
        {
            var model = new EdmModel();

            var badType    = new CustomCollectionType(null, EdmTypeKind.Collection);
            var badTypeRef = new EdmCollectionTypeReference(badType);
            var valueTerm  = new EdmTerm("NS", "Note", badTypeRef);

            model.AddElement(valueTerm);

            return(model);
        }
コード例 #20
0
        public static IEdmModel InterfaceCriticalKindValueMismatchOnlyUsingCollectionTypeReferenceModel()
        {
            var model = new EdmModel();

            var badType    = new CustomCollectionType(new EdmStringTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.String), false), EdmTypeKind.Enum);
            var badTypeRef = new EdmCollectionTypeReference(badType);
            var valueTerm  = new EdmTerm("NS", "Note", badTypeRef);

            model.AddElement(valueTerm);

            return(model);
        }
コード例 #21
0
        private EdmModel BuildBasicModelWithTerm(IEdmTypeReference valueKindType)
        {
            var model     = new EdmModel();
            var container = new EdmEntityContainer("foo", "Container");

            model.AddElement(container);

            var valueTerm = new EdmTerm("foo", "ValueTerm", valueKindType);

            model.AddElement(valueTerm);

            return(model);
        }
コード例 #22
0
        public static EdmModel FindValueTermModel()
        {
            var model = new EdmModel();

            var secondValueTerm = new EdmTerm("DefaultNamespace", "SecondValueTermInModel", EdmCoreModel.Instance.GetString(true));

            model.AddElement(secondValueTerm);

            var referenceAmbigous = new EdmTerm("DefaultNamespace", "ReferenceAmbigousValueTerm", EdmCoreModel.Instance.GetString(true));

            model.AddElement(referenceAmbigous);

            return(model);
        }
コード例 #23
0
        public static IEdmModel InterfaceCriticalPropertyValueMustNotBeNullUsingEnumMemberDeclaredTypeModel()
        {
            var model = new EdmModel();

            var enumType = new EdmEnumType("NS", "Enum");

            enumType.AddMember(new CustomEnumMember(null, "foo", new EdmIntegerConstant(5)));
            var enumTypeRef = new EdmEnumTypeReference(enumType, true);
            var valueTerm   = new EdmTerm("NS", "Note", enumTypeRef);

            model.AddElement(valueTerm);

            return(model);
        }
コード例 #24
0
        private static void AppendAnnotationForPermission(IEdmModel model)
        {
            IEdmEnumType enumType = model.SchemaElements.OfType <IEdmEnumType>().First(c => c.Name == "Permission");
            EdmTerm      term     = new EdmTerm("NS", "PermissionTerm", new EdmEnumTypeReference(enumType, true), appliesTo: "Property");

            ((EdmModel)model).AddElement(term);

            IEdmEntityType entityType = model.SchemaElements.OfType <IEdmEntityType>().First(c => c.Name == "Customer");
            IEdmProperty   property   = entityType.Properties().First(c => c.Name == "Name");

            EdmVocabularyAnnotation annotation = new EdmVocabularyAnnotation(property, term, new EdmEnumMemberExpression(enumType.Members.First(c => c.Name == "ReadOnly")));

            annotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
            ((EdmModel)model).SetVocabularyAnnotation(annotation);
        }
コード例 #25
0
        public void EnsureDuplicateTermAndFunctionReturnTrue()
        {
            EdmModel model       = new EdmModel();
            var      edmFunction = new EdmFunction("n.s", "GetStuff", EdmCoreModel.Instance.GetString(true), false /*isBound*/, null /*entitySetPath*/, false /*isComposable*/);

            model.AddElement(edmFunction);

            EdmModel otherModel = new EdmModel();
            var      edmTerm    = new EdmTerm("n.s", "GetStuff", EdmPrimitiveTypeKind.Int32);

            otherModel.AddElement(edmTerm);
            model.AddReferencedModel(otherModel);

            model.OperationOrNameExistsInReferencedModel(edmFunction, edmFunction.FullName()).Should().BeTrue();
        }
コード例 #26
0
        public static IEdmModel InterfaceCriticalPropertyValueMustNotBeNullOnlyModel()
        {
            var model     = new EdmModel();
            var valueTerm = new EdmTerm("DefaultNamespace", "Note", EdmCoreModel.Instance.GetString(true));

            model.AddElement(valueTerm);

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

            model.AddVocabularyAnnotation(valueAnnotation);

            return(model);
        }
コード例 #27
0
        private static void AppendAnnotation(IEdmModel model)
        {
            EdmTerm term = new EdmTerm("NS", "FooBar", EdmCoreModel.Instance.GetString(true));

            ((EdmModel)model).AddElement(term);

            IEdmEnumType enumType = model.SchemaElements.OfType <IEdmEnumType>().First(c => c.Name == "Appliance");

            var member = enumType.Members.First(c => c.Name == "Stove");

            EdmVocabularyAnnotation annotation = new EdmVocabularyAnnotation(member, term, new EdmStringConstant("Stove Top"));

            // Note: OutOfLine can't work for the "EnumMember" because the OutofLine needs the full type of name.
            annotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
            ((EdmModel)model).SetVocabularyAnnotation(annotation);
        }
コード例 #28
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 EdmVocabularyAnnotation(trackGuidProperty, term, new EdmBooleanConstant(true));
                var anno2 = new EdmVocabularyAnnotation(timeStampValueProp, term, new EdmBooleanConstant(true));

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

                return(model);
            }
コード例 #29
0
        public static EdmModel TermWithAnnotationModel()
        {
            EdmModel model = new EdmModel();

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

            model.AddElement(note);

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

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

            return(model);
        }
コード例 #30
0
        public static IEdmModel VocabularyAnnotationInvalidTypeReferenceDurationConstantModel()
        {
            var model     = new EdmModel();
            var valueTerm = new EdmTerm("DefaultNamespace", "Note", EdmCoreModel.Instance.GetDuration(true));

            model.AddElement(valueTerm);

            var valueAnnotation = new EdmVocabularyAnnotation(
                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);
        }