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"); }
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); }
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()); }
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); }