public void Init()
 {
     this._intType = EdmCoreModel.Instance.GetInt32(false);
     this._value1 = new EdmIntegerConstant(1);
     this._value2 = new EdmIntegerConstant(2);
     this._collection = new ClientEdmCollectionValue(this._intType, new IEdmValue[] { this._value1, this._value2 });
 }
Ejemplo n.º 2
0
        public static void SetScaleMeasuresAnnotation(this EdmModel model, IEdmProperty property, byte scale)
        {
            if (model == null) throw new ArgumentNullException("model");
            if (property == null) throw new ArgumentNullException("property");

            var target = property;
            var term = ScaleTerm;
            var expression = new EdmIntegerConstant(scale);
            var annotation = new EdmAnnotation(target, term, expression);
            annotation.SetSerializationLocation(model, property.ToSerializationLocation());
            model.AddVocabularyAnnotation(annotation);
        }
Ejemplo n.º 3
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");
        }
Ejemplo n.º 4
0
        public void TestIntegerConstant()
        {
            var constant = new EdmIntegerConstant(0);
            Assert.AreEqual(EdmValueKind.Integer, constant.ValueKind, "Invalid value kind.");

            this.ValidateEdmValueKindRoundTrip(EdmValueKind.Integer, EdmCoreModel.Instance.GetByte(true), constant);
            this.ValidateEdmValueKindRoundTrip(EdmValueKind.Integer, EdmCoreModel.Instance.GetSByte(true), constant);
            this.ValidateEdmValueKindRoundTrip(EdmValueKind.Integer, EdmCoreModel.Instance.GetInt16(true), constant);
            this.ValidateEdmValueKindRoundTrip(EdmValueKind.Integer, EdmCoreModel.Instance.GetInt32(true), constant);
            this.ValidateEdmValueKindRoundTrip(EdmValueKind.Integer, EdmCoreModel.Instance.GetInt64(true), constant);
        }
Ejemplo n.º 5
0
 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 EdmIntegerConstant()
        {
            var e = new EdmIntegerConstant(2);
            Assert.AreEqual(EdmExpressionKind.IntegerConstant, e.ExpressionKind, "e.ExpressionKind");
            Assert.IsNull(e.Type, "e.Type");
            Assert.AreEqual(2, e.Value, "e.Value");

            e = new EdmIntegerConstant(EdmCoreModel.Instance.GetInt32(true), 3);
            Assert.AreEqual(true, e.Type.IsNullable, "e.Type.IsNullable");
            Assert.AreEqual(3, e.Value, "e.Value");

            e = new EdmIntegerConstant(null, 2);
            Assert.IsNull(e.Type, "e.Type");

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