public void ClrTypeMappingVocabularyAnnotationEnumTest() { var edmModel = this.GetParserResult(ClrTypeMappingTestModelBuilder.VocabularyAnnotationEnumTest()); var annotations = edmModel.FindVocabularyAnnotations(edmModel.FindType("NS1.Person")); Func <string, IEdmIntegerConstantExpression> GetIntegerExpression = (termName) => { var valueAnnotation = annotations.Single(n => n.Term.Name == termName); return((IEdmIntegerConstantExpression)valueAnnotation.Value); }; Func <string, IEdmValue> GetEdmValue = (termName) => { var valueAnnotation = annotations.Single(n => n.Term.Name == termName); var edmToClrEvaluator = new EdmToClrEvaluator(null); return(edmToClrEvaluator.Evaluate(valueAnnotation.Value)); }; var edmToClrConverter = new EdmToClrConverter(); Assert.AreEqual(edmToClrConverter.AsClrValue(GetIntegerExpression("PersonValueAnnotation3"), typeof(EnumInt)), EnumInt.Member1, "It should return Infinit for Single when the value is greater than Single.MaxValue."); Assert.AreEqual(new EdmToClrEvaluator(null).EvaluateToClrValue <EnumInt>(GetIntegerExpression("PersonValueAnnotation3")), EnumInt.Member1, "It should return Infinit for Single when the value is greater than Single.MaxValue."); Assert.AreEqual(new EdmToClrEvaluator(null).EvaluateToClrValue <EnumInt>(GetIntegerExpression("PersonValueAnnotation4")), (EnumInt)(-2), "It should return Infinit for Single when the value is greater than Single.MaxValue."); #if !SILVERLIGHT this.ValidateClrObjectConverter(this.GetVocabularyAnnotations(edmModel, edmModel.FindType("NS1.Person"), "PersonValueAnnotation1").Single(), new ClassWithEnum() { EnumInt = EnumInt.Member1, EnumByte = (EnumByte)10, EnumULong = EnumULong.Member2 }); #endif this.VerifyThrowsException(typeof(InvalidCastException), () => new EdmToClrEvaluator(null).EvaluateToClrValue <EnumInt>(GetIntegerExpression("PersonValueAnnotation2"))); #if !SILVERLIGHT this.ValidateClrObjectConverter(this.GetVocabularyAnnotations(edmModel, edmModel.FindType("NS1.Person"), "PersonValueAnnotation8").Single(), new ClassWithEnum() { EnumInt = (EnumInt)10, }); #endif }