Beispiel #1
0
        public EvaluationTests()
        {
            const string baseModelCsdl =
@"<Schema Namespace=""foo"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
    <Term Name=""DistantAge"" Type=""Int32"" />
    <Term Name=""NewAge"" Type=""Int32"" />
    <Term Name=""Punning0"" Type=""Boolean"" />
    <Term Name=""Punning1"" Type=""Byte"" />
    <Term Name=""Punning2"" Type=""SByte"" />
    <Term Name=""Punning3"" Type=""Int16"" />
    <Term Name=""Punning4"" Type=""Int32"" />
    <Term Name=""Punning5"" Type=""Collection(Int32)"" />
    <Term Name=""Punning6"" Type=""String"" />
    <Term Name=""Punning7"" Type=""String"" />
    <Term Name=""Punning8"" Type=""foo.Cartoon"" />
    <Term Name=""Punning9"" Type=""foo.Cartoon"" />
    <Term Name=""Punning10"" Type=""foo.RealSponsor"" />
    <Term Name=""Punning11"" Type=""foo.Pet"" />
    <Term Name=""PunningBool1"" Type=""Boolean"" />
    <Term Name=""PunningBool2"" Type=""Boolean"" />
    <Term Name=""PunningBool3"" Type=""Boolean"" />
    <Term Name=""PunningBool4"" Type=""Boolean"" />
    <Term Name=""PunningBool5"" Type=""Boolean"" />
    <Term Name=""PunningBool6"" Type=""Boolean"" />
    <Term Name=""PunningBool7"" Type=""Boolean"" />
    <Term Name=""PunningBool8"" Type=""Boolean"" />
    <Term Name=""PunningBool9"" Type=""Boolean"" />
    <Term Name=""PunningBool10"" Type=""Boolean"" />
    <Term Name=""PunningBool11"" Type=""Boolean"" />
    <Term Name=""Clear0"" Type=""foo.Address"" />
    <Term Name=""Clear1"" Type=""Byte"" />
    <Term Name=""Clear2"" Type=""SByte"" />
    <Term Name=""Clear3"" Type=""Int16"" />
    <Term Name=""Clear4"" Type=""Int32"" />
    <Term Name=""Clear6"" Type=""String"" />
    <Term Name=""Clear7"" Type=""String"" />
    <Term Name=""Clear8"" Type=""foo.Cartoon"" />
    <Term Name=""Clear10"" Type=""foo.RealSponsor"" />
    <Term Name=""Clear11"" Type=""foo.Pet"" />
    <Term Name=""ClearBool0"" Type=""Boolean"" />
    <Term Name=""ClearBool1"" Type=""Boolean"" />
    <Term Name=""ClearBool2"" Type=""Boolean"" />
    <Term Name=""ClearBool3"" Type=""Boolean"" />
    <Term Name=""ClearBool4"" Type=""Boolean"" />
    <Term Name=""ClearBool6"" Type=""Boolean"" />
    <Term Name=""ClearBool7"" Type=""Boolean"" />
    <Term Name=""ClearBool8"" Type=""Boolean"" />
    <Term Name=""ClearBool10"" Type=""Boolean"" />
    <Term Name=""ClearBool11"" Type=""Boolean"" />
    <Term Name=""CoolPersonTerm"" Type=""foo.CoolPerson"" />
    <EntityType Name=""Person"">
        <Key>
            <PropertyRef Name=""Name"" />
        </Key>
        <Property Name=""Name"" Type=""String"" Nullable=""false"" />
        <Property Name=""Birthday"" Type=""DateTimeOffset"" />
        <Property Name=""CoolnessIndex"" Type=""Int32"" />
        <Property Name=""Living"" Type=""Boolean"" />
        <Property Name=""Famous"" Type=""Boolean"" />
        <NavigationProperty Name=""Address"" Type=""foo.Address"" Nullable=""false""  />
    </EntityType>
    <EntityType Name=""LyingPerson"" BaseType=""Edm.TypeTerm"">
        <Property Name=""Handle"" Type=""String"" Nullable=""false"" />
        <Property Name=""FictionalAge"" Type=""Int32"" Nullable=""false"" />
    </EntityType>
    <EntityType Name=""CoolPerson"" BaseType=""Edm.TypeTerm"">
        <Property Name=""Sobriquet"" Type=""String"" Nullable=""false"" />
        <Property Name=""Assessment"" Type=""Int32"" Nullable=""false"" />
        <Property Name=""Street"" Type=""String"" />
    </EntityType>
    <EntityType Name=""Address"">
        <Key>
            <PropertyRef Name=""Number"" />
            <PropertyRef Name=""Street"" />
            <PropertyRef Name=""City"" />
            <PropertyRef Name=""State"" />
        </Key>
        <Property Name=""Number"" Type=""Int32"" Nullable=""false"" />
        <Property Name=""Street"" Type=""String"" Nullable=""false"" />
        <Property Name=""City"" Type=""String"" Nullable=""false"" />
        <Property Name=""State"" Type=""String"" Nullable=""false"" />
    </EntityType>
    <EntityType Name=""Cartoon"">
        <Key>
            <PropertyRef Name=""Lead"" />
        </Key>
        <Property Name=""Lead"" Type=""String"" Nullable=""false"" />
        <Property Name=""Sidekick"" Type=""String"" Nullable=""false"" />
        <NavigationProperty Name=""Sponsor"" Type=""foo.Sponsor"" Nullable=""false"" />
    </EntityType>
    <EntityType Name=""Sponsor"">
        <Key>
            <PropertyRef Name=""Name"" />
        </Key>
        <Property Name=""Name"" Type=""String"" Nullable=""false"" />
    </EntityType>
    <ComplexType Name=""Pet"">
        <Property Name=""Name"" Type=""String"" Nullable=""false"" />
        <Property Name=""Age"" Type=""Int32"" Nullable=""true"" />
        <Property Name=""Toys"" Type=""Collection(String)"" />
    </ComplexType>
    <EntityType Name=""FakeSponsor"" BaseType=""foo.Sponsor"">
        <Property Name=""Secret"" Type=""String"" />
    </EntityType>
    <EntityType Name=""RealSponsor"" BaseType=""foo.Sponsor"">
        <Property Name=""Secret"" Type=""String"" />
    </EntityType>
</Schema>";

            const string builtinFunctionsCsdl =
@"<Schema Namespace=""Functions"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
  <Function Name=""StringConcat""><ReturnType Type=""String""/>
    <Parameter Name=""String1"" Type=""String"" />
    <Parameter Name=""String2"" Type=""String"" />
  </Function>
  <Function Name=""IntegerToString""><ReturnType Type=""String""/>
    <Parameter Name=""Value"" Type=""Int64"" />
  </Function>
</Schema>";

            IEnumerable<EdmError> errors;
            CsdlReader.TryParse(new XmlReader[] { XmlReader.Create(new StringReader(baseModelCsdl)) }, out this.baseModel, out errors);
            CsdlReader.TryParse(new XmlReader[] { XmlReader.Create(new StringReader(builtinFunctionsCsdl)) }, out this.builtInFunctionsModel, out errors);

            IEdmEntityType person = (IEdmEntityType)this.baseModel.FindType("foo.Person");
            IEdmEntityType address = (IEdmEntityType)this.baseModel.FindType("foo.Address");

            EdmPropertyValue address1Number = new EdmPropertyValue("Number", new EdmIntegerConstant(null, 1));
            EdmPropertyValue address1Street = new EdmPropertyValue("Street", new EdmStringConstant(null, "Joey Ramone Place"));
            EdmPropertyValue address1City = new EdmPropertyValue("City", new EdmStringConstant(null, "New York"));
            EdmPropertyValue address1State = new EdmPropertyValue("State", new EdmStringConstant(null, "New York"));
            EdmPropertyValue[] address1Properties = new EdmPropertyValue[] { address1Number, address1Street, address1City, address1State };
            EdmStructuredValue address1Value = new EdmStructuredValue(new EdmEntityTypeReference(address, true), address1Properties);

            EdmPropertyValue person1Name = new EdmPropertyValue("Name", new EdmStringConstant(null, "Joey Ramone"));
            EdmPropertyValue person1Birthday = new EdmPropertyValue("Birthday", new EdmDateTimeOffsetConstant(null, new DateTimeOffset(new DateTime(1951, 5, 19), TimeSpan.Zero)));
            EdmPropertyValue person1CoolnessIndex = new EdmPropertyValue("CoolnessIndex", new EdmIntegerConstant(null, Int32.MaxValue));
            EdmPropertyValue person1Living = new EdmPropertyValue("Living", new EdmBooleanConstant(false));
            EdmPropertyValue person1Famous = new EdmPropertyValue("Famous", new EdmBooleanConstant(null, true));
            EdmPropertyValue person1Address = new EdmPropertyValue("Address", address1Value);

            EdmPropertyValue[] person1Properties = new EdmPropertyValue[] { person1Name, person1Birthday, person1CoolnessIndex, person1Living, person1Famous, person1Address };
            this.personValue = new EdmStructuredValue(new EdmEntityTypeReference(person, false), person1Properties);

            this.builtInFunctions = new Dictionary<IEdmOperation, Func<IEdmValue[], IEdmValue>>();

            IEdmOperation stringConcat = this.builtInFunctionsModel.FindOperations("Functions.StringConcat").Single();
            this.builtInFunctions[stringConcat] = (a) => new EdmStringConstant(((IEdmStringValue)a[0]).Value + ((IEdmStringValue)a[1]).Value);

            IEdmOperation integerToString = this.builtInFunctionsModel.FindOperations("Functions.IntegerToString").Single();
            this.builtInFunctions[integerToString] = (a) => new EdmStringConstant(((IEdmIntegerValue)a[0]).Value.ToString());
        }
Beispiel #2
0
        public void EvaluateExpressionsOnBaseType()
        {
            const string annotatingModelCsdl =
@"<Schema Namespace=""foo"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
    <EntityType Name=""Thing"">
        <Key>
            <PropertyRef Name=""ID"" />
        </Key>
        <Property Name=""ID"" Type=""Int32"" />
        <Property Name=""Value"" Type=""String"" />
    </EntityType>
    <EntityType Name=""AnotherThing"" BaseType=""Edm.TypeTerm"">
        <Property Name=""AnotherValue"" Type=""String"" />
    </EntityType>
    <Annotations Target=""foo.Thing"">
        <Annotation Term=""foo.DistantAge"" Qualifier=""Short"" Int=""27"" />
        <Annotation Term=""foo.DistantAge"" Qualifier=""VeryLong"" Int=""127"" />
    </Annotations>
    <EntityType Name=""MiddleThing"" BaseType=""foo.Thing"">
        <Property Name=""AddSome"" Type=""String"" />
    </EntityType>
    <EntityType Name=""DerivedThing"" BaseType=""foo.MiddleThing"">
        <Property Name=""AddSomeMore"" Type=""String"" />
    </EntityType>
</Schema>";

            IEnumerable<EdmError> errors;
            IEdmModel annotatingModel;
            bool parsed = CsdlReader.TryParse(new XmlReader[] { XmlReader.Create(new StringReader(annotatingModelCsdl)) }, new IEdmModel[] { this.baseModel }, out annotatingModel, out errors);
            Assert.IsTrue(parsed, "parsed");
            Assert.IsTrue(errors.Count() == 0, "No errors");

            IEdmEntityType derivedThing = (IEdmEntityType)annotatingModel.FindType("foo.DerivedThing");

            EdmPropertyValue id = new EdmPropertyValue("ID", new EdmIntegerConstant(null, 17));
            EdmPropertyValue value = new EdmPropertyValue("Value", new EdmStringConstant(null, "Very high value"));
            EdmPropertyValue addSome = new EdmPropertyValue("AddSome", new EdmStringConstant(null, "More")); 
            EdmPropertyValue addSomeMore = new EdmPropertyValue("AddSomeMore", new EdmStringConstant(null, "Much, much, more"));

            EdmPropertyValue[] thingProperties = new EdmPropertyValue[] { id, value, addSome, addSomeMore };
            IEdmStructuredValue thingValue = new EdmStructuredValue(new EdmEntityTypeReference(derivedThing, false), thingProperties);

            IEdmEntityType anotherThing = (IEdmEntityType)this.baseModel.FindType("foo.AnotherThing");
            IEdmValueTerm distantAge = this.baseModel.FindValueTerm("foo.DistantAge");

            EdmExpressionEvaluator expressionEvaluator = new EdmExpressionEvaluator(this.builtInFunctions);
            EdmToClrEvaluator clrEvaluator = new EdmToClrEvaluator(this.builtInFunctions);

            IEdmValue thingDistantAge = annotatingModel.GetTermValue(thingValue, distantAge, "Short", expressionEvaluator);
            Assert.AreEqual(27, ((IEdmIntegerValue)thingDistantAge).Value, "Term annotation value");
            Assert.AreEqual(127, annotatingModel.GetTermValue<int>(thingValue, distantAge, "VeryLong", clrEvaluator), "Term annotation value too");
        }
Beispiel #3
0
        public void EvaluateExpressionsDuplicatePropertiesTest()
        {
            var aValue = new EdmStructuredValue(null, new IEdmPropertyValue[]
            {
                new EdmPropertyValue("P1", new EdmStringConstant("aStringValueOne")),
                new EdmPropertyValue("P1", new EdmStringConstant("aStringValueTwo")),
            });
            var evaluator = new EdmExpressionEvaluator(null);
            var pathP1 = new EdmPathExpression("P1");
            Assert.AreEqual("aStringValueOne", ((IEdmStringConstantExpression)evaluator.Evaluate(pathP1, aValue)).Value, "The evaluated value is not correct.");

            aValue = new EdmStructuredValue(null, new IEdmPropertyValue[]
            {
                new EdmPropertyValue("", new EdmStringConstant("aStringValueOne")),
                new EdmPropertyValue("", new EdmStringConstant("aStringValueTwo")),
            });
            var pathEmpty = new EdmPathExpression("");
            Assert.AreEqual("aStringValueOne", ((IEdmStringConstantExpression)evaluator.Evaluate(pathEmpty, aValue)).Value, "The evaluated value is not correct.");
        }
Beispiel #4
0
        public void EvaluatePathOverValueWithManyProperties()
        {
            List<IEdmPropertyValue> contextValues = new List<IEdmPropertyValue>();
            for (int i = 0; i < 10000; i++)
            {
                contextValues.Add(new EdmPropertyValue("P" + i.ToString(), new EdmIntegerConstant(i)));
            }

            EdmStructuredValue context = new EdmStructuredValue(null, contextValues);

            EdmExpressionEvaluator evaluator = new EdmExpressionEvaluator(this.builtInFunctions);

            EdmPathExpression path = new EdmPathExpression("P0");
            IEdmValue first = evaluator.Evaluate(path, context);
            Assert.AreEqual(0, ((IEdmIntegerValue)first).Value, "Property value");

            path = new EdmPathExpression("P555");
            IEdmValue middle = evaluator.Evaluate(path, context);
            Assert.AreEqual(555, ((IEdmIntegerValue)middle).Value, "Property value");

            path = new EdmPathExpression("P9999");
            IEdmValue last = evaluator.Evaluate(path, context);
            Assert.AreEqual(9999, ((IEdmIntegerValue)last).Value, "Property value");
        }
Beispiel #5
0
        public void EvaluateExpressionsInvalidCasesTest()
        {
            Action<IEnumerable<IEdmPropertyValue>, IEnumerable<IEdmPropertyValue>> compareProperties = (expected, actual) =>
                {
                    Assert.IsTrue(expected == null && actual == null || expected.Count() == actual.Count() && !expected.Except(actual).Any(), "Actual property values are different from the expected ones.");
                };
            var pathInvalid = new EdmPathExpression("DoesNotExist.><#!");
            var pathNoSegment = new EdmPathExpression();
            var pathValid = new EdmPathExpression("P1");
            var pathValidInvalid = new EdmPathExpression("P1", "DoesNotExist.><#!");
            EdmExpressionEvaluator evaluator = new EdmExpressionEvaluator(null);

            IEdmStructuredValue aValue = new EdmStructuredValue(null, new IEdmPropertyValue[]
            {
                new EdmPropertyValue("P1", new EdmStringConstant("aStringValue")),
                new EdmPropertyValue("P3", new EdmIntegerConstant(110))
            });
            compareProperties(aValue.PropertyValues, ((IEdmStructuredValue)evaluator.Evaluate(pathNoSegment, aValue)).PropertyValues);
            this.VerifyThrowsException(typeof(InvalidOperationException), () => evaluator.Evaluate(pathNoSegment));
            this.VerifyThrowsException(typeof(InvalidOperationException), () => evaluator.Evaluate(pathNoSegment, null));
            this.VerifyThrowsException(typeof(ArgumentNullException), () => evaluator.Evaluate(pathNoSegment, aValue, null));
            this.VerifyThrowsException(typeof(InvalidOperationException), () => evaluator.Evaluate(pathInvalid, aValue));
            this.VerifyThrowsException(typeof(InvalidOperationException), () => evaluator.Evaluate(pathValid, aValue, EdmCoreModel.Instance.GetInt32(true)));
            this.VerifyThrowsException(typeof(InvalidOperationException), () => evaluator.Evaluate(pathValidInvalid, aValue));

            aValue = new EdmStructuredValue(null, new IEdmPropertyValue[] { });
            compareProperties(aValue.PropertyValues, ((IEdmStructuredValue)evaluator.Evaluate(pathNoSegment, aValue)).PropertyValues);
            this.VerifyThrowsException(typeof(InvalidOperationException), () => evaluator.Evaluate(pathInvalid, aValue));


            aValue = new MutableStructuredValue();
            compareProperties(aValue.PropertyValues, ((IEdmStructuredValue)evaluator.Evaluate(pathNoSegment, aValue)).PropertyValues);

            aValue = new EdmStructuredValue(null, new IEdmPropertyValue[]
            {
                new EdmPropertyValue("", new EdmStringConstant("aStringValue")),
                new EdmPropertyValue("", new EdmStringConstant("aStringValue")),
            });
            compareProperties(aValue.PropertyValues, ((IEdmStructuredValue)evaluator.Evaluate(pathNoSegment, aValue)).PropertyValues);
            this.VerifyThrowsException(typeof(InvalidOperationException), () => evaluator.Evaluate(pathInvalid, aValue));

            aValue = new EdmStructuredValue(null, new IEdmPropertyValue[]
            {
                new EdmPropertyValue("P1", new EdmStringConstant("aStringValueOne")),
                new EdmPropertyValue("P1", new EdmStringConstant("aStringValueTwo")),
            });
            compareProperties(aValue.PropertyValues, ((IEdmStructuredValue)evaluator.Evaluate(pathNoSegment, aValue)).PropertyValues);
            this.VerifyThrowsException(typeof(InvalidOperationException), () => evaluator.Evaluate(pathInvalid, aValue));

            aValue = new EdmStructuredValue(null, new IEdmPropertyValue[]
            {
                new MutablePropertyValue() { Value = new EdmStringConstant("aStringValueOne") },
                new EdmPropertyValue("P1", new EdmStringConstant("aStringValueTwo")),
            });
            this.VerifyThrowsException(typeof(ArgumentNullException), () => new EdmPathExpression((string)null));
            compareProperties(aValue.PropertyValues, ((IEdmStructuredValue)evaluator.Evaluate(pathNoSegment, aValue)).PropertyValues);
            Assert.AreEqual("aStringValueTwo", ((IEdmStringConstantExpression)evaluator.Evaluate(pathValid, aValue)).Value, "The evaluated value is not correct.");
        }
Beispiel #6
0
        //[TestMethod, Variation(Id = 102, SkipReason=@"[EdmLib] EdmExpressionEvaluator throws NullReferenceException when EdmStructureValue has null properties. -- postponed")]
        public void EvaluateExpressionsNullPropertiesTest()
        {
            var aValue = new EdmStructuredValue(null, null);
            EdmExpressionEvaluator evaluator = new EdmExpressionEvaluator(null);
            var path = new EdmPathExpression();
            this.VerifyThrowsException(typeof(ArgumentNullException), () => evaluator.Evaluate(path, aValue));

            path = new EdmPathExpression("path");
            this.VerifyThrowsException(typeof(ArgumentNullException), () => evaluator.Evaluate(path, aValue)); // System.NullReferenceException
        }
 public void TestStructuredValue()
 {
     var constant = new EdmStructuredValue(null, new List<IEdmPropertyValue>());
     Assert.AreEqual(EdmValueKind.Structured, constant.ValueKind, "Invalid value kind.");
 }
        private static void RunPinningTest(StringBuilder builder, params object[] keyValues)
        {
            var compositeKey = keyValues.Select((k, i) => new { Name = "prop" + i, Value = k }).ToArray();
            var allKeys = keyValues.Select(k => new[] { new { Name = "prop", Value = k } }).Concat(new[] { compositeKey });

            foreach (var key in allKeys)
            {
                if (builder.Length > 0)
                {
                    builder.AppendLine();
                }

                var properties = key.Select(p => new EdmPropertyValue(p.Name, EdmValueUtils.ConvertPrimitiveValue(p.Value, null).Value)).ToList();
                var entityType = new EdmEntityType("Fake", "Fake");
                entityType.AddKeys(properties.Select(p => new EdmStructuralProperty(entityType, p.Name, p.Value.Type)));
                var entity = new EdmStructuredValue(new EdmEntityTypeReference(entityType, false), properties);
                ODataConventionalUriBuilder uriBuilder = new ODataConventionalUriBuilder(new Uri("http://baseuri.org/"), UrlConvention.CreateWithExplicitValue(false));
                var entityInstanceUri = uriBuilder.BuildEntityInstanceUri(new Uri("http://baseuri.org/Customers"), new Collection<KeyValuePair<string, object>>(properties.Select(p => new KeyValuePair<string, object>(p.Name, ((IEdmPrimitiveValue)p.Value).ToClrValue())).ToList()), entity.Type.FullName());
                builder.Append(entityInstanceUri.OriginalString.Replace("http://baseuri.org/Customers", null).Replace("()", "%28%29"));
            }

            builder.AppendLine();
        }
        public void TestElementInterfaceCriticalEnumerableMustNotHaveNullElements()
        {
            var expectedErrors = new EdmLibTestErrors()
            {
                { null, null, EdmErrorCode.InterfaceCriticalEnumerableMustNotHaveNullElements }
            };

            EdmPropertyValue personName = new EdmPropertyValue("Name", new EdmStringConstant("foo"));
            EdmPropertyValue[] properties = new EdmPropertyValue[] { personName, null };

            var structuralValue = new EdmStructuredValue(new EdmEntityTypeReference(new EdmEntityType("", ""), false), properties);
            var actualErrors = structuralValue.Errors();

            Assert.IsTrue(structuralValue.IsBad(), "Element is expected to be bad.");
            this.CompareErrors(actualErrors, expectedErrors);
        }
        //[TestMethod, Variation(Id = 202, SkipReason = @"[EdmLib] Evaluator extension method assumes value is always EntityValue  -- postponed")]
        public void GetTermValueWithNonEntityTest()
        {
            const string annotatingModelCsdl =
@"<Schema Namespace=""foo"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
    <Term Name=""DistantAge"" Type=""Int32"" />
</Schema>";
            var aValue = new EdmStructuredValue(null, new IEdmPropertyValue[]
            {
                new EdmPropertyValue("P1", new EdmStringConstant("aStringValueOne")),
                new EdmPropertyValue("P2", new EdmStringConstant("aStringValueTwo")),
            });
            var edmModel = this.GetParserResult(new XElement[] { XElement.Parse(annotatingModelCsdl) });
            var evaluator = new EdmExpressionEvaluator(null);
            edmModel.GetTermValue(aValue, edmModel.FindValueTerm("foo.DistantAge"), evaluator);
        }
        public void EvaluateUnboundTerms()
        {
            const string applicationCsdl =
@"<Schema Namespace=""bar"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
    <Annotations Target=""bar.Person"">
        <Annotation Term=""bar.RandomTerm"" Path=""Extra"" />
    </Annotations>
    <EntityType Name=""Person"">
        <Key>
            <PropertyRef Name=""Name"" />
        </Key>
        <Property Name=""Name"" Type=""String"" Nullable=""false"" />
        <Property Name=""Decoration"" Type=""bar.Decoration"">
            <Annotation Term=""bar.DecorationTerm"" Qualifier=""Goodness"" String=""Excellent"" />
        </Property>
    </EntityType>
    <ComplexType Name=""Decoration"">
        <Property Name=""One"" Type=""Int32"" />
        <Property Name=""Two"" Type=""Int32"" />
    </ComplexType>
</Schema>";
            IEdmModel applicationModel = this.Parse(applicationCsdl);
            IEdmEntityType person = (IEdmEntityType)applicationModel.FindType("bar.Person");
            IEdmProperty personDecoration = person.FindProperty("Decoration");

            EdmToClrEvaluator evaluator = new EdmToClrEvaluator(null);

            List<IEdmPropertyValue> decorationPropertyValues = new List<IEdmPropertyValue>();
            decorationPropertyValues.Add(new EdmPropertyValue("One", new EdmIntegerConstant(1)));
            decorationPropertyValues.Add(new EdmPropertyValue("Two", new EdmIntegerConstant(2)));

            List<IEdmPropertyValue> propertyValues = new List<IEdmPropertyValue>();
            propertyValues.Add(new EdmPropertyValue("Name", new EdmStringConstant("Goober")));
            propertyValues.Add(new EdmPropertyValue("Decoration", new EdmStructuredValue(null, decorationPropertyValues)));
            propertyValues.Add(new EdmPropertyValue("Extra", new EdmStringConstant("Extra value!")));
            IEdmStructuredValue context = new EdmStructuredValue(new EdmEntityTypeReference(person, false), propertyValues);

            string random = applicationModel.GetTermValue<string>(context, "bar.RandomTerm", evaluator);
            Assert.AreEqual("Extra value!", random, "Annotation evaluated value.");

            IEdmValue randomValue = applicationModel.GetTermValue(context, "bar.RandomTerm", evaluator);
            Assert.AreEqual("Extra value!", ((IEdmStringValue)randomValue).Value, "Annotation evaluated value.");

            string goodness = applicationModel.GetTermValue<string>(personDecoration, "bar.DecorationTerm", "Goodness", evaluator);
            Assert.AreEqual("Excellent", goodness, "Annotation evaluated value.");

            IEdmValue goodnessValue = applicationModel.GetTermValue(personDecoration, "bar.DecorationTerm", "Goodness", evaluator);
            Assert.AreEqual("Excellent", ((IEdmStringValue)goodnessValue).Value, "Annotation evaluated value.");

            IEdmValueAnnotation randomTermAnnotation = applicationModel.FindVocabularyAnnotations<IEdmValueAnnotation>(person, "bar.RandomTerm").Single();
            random = evaluator.EvaluateToClrValue<string>(randomTermAnnotation.Value, context);
            Assert.AreEqual("Extra value!", random, "Annotation evaluated value.");
        }
        public void SingleModel_Annotation_OnEntityType()
        {
            const string applicationCsdl =
@"<Schema Namespace=""bar"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
    <Term Name=""MoreTransformedPersonTerm"" Type=""bar.MoreTransformedPerson"" />
    <Annotations Target=""bar.Person"">
        <Annotation Term=""bar.MoreTransformedPersonTerm"">
            <Record>
                <PropertyValue Property=""Description"" String=""I know it!"" />
            </Record>
        </Annotation>
    </Annotations>
    <EntityType Name=""MoreTransformedPerson"" BaseType=""bar.TransformedPerson"">
        <Property Name=""Description"" Type=""String"" />
    </EntityType>
    <EntityType Name=""TransformedPerson"">
        <Property Name=""Age"" Type=""Int32"" Nullable=""false"" />
    </EntityType>
    <EntityType Name=""Person"">
        <Key>
            <PropertyRef Name=""Name"" />
        </Key>
        <Property Name=""Name"" Type=""String"" Nullable=""false"" />
    </EntityType>
</Schema>";
            IEdmModel applicationModel = this.Parse(applicationCsdl);
            EdmExpressionEvaluator expressionEvaluator = new EdmExpressionEvaluator(null);

            var term = applicationModel.FindValueTerm("bar.MoreTransformedPersonTerm");
            var property = applicationModel.FindEntityType("bar.MoreTransformedPerson").FindProperty("Description");
            var fakeContextValue = new EdmStructuredValue(new EdmEntityTypeReference(applicationModel.FindEntityType("bar.Person"), true), Enumerable.Empty<IEdmPropertyValue>());
            IEdmValue valueOfAnnotation = applicationModel.GetPropertyValue(fakeContextValue, term, property, expressionEvaluator);

            Assert.AreEqual("I know it!", ((IEdmStringValue)valueOfAnnotation).Value, "Annotation evaluated value.");
        }
        private void SetupValues()
        {
            IEdmEntityType person = (IEdmEntityType)this.baseModel.FindType("foo.Person");
            IEdmEntityType professional = (IEdmEntityType)this.baseModel.FindType("foo.Professional");
            IEdmEntityType address = (IEdmEntityType)this.baseModel.FindType("foo.Address");

            // ?? no EdmComplexValue
            var zipMain = new EdmPropertyValue("Main", new EdmStringConstant("98052"));
            var zipExtension = new EdmPropertyValue("Extension", new EdmStringConstant("0000"));
            var zipValue = new EdmPropertyValue("Zip", new EdmStructuredValue(null, new EdmPropertyValue[] { zipMain, zipExtension }));

            EdmPropertyValue address1Number = new EdmPropertyValue("Number", new EdmIntegerConstant(null, 1));
            EdmPropertyValue address1Street = new EdmPropertyValue("Street", new EdmStringConstant(null, "Joey Ramone Place"));
            EdmPropertyValue address1City = new EdmPropertyValue("City", new EdmStringConstant(null, "New York"));
            EdmPropertyValue address1State = new EdmPropertyValue("State", new EdmStringConstant(null, "New York"));
            EdmPropertyValue[] address1Properties = new EdmPropertyValue[] { address1Number, address1Street, address1City, address1State, zipValue };
            EdmStructuredValue address1Value = new EdmStructuredValue(new EdmEntityTypeReference(address, true), address1Properties);

            var phoneLocal = new EdmPropertyValue("Local", new EdmIntegerConstant(9991234));
            var phoneValue = new EdmPropertyValue("WorkPhone", new EdmStructuredValue(null, new EdmPropertyValue[] { phoneLocal }));
            var contactInfoValue = new EdmPropertyValue("ContactInfo", new EdmStructuredValue(null, new EdmPropertyValue[] { phoneValue }));

            EdmPropertyValue person1Name = new EdmPropertyValue("Name", new EdmStringConstant(null, "Joey Ramone"));
            EdmPropertyValue person1Birthday = new EdmPropertyValue("Birthday", new EdmDateTimeOffsetConstant(null, new DateTimeOffset(1951, 5, 19, 0, 0, 0, TimeSpan.Zero)));
            EdmPropertyValue person1CoolnessIndex = new EdmPropertyValue("CoolnessIndex", new EdmIntegerConstant(null, Int32.MaxValue));
            EdmPropertyValue person1Living = new EdmPropertyValue("Living", new EdmBooleanConstant(false));
            EdmPropertyValue person1Famous = new EdmPropertyValue("Famous", new EdmBooleanConstant(null, true));
            EdmPropertyValue person1Address = new EdmPropertyValue("Address", address1Value);

            EdmPropertyValue[] person1Properties = new EdmPropertyValue[] { person1Name, person1Birthday, person1CoolnessIndex, person1Living, person1Famous, person1Address, contactInfoValue };
            this.personValue = new EdmStructuredValue(new EdmEntityTypeReference(person, false), person1Properties);

            this.professionalValue = new EdmStructuredValue(new EdmEntityTypeReference(professional, false), person1Properties);
        }