static ODataFeedAndEntryTypeContextTests()
        {
            Model = new EdmModel();
            EntitySetElementType = new EdmEntityType("ns", "Customer");
            ExpectedEntityType = new EdmEntityType("ns", "VipCustomer", EntitySetElementType);
            ActualEntityType = new EdmEntityType("ns", "DerivedVipCustomer", ExpectedEntityType);

            EdmEntityContainer defaultContainer = new EdmEntityContainer("ns", "DefaultContainer");
            Model.AddElement(defaultContainer);
            Model.AddVocabularyAnnotation(new EdmAnnotation(defaultContainer, UrlConventionsConstants.ConventionTerm, UrlConventionsConstants.KeyAsSegmentAnnotationValue));

            EntitySet = new EdmEntitySet(defaultContainer, "Customers", EntitySetElementType);
            Model.AddElement(EntitySetElementType);
            Model.AddElement(ExpectedEntityType);
            Model.AddElement(ActualEntityType);
            defaultContainer.AddElement(EntitySet);

            SerializationInfo = new ODataFeedAndEntrySerializationInfo { NavigationSourceName = "MyCustomers", NavigationSourceEntityTypeName = "ns.MyCustomer", ExpectedTypeName = "ns.MyVipCustomer" };
            SerializationInfoWithEdmUnknowEntitySet = new ODataFeedAndEntrySerializationInfo() { NavigationSourceName = null, NavigationSourceEntityTypeName = "ns.MyCustomer", ExpectedTypeName = "ns.MyVipCustomer", NavigationSourceKind = EdmNavigationSourceKind.UnknownEntitySet };
            TypeContextWithoutModel = ODataFeedAndEntryTypeContext.Create(SerializationInfo, navigationSource: null, navigationSourceEntityType: null, expectedEntityType: null, model: Model, throwIfMissingTypeInfo: true);
            TypeContextWithModel = ODataFeedAndEntryTypeContext.Create(/*serializationInfo*/null, EntitySet, EntitySetElementType, ExpectedEntityType, Model, throwIfMissingTypeInfo: true);
            TypeContextWithEdmUnknowEntitySet = ODataFeedAndEntryTypeContext.Create(SerializationInfoWithEdmUnknowEntitySet, navigationSource: null, navigationSourceEntityType: null, expectedEntityType: null, model: Model, throwIfMissingTypeInfo: true);
            BaseTypeContextThatThrows = ODataFeedAndEntryTypeContext.Create(serializationInfo: null, navigationSource: null, navigationSourceEntityType: null, expectedEntityType: null, model: Model, throwIfMissingTypeInfo: true);
            BaseTypeContextThatWillNotThrow = ODataFeedAndEntryTypeContext.Create(serializationInfo: null, navigationSource: null, navigationSourceEntityType: null, expectedEntityType: null, model: Model, throwIfMissingTypeInfo: false);
        }
        private static ODataEntry CreateEntryWithKeyAsSegmentConvention(bool addAnnotation, bool? useKeyAsSegment)
        {
            var model = new EdmModel();
            var container = new EdmEntityContainer("Fake", "Container");
            model.AddElement(container);
            if (addAnnotation)
            {
                model.AddVocabularyAnnotation(new EdmAnnotation(container, UrlConventionsConstants.ConventionTerm, UrlConventionsConstants.KeyAsSegmentAnnotationValue));                
            }
            
            EdmEntityType entityType = new EdmEntityType("Fake", "FakeType");
            entityType.AddKeys(entityType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
            model.AddElement(entityType);

            var entitySet = new EdmEntitySet(container, "FakeSet", entityType);
            container.AddElement(entitySet);

            var metadataContext = new ODataMetadataContext(
                true,
                ODataReaderBehavior.DefaultBehavior.OperationsBoundToEntityTypeMustBeContainerQualified,
                new EdmTypeReaderResolver(model, ODataReaderBehavior.DefaultBehavior),
                model,
                new Uri("http://temp.org/$metadata"),
                null /*requestUri*/);

            var thing = new ODataEntry {Properties = new[] {new ODataProperty {Name = "Id", Value = 1}}};
            thing.SetAnnotation(new ODataTypeAnnotation(entitySet, entityType));
            thing.MetadataBuilder = metadataContext.GetEntityMetadataBuilderForReader(new TestJsonLightReaderEntryState { Entry = thing, SelectedProperties = new SelectedPropertiesNode("*")}, useKeyAsSegment);
            return thing;
        }
 public void UrlConventionFromAnnotationShouldReturnDefaultIfAnnotationMissing()
 {
     var container = new EdmEntityContainer("Fake", "Container");
     var model = new EdmModel();
     model.AddElement(container);
     model.AddVocabularyAnnotation(new EdmAnnotation(container, new EdmTerm("Fake", "Fake", EdmPrimitiveTypeKind.Stream), EdmNullExpression.Instance));
     UrlConvention.ForModel(model).GenerateKeyAsSegment.Should().BeFalse();
 }
 public void UrlConventionFromAnnotationShouldReturnKeyAsSegmentIfAnnotationFound()
 {
     var container = new EdmEntityContainer("Fake", "Container");
     var model = new EdmModel();
     model.AddElement(container);
     model.AddVocabularyAnnotation(new EdmAnnotation(container, UrlConventionsConstants.ConventionTerm, UrlConventionsConstants.KeyAsSegmentAnnotationValue));
     UrlConvention.ForModel(model).GenerateKeyAsSegment.Should().BeTrue();
 }
 public void UrlConventionFromAnnotationShouldReturnDefaultIfAnnotationHasWrongValue()
 {
     var container = new EdmEntityContainer("Fake", "Container");
     var model = new EdmModel();
     model.AddElement(container);
     model.AddVocabularyAnnotation(new EdmAnnotation(container, UrlConventionsConstants.ConventionTerm, new EdmStringConstant("fake")));
     UrlConvention.ForModel(model).GenerateKeyAsSegment.Should().BeFalse();
 }
        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;
        }
        public static IEdmModel EdmExpressionKindInterfaceCriticalKindValueUnexpectedOnlyModel()
        {
            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.String);

            var valueAnnotation = new EdmAnnotation(
                valueTerm,
                valueTerm,
                badString);
            model.AddVocabularyAnnotation(valueAnnotation);

            return model;
        }
        public void ConstructibleVocabularySerializingAnnotationsWithNoTerm()
        {
            var stockModel = new EdmModel();
            var customer = new EdmEntityType("NS1", "Customer");
            var customerId = customer.AddStructuralProperty("CustomerID", EdmCoreModel.Instance.GetString(false));
            customer.AddKeys(customerId);
            stockModel.AddElement(customer);

            var annotation = new MutableValueAnnotation()
            {
                Target = customer,
                Value = new EdmStringConstant("Hello world2!"),
            };
            stockModel.AddVocabularyAnnotation(annotation);

            var stringWriter = new StringWriter();
            var xmlWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings() { Indent = true });
            IEnumerable<EdmError> serializationErrors;
            stockModel.TryWriteCsdl(xmlWriter, out serializationErrors);
            xmlWriter.Close();

            Assert.AreEqual(1, serializationErrors.Count(), "Error on serialization");
        }
        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 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 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;
        }
        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;
        }
        public static IEdmModel IsTypeResultTrueEvaluationModel()
        {
            var model = new EdmModel();

            var booleanFlag = new EdmComplexType("NS", "BooleanFlag");
            var flag = booleanFlag.AddStructuralProperty("Flag", EdmCoreModel.Instance.GetBoolean(true));
            model.AddElement(booleanFlag);

            var booleanFlagTerm = new EdmTerm("NS", "BooleanFlagTerm", new EdmComplexTypeReference(booleanFlag, true));
            model.AddElement(booleanFlagTerm);

            var valueAnnotation = new EdmAnnotation(
                booleanFlag,
                booleanFlagTerm,
                new EdmRecordExpression(
                    new EdmPropertyConstructor(flag.Name, new EdmIsTypeExpression(new EdmStringConstant("foo"), EdmCoreModel.Instance.GetString(true)))));
            valueAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.OutOfLine);
            model.AddVocabularyAnnotation(valueAnnotation);

            return model;
        }
 public void AddAnnotationWithNoTarget()
 {
     var edmModel = new EdmModel();
     var annotation = new MutableValueAnnotation();
     this.VerifyThrowsException(typeof(InvalidOperationException), () => edmModel.AddVocabularyAnnotation(annotation));
 }
Beispiel #15
0
        private static void EdmWriteAnnotationDemo()
        {
            Console.WriteLine("EdmWriteAnnotationDemo");

            var model = new EdmModel();

            var mail = new EdmEntityType("ns", "Mail");
            model.AddElement(mail);
            mail.AddKeys(mail.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));

            var person = new EdmEntityType("ns", "Person");
            model.AddElement(person);
            person.AddKeys(person.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
            var mails = person.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
            {
                ContainsTarget = true,
                Name = "Mails",
                TargetMultiplicity = EdmMultiplicity.Many,
                Target = mail,
            });

            var ann1 = new EdmAnnotation(mails, CoreVocabularyModel.DescriptionTerm, new EdmStringConstant("test1"));
            ann1.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
            model.AddVocabularyAnnotation(ann1);

            var container = new EdmEntityContainer("ns", "container");
            model.AddElement(container);
            var people = container.AddEntitySet("People", person);
            var ann2 = new EdmAnnotation(people, CoreVocabularyModel.DescriptionTerm, new EdmStringConstant("test2"));
            model.AddVocabularyAnnotation(ann2);

            ShowModel(model);
        }
Beispiel #16
0
        private static void CustomTermDemo()
        {
            Console.WriteLine("CustomTermDemo");

            var model = new EdmModel();
            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 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.NotNull(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"));
        }
        private void AddStockVocabularies(IEdmModel edmModel, EdmModel stockModel)
        {
            foreach (var valueTypeTerm in edmModel.SchemaElements.OfType<IEdmValueTerm>())
            {
                var stockValueTerm = new EdmTerm(valueTypeTerm.Namespace, valueTypeTerm.Name, this.ConvertToStockTypeReference(valueTypeTerm.Type, stockModel));
                stockModel.AddElement(stockValueTerm);
            }

            foreach (var edmAnnotation in edmModel.VocabularyAnnotations.OfType<IEdmValueAnnotation>())
            {
                var stockAnnotation = new EdmAnnotation(
                    this.ConvertToStockVocabularyAnnotatable(edmAnnotation.Target, stockModel),
                    stockModel.FindValueTerm(((IEdmSchemaElement)edmAnnotation.Term).FullName()),
                    edmAnnotation.Qualifier,
                    this.ConvertToStockExpression(edmAnnotation.Value, stockModel)
                    // TODO: Do we need FullName()?  
                    // TODO: FullName() is Namespace.Name, but should it be NamespaceUri.Name? 
                    // TODO: FullName() on Annotation.Term returns Vocabulary0.TermName. Vocabulary0 is the using Alias. Is this correct? 
                    // TODO: Namepsace on Annotation.Term returns Vocabulary0, which is the using Alias. Is this correct?
                );
                stockModel.AddVocabularyAnnotation(stockAnnotation);
            }
        }
        private IEdmModel TermAppliesToAttributeModel()
        {
            var model = new EdmModel();

            var inlineWithoutAppliesToIntegerTerm = new EdmTerm("NS", "InlineWithoutAppliesToIntegerTerm", EdmCoreModel.Instance.GetInt32(true));
            model.AddElement(inlineWithoutAppliesToIntegerTerm);
            var inlineWithoutAppliesToIntegerAnnotation = new EdmAnnotation(inlineWithoutAppliesToIntegerTerm, inlineWithoutAppliesToIntegerTerm, new EdmIntegerConstant(1));
            inlineWithoutAppliesToIntegerAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
            model.AddVocabularyAnnotation(inlineWithoutAppliesToIntegerAnnotation);

            var inlineWithAppliesToIntegerTerm = new EdmTerm("NS", "InlineWithAppliesToIntegerTerm", EdmCoreModel.Instance.GetInt32(true), "Term Property");
            model.AddElement(inlineWithAppliesToIntegerTerm);
            var inlineWithAppliesToIntegerAnnotation = new EdmAnnotation(inlineWithAppliesToIntegerTerm, inlineWithAppliesToIntegerTerm, new EdmIntegerConstant(2));
            inlineWithAppliesToIntegerAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
            model.AddVocabularyAnnotation(inlineWithAppliesToIntegerAnnotation);

            var outlineWithoutAppliesToStringTerm = new EdmTerm("NS", "OutlineWithoutAppliesToStringTerm", EdmCoreModel.Instance.GetString(true));
            model.AddElement(outlineWithoutAppliesToStringTerm);
            var outlineWithoutAppliesToStringAnnotation = new EdmAnnotation(outlineWithoutAppliesToStringTerm, outlineWithoutAppliesToStringTerm, new EdmStringConstant("this is 3"));
            model.AddVocabularyAnnotation(outlineWithoutAppliesToStringAnnotation);

            var outlineWithAppliesToStringTerm = new EdmTerm("NS", "OutlineWithAppliesToStringTerm", EdmCoreModel.Instance.GetString(true), "Property Term");
            model.AddElement(outlineWithAppliesToStringTerm);
            var outlineWithAppliesToStringAnnotation = new EdmAnnotation(outlineWithAppliesToStringTerm, outlineWithAppliesToStringTerm, new EdmStringConstant("this is 4"));
            model.AddVocabularyAnnotation(outlineWithAppliesToStringAnnotation);

            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 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;
        }
        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;
        }
        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;
        }
        private IEdmModel CollectionOfEntityTypeTermModel()
        {
            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 collectionOfEntityTypeTerm = new EdmTerm("NS", "CollectionOfEntityTypeTerm", EdmCoreModel.GetCollection(new EdmEntityTypeReference(entityTypeElement, true)));
            model.AddElement(collectionOfEntityTypeTerm);

            var inlineCollectionOfEntityTypeAnnotation = new EdmAnnotation(entityTypeElement, collectionOfEntityTypeTerm, new EdmCollectionExpression(
                new EdmRecordExpression(
                    new EdmPropertyConstructor("KeyProperty", new EdmIntegerConstant(1)),
                    new EdmPropertyConstructor("IntegerProperty", new EdmIntegerConstant(111)),
                    new EdmPropertyConstructor("StringProperty", new EdmStringConstant("Inline String 111"))),
                new EdmRecordExpression(
                    new EdmPropertyConstructor("KeyProperty", new EdmIntegerConstant(2)),
                    new EdmPropertyConstructor("IntegerProperty", new EdmIntegerConstant(222)),
                    new EdmPropertyConstructor("StringProperty", new EdmStringConstant("Inline String 222"))),
                new EdmRecordExpression(
                    new EdmPropertyConstructor("KeyProperty", new EdmIntegerConstant(3)),
                    new EdmPropertyConstructor("IntegerProperty", new EdmIntegerConstant(333)),
                    new EdmPropertyConstructor("StringProperty", new EdmStringConstant("Inline String 333")))));
            inlineCollectionOfEntityTypeAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
            model.AddVocabularyAnnotation(inlineCollectionOfEntityTypeAnnotation);

            var outlineCollectionOfEntityTypeAnnotation = new EdmAnnotation(collectionOfEntityTypeTerm, collectionOfEntityTypeTerm, new EdmCollectionExpression(
                new EdmRecordExpression(
                    new EdmPropertyConstructor("KeyProperty", new EdmIntegerConstant(4)),
                    new EdmPropertyConstructor("IntegerProperty", new EdmIntegerConstant(444)),
                    new EdmPropertyConstructor("StringProperty", new EdmStringConstant("Inline String 444"))),
                new EdmRecordExpression(
                    new EdmPropertyConstructor("KeyProperty", new EdmIntegerConstant(5)),
                    new EdmPropertyConstructor("IntegerProperty", new EdmIntegerConstant(555)),
                    new EdmPropertyConstructor("StringProperty", new EdmStringConstant("Inline String 555")))));
            model.AddVocabularyAnnotation(outlineCollectionOfEntityTypeAnnotation);

            return model;
        }
Beispiel #25
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);
        }
        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;
        }
        public static IEdmModel CastResultTrueEvaluationModel()
        {
            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 EdmEntityType("NS", "Friend");
            var friendName = friend.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(false));
            friend.AddKeys(friendName);
            var friendAddress = friend.AddStructuralProperty("Address", new EdmComplexTypeReference(address, true));
            model.AddElement(friend);

            var addressRecord = new EdmRecordExpression(new EdmPropertyConstructor[] { 
                new EdmPropertyConstructor("StreetNumber", new EdmIntegerConstant(3)), 
                new EdmPropertyConstructor("StreetName", new EdmStringConstant("에O詰 갂คำŚёæ")) 
            });

            var friendAddressCast = new EdmCastExpression(addressRecord, new EdmComplexTypeReference(address, true));

            var friendTerm = new EdmTerm("NS", "FriendTerm", new EdmEntityTypeReference(friend, true));
            model.AddElement(friendTerm);

            var valueAnnotation = new EdmAnnotation(
                friend,
                friendTerm,
                new EdmRecordExpression(
                    new EdmPropertyConstructor(friendName.Name, new EdmStringConstant("foo")),
                    new EdmPropertyConstructor(friendAddress.Name, friendAddressCast)));

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

            return model;
        }
        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;
        }
        public static IEdmModel InvalidPropertyTypeUsingIsTypeOnOutOfLineAnnotationModel()
        {
            var model = new EdmModel();

            var friendName = new EdmTerm("NS", "FriendName", EdmCoreModel.Instance.GetString(true));
            model.AddElement(friendName);

            var valueAnnotation = new EdmAnnotation(
                friendName,
                friendName,
                new EdmIsTypeExpression(new EdmStringConstant("foo"), EdmCoreModel.Instance.GetString(true)));
            valueAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.OutOfLine);
            model.AddVocabularyAnnotation(valueAnnotation);

            return model;
        }
        private IEdmModel CollectionOfPrimitiveTypeTermModel()
        {
            var model = new EdmModel();

            var collectionOfPrimitiveTypeEntity = new EdmEntityType("NS", "CollectionOfPrimitiveTypeEntity");
            collectionOfPrimitiveTypeEntity.AddKeys(collectionOfPrimitiveTypeEntity.AddStructuralProperty("KeyProperty", EdmCoreModel.Instance.GetInt32(false)));
            model.AddElement(collectionOfPrimitiveTypeEntity);

            // Collection of Boolean
            var collectionOfBooleanProperty = collectionOfPrimitiveTypeEntity.AddStructuralProperty("CollectionOfBooleanProperty", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetBoolean(true)));
            var collectionOfBooleanTerm = new EdmTerm("NS", "CollectionOfBooleanTerm", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetBoolean(true)));
            model.AddElement(collectionOfBooleanTerm);
            var collectionOfBooleanAnnotation = new EdmAnnotation(collectionOfBooleanProperty, collectionOfBooleanTerm, new EdmCollectionExpression(
                new EdmBooleanConstant(true),
                new EdmBooleanConstant(false)));
            model.AddVocabularyAnnotation(collectionOfBooleanAnnotation);

            // Collection of Integer
            var collectionOfIntegerProperty = collectionOfPrimitiveTypeEntity.AddStructuralProperty("CollectionOfIntegerProperty", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetInt32(true)));
            var collectionOfIntegerTerm = new EdmTerm("NS", "CollectionOfIntegerTerm", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetInt32(true)));
            model.AddElement(collectionOfIntegerTerm);
            var collectionOfIntegerAnnotation = new EdmAnnotation(collectionOfIntegerProperty, collectionOfIntegerTerm, new EdmCollectionExpression(
                new EdmIntegerConstant(1),
                new EdmIntegerConstant(2),
                new EdmIntegerConstant(3)));
            model.AddVocabularyAnnotation(collectionOfIntegerAnnotation);

            // Collection of Floating
            var collectionOfFloatingProperty = collectionOfPrimitiveTypeEntity.AddStructuralProperty("CollectionOfFloatingProperty", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetDouble(true)));
            var collectionOfFloatingTerm = new EdmTerm("NS", "CollectionOfFloatingTerm", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetDouble(true)));
            model.AddElement(collectionOfFloatingTerm);
            var collectionOfFloatingAnnotation = new EdmAnnotation(collectionOfFloatingProperty, collectionOfFloatingTerm, new EdmCollectionExpression(
                new EdmFloatingConstant(1.23),
                new EdmFloatingConstant(99.99)));
            model.AddVocabularyAnnotation(collectionOfFloatingAnnotation);

            // Collection of Guid
            var collectionOfGuidProperty = collectionOfPrimitiveTypeEntity.AddStructuralProperty("CollectionOfGuidProperty", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetGuid(true)));
            var collectionOfGuidTerm = new EdmTerm("NS", "CollectionOfGuidTerm", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetGuid(true)));
            model.AddElement(collectionOfGuidTerm);
            var collectionOfGuidAnnotation = new EdmAnnotation(collectionOfGuidProperty, collectionOfGuidTerm, new EdmCollectionExpression(new EdmGuidConstant(new Guid("00000000-0000-0000-0000-000000000000"))));
            model.AddVocabularyAnnotation(collectionOfGuidAnnotation);

            // Collection of Binary
            var collectionOfBinaryProperty = collectionOfPrimitiveTypeEntity.AddStructuralProperty("CollectionOfBinaryProperty", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetBinary(true)));
            var collectionOfBinaryTerm = new EdmTerm("NS", "CollectionOfBinaryTerm", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetBinary(true)));
            model.AddElement(collectionOfBinaryTerm);
            var collectionOfBinaryAnnotation = new EdmAnnotation(collectionOfBinaryProperty, collectionOfBinaryTerm, new EdmCollectionExpression(
                new EdmBinaryConstant(new byte[] { 0x41, 0x42 }),
                new EdmBinaryConstant(new byte[] { 0x61, 0x62 }),
                new EdmBinaryConstant(new byte[] { 0x4A, 0x4B, 0x6A, 0x6B })));
            model.AddVocabularyAnnotation(collectionOfBinaryAnnotation);

            // Collection of Decimal
            var collectionOfDecimalProperty = collectionOfPrimitiveTypeEntity.AddStructuralProperty("CollectionOfDecimalProperty", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetDecimal(true)));
            var collectionOfDecimalTerm = new EdmTerm("NS", "CollectionOfDecimalTerm", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetDecimal(true)));
            model.AddElement(collectionOfDecimalTerm);
            var collectionOfDecimalAnnotation = new EdmAnnotation(collectionOfDecimalProperty, collectionOfDecimalTerm, new EdmCollectionExpression(
                new EdmDecimalConstant(-1.0000000000m),
                new EdmDecimalConstant(1234567890m),
                new EdmDecimalConstant(99.9999999999m)));
            collectionOfDecimalAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
            model.AddVocabularyAnnotation(collectionOfDecimalAnnotation);

            // Collection of String
            var collectionOfStringProperty = collectionOfPrimitiveTypeEntity.AddStructuralProperty("CollectionOfStringProperty", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetString(true)));
            var collectionOfStringTerm = new EdmTerm("NS", "CollectionOfStringTerm", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetString(true)));
            model.AddElement(collectionOfStringTerm);
            var collectionOfStringAnnotation = new EdmAnnotation(collectionOfStringProperty, collectionOfStringTerm, new EdmCollectionExpression(
                new EdmStringConstant("12345"),
                new EdmStringConstant("abcdABCD"),
                new EdmStringConstant("Hello World!")));
            collectionOfStringAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
            model.AddVocabularyAnnotation(collectionOfStringAnnotation);

            // Collection of DateTimeOffset
            var collectionOfDateTimeOffsetProperty = collectionOfPrimitiveTypeEntity.AddStructuralProperty("CollectionOfDateTimeOffsetProperty", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetDateTimeOffset(true)));
            var collectionOfDateTimeOffsetTerm = new EdmTerm("NS", "CollectionOfDateTimeOffsetTerm", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetDateTimeOffset(true)));
            model.AddElement(collectionOfDateTimeOffsetTerm);
            var collectionOfDateTimeOffsetAnnotation = new EdmAnnotation(collectionOfDateTimeOffsetProperty, collectionOfDateTimeOffsetTerm, new EdmCollectionExpression(
                new EdmDateTimeOffsetConstant(new DateTimeOffset(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc))),
                new EdmDateTimeOffsetConstant(new DateTimeOffset(new DateTime(2000, 12, 31, 23, 59, 59, DateTimeKind.Utc)))));
            collectionOfDateTimeOffsetAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
            model.AddVocabularyAnnotation(collectionOfDateTimeOffsetAnnotation);

            // Collection of Duration
            var collectionOfDurationProperty = collectionOfPrimitiveTypeEntity.AddStructuralProperty("CollectionOfDurationProperty", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetDuration(true)));
            var collectionOfDurationTerm = new EdmTerm("NS", "CollectionOfDurationTerm", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetDuration(true)));
            model.AddElement(collectionOfDurationTerm);
            var collectionOfDurationAnnotation = new EdmAnnotation(collectionOfDurationProperty, collectionOfDurationTerm, new EdmCollectionExpression(
                new EdmDurationConstant(new TimeSpan(1, 2, 3, 4)),
                new EdmDurationConstant(new TimeSpan(23, 59, 59))));
            collectionOfDurationAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
            model.AddVocabularyAnnotation(collectionOfDurationAnnotation);

            return model;
        }