public void XElementAnnotationTestXElementWithWithoutNamespaceCsdl()
        {
            EdmModel model = new EdmModel();

            EdmComplexType complexType = new EdmComplexType("DefaultNamespace", "ComplexType");
            complexType.AddStructuralProperty("Data", EdmCoreModel.Instance.GetString(true));
            model.AddElement(complexType);

            XElement annotationElement = new XElement("EmptyAnnotation");
            var annotation = new EdmStringConstant(EdmCoreModel.Instance.GetString(false), annotationElement.ToString());
            VerifyThrowsException(typeof(InvalidOperationException), () => annotation.SetIsSerializedAsElement(model, true));
        }
Example #2
0
        public static void SetISOCurrencyMeasuresAnnotation(this EdmModel model, IEdmProperty property, string isoCurrency)
        {
            if (model == null) throw new ArgumentNullException("model");
            if (property == null) throw new ArgumentNullException("property");

            var target = property;
            var term = ISOCurrencyTerm;
            var expression = new EdmStringConstant(isoCurrency);
            var annotation = new EdmAnnotation(target, term, expression);
            annotation.SetSerializationLocation(model, property.ToSerializationLocation());
            model.AddVocabularyAnnotation(annotation);
        }
        public static EdmModel AnnotationWithoutChildrenModel()
        {
            EdmModel model = new EdmModel();

            EdmComplexType complexType = new EdmComplexType("DefaultNamespace", "ComplexType");
            complexType.AddStructuralProperty("Data", EdmCoreModel.Instance.GetString(true));
            model.AddElement(complexType);

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

            return model;
        }
        public static EdmModel NestedXElementWithNoValueModel()
        {
            EdmModel model = new EdmModel();

            EdmComplexType simpleType = new EdmComplexType("DefaultNamespace", "SimpleType");
            EdmStructuralProperty simpleTypeId = simpleType.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(true));
            model.AddElement(simpleType);

            XElement annotationElement = 
                new XElement("{http://foo}Annotation",
                    new XElement("{http://foo}Child",
                        new XElement("{http://foo}GrandChild",
                            new XElement("{http://foo}GreatGrandChild",
                                new XElement("{http://foo}GreateGreatGrandChild")
                            )
                        )
                    )
                );
            var annotation = new EdmStringConstant(EdmCoreModel.Instance.GetString(false), annotationElement.ToString());
            annotation.SetIsSerializedAsElement(model, true);
            model.SetAnnotationValue(simpleTypeId, "http://foo", "Annotation", annotation);

            return model;
        }
        public void EdmApplyExpression()
        {
            var arguments = new IEdmExpression[] { new EdmIntegerConstant(1) };
            var appliedExpression = new EdmStringConstant("foo");
            var e = new EdmApplyExpression(appliedExpression, arguments);
            Assert.AreEqual(EdmExpressionKind.OperationApplication, e.ExpressionKind, "e.ExpressionKind");
            Assert.AreEqual(appliedExpression, e.AppliedOperation, "e.AppliedFunction");
            Assert.AreEqual(arguments, e.Arguments, "e.AppliedFunction");
            Assert.IsFalse(e.IsBad(), "e good");

            var operation = new EdmFunction("NS", "function", new EdmStringTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.String), true));
            var operationReference = new EdmOperationReferenceExpression(operation);
            e = new EdmApplyExpression(operationReference, arguments);
            Assert.AreEqual(EdmExpressionKind.OperationApplication, e.ExpressionKind, "e.ExpressionKind");
            Assert.AreEqual(operationReference, e.AppliedOperation, "e.AppliedFunction");
            Assert.AreEqual(arguments, e.Arguments, "e.AppliedFunction");
            Assert.IsFalse(e.IsBad(), "e good");

            this.VerifyThrowsException(typeof(ArgumentNullException), () => new EdmApplyExpression((IEdmExpression)null, arguments));
            this.VerifyThrowsException(typeof(ArgumentNullException), () => new EdmApplyExpression((IEdmOperation)null, arguments));
            this.VerifyThrowsException(typeof(ArgumentNullException), () => new EdmApplyExpression((IEdmOperation)null, arguments.AsEnumerable()));
            this.VerifyThrowsException(typeof(ArgumentNullException), () => new EdmApplyExpression(new EdmStringConstant("foo"), null));
            this.VerifyThrowsException(typeof(ArgumentNullException), () => new EdmApplyExpression(operation, null));
            this.VerifyThrowsException(typeof(ArgumentNullException), () => new EdmApplyExpression(operation, (IEnumerable<IEdmExpression>)null));

            var ee = new MutableEdmApplyExpression();
            Assert.IsNull(ee.AppliedOperation, "ee.AppliedFunction");
            Assert.IsNull(ee.Arguments, "ee.Arguments");
            Assert.IsTrue(ee.IsBad(), "Expression is bad.");
            Assert.AreEqual(2, ee.Errors().Count(), "Expression has no errors");
        }
        public void EdmStringConstant()
        {
            var e = new EdmStringConstant("qqq");
            Assert.AreEqual(EdmExpressionKind.StringConstant, e.ExpressionKind, "e.ExpressionKind");
            Assert.IsNull(e.Type, "e.Type");
            Assert.AreEqual("qqq", e.Value, "e.Value");

            e = new EdmStringConstant(EdmCoreModel.Instance.GetString(true), "aaa");
            Assert.AreEqual(true, e.Type.IsNullable, "e.Type.IsNullable");
            Assert.AreEqual("aaa", e.Value, "e.Value");

            e = new EdmStringConstant(null, "qqq");
            Assert.IsNull(e.Type, "e.Type");

            Assert.IsFalse(e.IsBad(), "Expression not bad.");
            Assert.AreEqual(0, e.Errors().Count(), "Expression has no errors");

            try
            {
                new EdmStringConstant(null);
                Assert.Fail("exception expected.");
            }
            catch (Exception ex1)
            {
                Assert.AreEqual(typeof(ArgumentNullException), ex1.GetType(), "ArgumentNullException expected");
            }
            try
            {
                new EdmStringConstant(EdmCoreModel.Instance.GetString(true), null);
                Assert.Fail("exception expected.");
            }
            catch (Exception ex2)
            {
                Assert.AreEqual(typeof(ArgumentNullException), ex2.GetType(), "ArgumentNullException expected");
            }
        }
        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 EdmModel NavigationPropertyWithAnnotationModel()
        {
            EdmModel model = new EdmModel();

            EdmEntityType person = new EdmEntityType("DefaultNamespace", "Person");
            EdmStructuralProperty personId = person.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(false));
            person.AddKeys(personId);
            model.AddElement(person);

            EdmNavigationProperty friend = person.AddBidirectionalNavigation(
                new EdmNavigationPropertyInfo() { Name = "Friends", Target = person, TargetMultiplicity = EdmMultiplicity.One },
                new EdmNavigationPropertyInfo() { Name = "Self", TargetMultiplicity = EdmMultiplicity.One });
            IEdmNavigationProperty self = friend.Partner;

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

            return model;
        }
        public static EdmModel NestedXElementWithValueModel()
        {
            EdmModel model = new EdmModel();

            EdmOperation simpleOperation = new EdmFunction("DefaultNamespace", "SimpleFunction", EdmCoreModel.Instance.GetString(true));
            model.AddElement(simpleOperation);

            XElement annotationElement =
                new XElement("{http://foo}Annotation",
                    "1",
                    new XElement("{http://foo}Child",
                        "2",
                        new XElement("{http://foo}GrandChild",
                            "3",
                            new XElement("{http://foo}GreatGrandChild",
                                "4",
                                new XElement("{http://foo}GreateGreatGrandChild", "5")
                            )
                        )
                    )
                );
            var annotation = new EdmStringConstant(EdmCoreModel.Instance.GetString(false), annotationElement.ToString());
            annotation.SetIsSerializedAsElement(model, true);
            model.SetAnnotationValue(simpleOperation, "http://foo", "Annotation", annotation);

            return model;
        }
        private static EdmModel SetNullAnnotationNameModel()
        {
            EdmModel model = new EdmModel();

            EdmEnumType spicy = new EdmEnumType("DefaultNamespace", "Spicy");
            model.AddElement(spicy);

            XElement annotationElement =
                new XElement("{http://foo}Annotation",
                    new XElement("{http://foo1}Child",
                      "1"
                    )
                );
            var annotation = new EdmStringConstant(EdmCoreModel.Instance.GetString(false), annotationElement.ToString());
            annotation.SetIsSerializedAsElement(model, true);
            model.SetAnnotationValue(spicy, "http://foo", null, annotation);

            return model;
        }
        public static EdmModel ComplexNamespaceOverlappingModel()
        {
            EdmModel model = new EdmModel();

            EdmEntityContainer container = new EdmEntityContainer("Default", "Container");
            EdmAction simpleOperationAction = new EdmAction("Default", "SimpleFunction", EdmCoreModel.Instance.GetInt32(false));
            model.AddElement(simpleOperationAction);
            EdmActionImport simpleOperation = new EdmActionImport(container, "SimpleFunction", simpleOperationAction);
            container.AddElement(simpleOperation);
            model.AddElement(container);

            XElement annotationElement =
                new XElement("{http://foo}Annotation",
                    new XElement("{http://foo}Child",
                        new XElement("{http://foo1}GrandChild",
                            new XElement("{http://foo}GreatGrandChild",
                              "1"
                            )
                        )
                    ),
                    new XElement("{http://foo1}Child",
                        new XElement("{http://foo}GrandChild",
                          "1"
                        )
                    )
                );
            var annotation = new EdmStringConstant(EdmCoreModel.Instance.GetString(false), annotationElement.ToString());
            annotation.SetIsSerializedAsElement(model, true);
            model.SetAnnotationValue(simpleOperation, "http://foo", "Annotation", annotation);

            return model;
        }
        public static EdmModel DifferentAnnotationNamespaceModel()
        {
            EdmModel model = new EdmModel();

            EdmEntityType simpleType = new EdmEntityType("DefaultNamespace", "SimpleType");
            EdmStructuralProperty simpleTypeId = simpleType.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(false));
            simpleType.AddKeys(simpleTypeId);
            model.AddElement(simpleType);

            EdmEntityContainer container = new EdmEntityContainer("DefaultNamespace", "Container");
            EdmEntitySet simpleSet = container.AddEntitySet("SimpleSet", simpleType);

            model.AddElement(container);

            XElement annotationElement =
                new XElement("{http://foo}Annotation",
                    new XElement("{http://foo1}Child",
                        new XElement("{http://foo2}GrandChild",
                            "1"
                        )
                    )
                );
            var annotation = new EdmStringConstant(EdmCoreModel.Instance.GetString(false), annotationElement.ToString());
            annotation.SetIsSerializedAsElement(model, true);
            model.SetAnnotationValue(simpleSet, "http://foo", "Annotation", annotation);

            return model;
        }
        public static EdmModel SetChildAnnotationAsAnnotationModel()
        {
            EdmModel model = new EdmModel();

            EdmTerm note = new EdmTerm("DefaultNamespace", "Note", EdmPrimitiveTypeKind.Int16);
            model.AddElement(note);

            XElement annotationElement =
                new XElement("{http://foo}Annotation",
                    new XElement("{http://foo1}Child",
                      "1"
                    )
                );
            var annotation = new EdmStringConstant(EdmCoreModel.Instance.GetString(false), annotationElement.ToString());
            annotation.SetIsSerializedAsElement(model, true);
            model.SetAnnotationValue(note, "http://foo1", "Child", annotation);

            return model;
        }
        public static EdmModel AnnotationWithEntitySetTagInEntityContainerModel()
        {
            EdmModel model = new EdmModel();

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

            XElement annotationElement =
                new XElement("{http://foo}EntitySet",
                    "1"
                );
            var annotation = new EdmStringConstant(EdmCoreModel.Instance.GetString(false), annotationElement.ToString());
            annotation.SetIsSerializedAsElement(model, true);
            model.SetAnnotationValue(container, "http://foo", "EntitySet", annotation);

            return model;
        }
        public static EdmModel AnnotationWithSchemaTagValueModel()
        {
            EdmModel model = new EdmModel();

            EdmEntityType simpleType = new EdmEntityType("DefaultNamespace", "SimpleType");
            EdmStructuralProperty simpleTypeId = simpleType.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(false));
            simpleType.AddKeys(simpleTypeId);
            model.AddElement(simpleType);

            XElement annotationElement =
                new XElement("{http://foo}Annotation",
                    "</Schema>"
                );
            var annotation = new EdmStringConstant(EdmCoreModel.Instance.GetString(false), annotationElement.ToString());
            annotation.SetIsSerializedAsElement(model, true);
            model.SetAnnotationValue(simpleType, "http://foo", "Annotation", annotation);

            return model;
        }
        public static EdmModel AnnotationWithValueModel()
        {
            EdmModel model = new EdmModel();

            EdmOperation simpleOperation = new EdmFunction("DefaultNamespace", "SimpleFunction", EdmCoreModel.Instance.GetString(true));
            EdmOperationParameter simpleOperationId = new EdmOperationParameter(simpleOperation, "Id", EdmCoreModel.Instance.GetInt32(true));
            simpleOperation.AddParameter(simpleOperationId);
            model.AddElement(simpleOperation);

            XElement annotationElement =
                new XElement("{http://foo}Annotation",
                    "Value 1.0"
                );
            var annotation = new EdmStringConstant(EdmCoreModel.Instance.GetString(false), annotationElement.ToString());
            annotation.SetIsSerializedAsElement(model, true);
            model.SetAnnotationValue(simpleOperationId, "http://foo", "Annotation", annotation);

            return model;
        }
 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;
 }
Example #18
0
        public void EvaluateExpressionsWithoutContext()
        {
            EdmExpressionEvaluator expressionEvaluator = new EdmExpressionEvaluator(this.builtInFunctions);

            IEdmExpression integerExpression = new EdmIntegerConstant(44);
            IEdmExpression stringExpression = new EdmStringConstant("Yow!");

            IEdmValue integerValue = expressionEvaluator.Evaluate(integerExpression, null);
            IEdmValue stringValue = expressionEvaluator.Evaluate(stringExpression);

            Assert.AreEqual(44, ((IEdmIntegerValue)integerValue).Value, "Integer constant value");
            Assert.AreEqual("Yow!", ((IEdmStringValue)stringValue).Value, "String constant value");
        }
Example #19
0
        public void TestStringConstant()
        {
            var constant = new EdmStringConstant("foo");
            Assert.AreEqual(EdmValueKind.String, constant.ValueKind, "Invalid value kind.");

            this.ValidateEdmValueKindRoundTrip(EdmValueKind.String, EdmCoreModel.Instance.GetString(true), constant);
        }
        public static IEdmModel ModelWithBadElementAnnotation()
        {
            EdmModel model = new EdmModel();
            EdmEntityType customer = new EdmEntityType("Westwind", "Customer");
            EdmStructuralProperty customerID = customer.AddStructuralProperty("IDC", EdmCoreModel.Instance.GetInt32(false));
            customer.AddKeys(customerID);
            model.AddElement(customer);

            EdmEntityContainer container = new EdmEntityContainer("Westwind", "Gunk");
            model.AddElement(container);
            EdmEntitySet customers = new EdmEntitySet(container, "Customers", customer);
            container.AddElement(customers);

            XElement contacts =
                new XElement("{http://msn}Contacts",
                    new XElement("{http://msn}Contact",
                        new XElement("{http://msn}Name", "Patrick Hines"),
                        new XElement("{http://msn}Phone", "206-555-0144"),
                        new XElement("{http://msn}Address",
                            new XElement("{http://msn}Street1", "123 Main St"),
                            new XElement("{http://msn}City", "Mercer Island"),
                            new XElement("{http://msn}State", "WA"),
                            new XElement("{http://msn}Postal", "68042")
                        )
                    )
                );

            var annotation = new EdmStringConstant(EdmCoreModel.Instance.GetString(false), contacts.ToString());
            annotation.SetIsSerializedAsElement(model, true);
            model.SetAnnotationValue(customer, "http://other", "Contacts", annotation);
            return model;
        }
        public static EdmModel OperationImportParameterWithAnnotationModel()
        {
            EdmModel model = new EdmModel();

            EdmEntityContainer container = new EdmEntityContainer("Default", "Container");
            EdmAction simpleOperationAction = new EdmAction("Default", "SimpleFunction", EdmCoreModel.Instance.GetInt32(false));
            EdmOperationParameter simpleOperationName = new EdmOperationParameter(simpleOperationAction, "Name", EdmCoreModel.Instance.GetString(true));
            simpleOperationAction.AddParameter(simpleOperationName);
            model.AddElement(simpleOperationAction);
            EdmOperationImport simpleOperation = new EdmActionImport(container, "SimpleFunction", simpleOperationAction);
            container.AddElement(simpleOperation);
            model.AddElement(container);

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

            return model;
        }
 private IEdmValue ComputeValue()
 {
     IEdmStringValue value = new EdmStringConstant(new EdmStringTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.String), false), this.annotation.Value);
     value.SetIsSerializedAsElement(this.model, !this.annotation.IsAttribute);
     return value;
 }
        public static EdmModel ValueTermWithAnnotationModel()
        {
            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;
        }
Example #24
0
        /// <summary>
        /// Tries to convert the given value if it is of a type specific to the client library but still able to be mapped to EDM.
        /// </summary>
        /// <param name="primitiveValue">The value to convert.</param>
        /// <param name="type">The expected type of the value or null.</param>
        /// <param name="convertedValue">The converted value, if conversion was possible.</param>
        /// <returns>Whether or not conversion was possible.</returns>
        private static bool TryConvertClientSpecificPrimitiveValue(object primitiveValue, IEdmPrimitiveTypeReference type, out IEdmDelayedValue convertedValue)
        {
            byte[] byteArray;
            if (ClientConvert.TryConvertBinaryToByteArray(primitiveValue, out byteArray))
            {
                type = EnsurePrimitiveType(type, EdmPrimitiveTypeKind.Binary);
                convertedValue = new EdmBinaryConstant((IEdmBinaryTypeReference)type, byteArray);
                return true;
            }

            PrimitiveType clientPrimitiveType;
            if (PrimitiveType.TryGetPrimitiveType(primitiveValue.GetType(), out clientPrimitiveType))
            {
                type = EnsurePrimitiveType(type, clientPrimitiveType.PrimitiveKind);
                if (clientPrimitiveType.PrimitiveKind == EdmPrimitiveTypeKind.String)
                {
                    {
                        convertedValue = new EdmStringConstant((IEdmStringTypeReference)type, clientPrimitiveType.TypeConverter.ToString(primitiveValue));
                        return true;
                    }
                }
            }

            convertedValue = null;
            return false;
        }