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 ValueTerm_Collection_OnEntityType() { this.SetupModels(); IEdmEntityType person = this.baseModel.FindEntityType("NS1.Person"); IEdmValueTerm termStringValue = this.longDefinitionModel.FindValueTerm("bar.StringValue"); var collection = new EdmCollectionExpression(new EdmStringConstant("s1"), new EdmLabeledExpression("xyz", new EdmIntegerConstant(2))); this.CreateAndAttachValueAnnotation(person, termStringValue, collection); string expectedCsdl = @"<Schema Namespace=""NS1"" xmlns=""http://docs.oasis-open.org/odata/ns/edm""> <EntityType Name=""Person""> <Key> <PropertyRef Name=""Name"" /> </Key> <Property Name=""Name"" Type=""Edm.String"" Nullable=""false"" /> <Property Name=""Birthday"" Type=""Edm.DateTimeOffset"" Nullable=""false"" /> </EntityType> <Annotations Target=""NS1.Person""> <Annotation Term=""bar.StringValue""> <Collection> <String>s1</String> <LabeledElement Name=""xyz""> <Int>2</Int> </LabeledElement> </Collection> </Annotation> </Annotations> </Schema>"; this.SerializeAndVerifyAgainst(this.baseModel, expectedCsdl); }
public IEdmExpression ConvertToStockExpression(IEdmExpression edmExpression, EdmModel stockModel) { IEdmExpression result = null; switch (edmExpression.ExpressionKind) { case EdmExpressionKind.Null: result = EdmNullExpression.Instance; break; case EdmExpressionKind.StringConstant: var tempString = (IEdmStringConstantExpression)edmExpression; result = new EdmStringConstant(tempString.Type != null ? this.ConvertToStockTypeReference(tempString.Type, stockModel).AsString() : null, tempString.Value); break; case EdmExpressionKind.IntegerConstant: var tempInteger = (IEdmIntegerConstantExpression)edmExpression; result = new EdmIntegerConstant(tempInteger.Type != null ? this.ConvertToStockTypeReference(tempInteger.Type, stockModel).AsPrimitive() : null, tempInteger.Value); break; case EdmExpressionKind.Record: var tempRecord = (IEdmRecordExpression)edmExpression; result = new EdmRecordExpression( tempRecord.DeclaredType == null ? null : this.ConvertToStockTypeReference(tempRecord.DeclaredType, stockModel).AsStructured(), tempRecord.Properties.Select(edmProperty => (IEdmPropertyConstructor)new EdmPropertyConstructor(edmProperty.Name, this.ConvertToStockExpression(edmProperty.Value, stockModel)))); break; case EdmExpressionKind.Collection: var tempCollection = (IEdmCollectionExpression)edmExpression; result = new EdmCollectionExpression(tempCollection.Elements.Select(element => this.ConvertToStockExpression(element, stockModel))); break; default: throw new NotImplementedException(); } return result; }
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")); }
public void EdmCollectionExpression() { var e = new EdmCollectionExpression( new EdmLabeledExpression("l1", new EdmStringConstant("qwerty")), new EdmLabeledExpression("l2", new EdmStringConstant("qwerty2"))); Assert.IsFalse(e.IsBad(), "Expression not bad."); Assert.AreEqual(EdmExpressionKind.Collection, e.ExpressionKind, "e.ExpressionKind"); Assert.AreEqual(2, e.Elements.Count(), "e.Elements.Count()"); Assert.AreEqual("l2", ((EdmLabeledExpression)e.Elements.ElementAt(1)).Name, "((EdmLabeledElement)e.Elements.ElementAt(1)).Label"); var l1 = e.Elements.First(); e = new EdmCollectionExpression(); Assert.IsNull(e.DeclaredType, "e.DeclaredType"); Assert.AreEqual(0, e.Elements.Count(), "e.Elements.Count()"); Assert.IsFalse(e.IsBad(), "Expression not bad."); Assert.AreEqual(0, e.Errors().Count(), "Expression has no errors"); try { new EdmCollectionExpression((IEdmLabeledExpression[])null); Assert.Fail("exception expected"); } catch (ArgumentNullException) { } }
public void ConstructibleVocabularyAddingInlineValueAnnotationToExistingElement() { EdmModel model = VocabularyTestModelBuilder.InlineAnnotationSimpleModel(); var vocabularyAnnotations = model.VocabularyAnnotations; Assert.AreEqual(1, vocabularyAnnotations.Count(), "Invalid vocabulary annotation count."); var container = model.FindEntityContainer("Container") as EdmEntityContainer; Assert.IsNotNull(container, "Invalid entity container name."); EdmTerm listOfNamesTerm = new EdmTerm("AnnotationNamespace", "ListOfNames", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetString(true))); var collectionOfNames = new EdmCollectionExpression( new EdmStringConstant("Joe"), new EdmStringConstant("Mary"), new EdmLabeledExpression("Justin", new EdmStringConstant("Justin"))); EdmAnnotation valueAnnotation = new EdmAnnotation( container, listOfNamesTerm, collectionOfNames); valueAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline); model.AddVocabularyAnnotation(valueAnnotation); vocabularyAnnotations = model.VocabularyAnnotations; Assert.AreEqual(2, vocabularyAnnotations.Count(), "Invalid vocabulary annotation count."); List<PropertyValue> listOfNames = new List<PropertyValue> { new PropertyValue("Joe"), new PropertyValue("Mary"), new PropertyValue("Justin") }; var valueAnnotationFound = this.CheckForValueAnnotation(vocabularyAnnotations, EdmExpressionKind.Collection, listOfNames); Assert.IsTrue(valueAnnotationFound, "Annotation can't be found."); var containerVocabularyAnnotations = container.VocabularyAnnotations(model); valueAnnotationFound = this.CheckForValueAnnotation(containerVocabularyAnnotations, EdmExpressionKind.Collection, listOfNames); Assert.IsTrue(valueAnnotationFound, "Annotation can't be found."); }
public static IEdmModel ValueAnnotationWithCollectionComplexTypeModel() { var model = new EdmModel(); var person = new EdmComplexType("NS", "Person"); var name = person.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(true)); model.AddElement(person); var friendNames = new EdmTerm("NS", "FriendNames", EdmCoreModel.GetCollection(new EdmComplexTypeReference(person, true))); model.AddElement(friendNames); var billGatesRecord = new EdmRecordExpression(new EdmPropertyConstructor("Name", new EdmStringConstant("Bill Gates"))); var steveBRecord = new EdmRecordExpression(new EdmPropertyConstructor("Name", new EdmStringConstant("Steve B"))); var annotationValue = new EdmCollectionExpression(billGatesRecord, steveBRecord); var valueAnnotation = new EdmAnnotation( person, friendNames, annotationValue); model.AddVocabularyAnnotation(valueAnnotation); return model; }
public static IEdmModel ValueAnnotationComplexTypeWithNullValuesModel() { var model = new EdmModel(); var address = new EdmComplexType("NS", "Address"); address.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(true)); model.AddElement(address); var person = new EdmComplexType("NS", "Person"); person.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(true)); person.AddStructuralProperty("Address", new EdmComplexTypeReference(address, true)); person.AddStructuralProperty("FriendNames", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetString(true))); model.AddElement(person); var personInfoTerm = new EdmTerm("NS", "PersonInfo", new EdmComplexTypeReference(person, true)); model.AddElement(personInfoTerm); var friendNamesRecord = new EdmCollectionExpression(EdmNullExpression.Instance); var valueAnnotationRecord = new EdmRecordExpression( new EdmPropertyConstructor("Id", EdmNullExpression.Instance), new EdmPropertyConstructor("Address", EdmNullExpression.Instance), new EdmPropertyConstructor("FriendNames", friendNamesRecord)); var valueAnnotation = new EdmAnnotation( personInfoTerm, personInfoTerm, valueAnnotationRecord); valueAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.OutOfLine); model.AddVocabularyAnnotation(valueAnnotation); return model; }
public static IEdmModel SimpleValueAnnotationWithComplexTypeModel() { var model = new EdmModel(); var address = new EdmComplexType("ßÆœÇèÒöæ", "नुसौस्वागूूम"); address.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(true)); model.AddElement(address); var person = new EdmComplexType("ßÆœÇèÒöæ", "Person"); person.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(false)); person.AddStructuralProperty("Address", new EdmComplexTypeReference(address, true)); person.AddStructuralProperty("öøãçšŰŽ", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetString(true))); model.AddElement(person); var personInfoTerm = new EdmTerm("ßÆœÇèÒöæ", "PersonInfo", new EdmComplexTypeReference(person, true)); model.AddElement(personInfoTerm); var addressRecord = new EdmRecordExpression(new EdmPropertyConstructor("Name", new EdmStringConstant("Microsoft Way"))); var friendNamesRecord = new EdmCollectionExpression(new EdmStringConstant("伯唯堯帯作停捜桜噂構申表アイウ¥¥"), new EdmStringConstant("bar")); var valueAnnotationRecord = new EdmRecordExpression( new EdmPropertyConstructor("Id", new EdmIntegerConstant(7)), new EdmPropertyConstructor("Address", addressRecord), new EdmPropertyConstructor("öøãçšŰŽ", friendNamesRecord)); var valueAnnotation = new EdmAnnotation( personInfoTerm, personInfoTerm, valueAnnotationRecord); valueAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.OutOfLine); model.AddVocabularyAnnotation(valueAnnotation); return model; }