public void ClrTypeMappingValueAnnotationConvertBetweenCollectionValueToCollectionType()
        {
            var edmModel = this.GetParserResult(ClrTypeMappingTestModelBuilder.ValueAnnotationClassTypeBasicTest());

            this.VerifyThrowsException
            (
                typeof(InvalidCastException),
                () =>
                this.ValidateClrObjectConverter
                (
                    this.GetValueAnnotations(edmModel, edmModel.FindType("NS1.Person"), "MultiMonitors").Single(),
                    new List <Coordination>()
            {
                new Coordination()
                {
                    X = 10, Y = 20
                },
                new Coordination()
                {
                    X = 30, Y = 40
                }
            }
                ),
                "EdmToClr_CannotConvertEdmCollectionValueToClrType"
            );
        }
        public void ClrTypeMappingValueAnnotationEmptyValueAnnotations()
        {
            var edmModel = this.GetParserResult(ClrTypeMappingTestModelBuilder.ValueAnnotationEmptyValueAnnotations());

#if !SILVERLIGHT
            this.ValidateClrObjectConverter(this.GetValueAnnotations(edmModel, edmModel.FindType("NS1.Person"), "PersonValueAnnotation1").Single(),
                                            new ClassWithEnum()
            {
                EnumInt   = EnumInt.Member2,
                EnumByte  = EnumByte.Member1,
                EnumULong = (EnumULong)0
            });
#endif
            this.ValidateClrObjectConverter(this.GetValueAnnotations(edmModel, edmModel.FindType("NS1.Person"), "PersonValueAnnotation1").Single(), new ClassWithCollectionProperty());
            this.ValidateClrObjectConverter(this.GetValueAnnotations(edmModel, edmModel.FindType("NS1.Person"), "PersonValueAnnotation1").Single(), new ClassWithCollectionOfCollectionProperty());
            this.ValidateClrObjectConverter(this.GetValueAnnotations(edmModel, edmModel.FindType("NS1.Person"), "PersonValueAnnotation1").Single(), new DisplayCoordination());
            this.ValidateClrObjectConverter(this.GetValueAnnotations(edmModel, edmModel.FindType("NS1.Person"), "PersonValueAnnotation1").Single(), new EmptyClass());

            this.VerifyThrowsException(typeof(InvalidCastException),
                                       () =>
                                       this.ValidateClrObjectConverter(this.GetValueAnnotations(edmModel, edmModel.FindType("NS1.Person"), "PersonValueAnnotation1").Single(), (int)1)
                                       );
            this.VerifyThrowsException(typeof(ArgumentNullException),
                                       () =>
                                       this.ConvertToClrObject <int>(this.GetValueAnnotations(edmModel, edmModel.FindType("NS1.Person"), "PersonValueAnnotation2").Single())
                                       );
        }
        public void ClrTypeMappingPrimitiveTypeOverflowTest()
        {
            var edmModel    = this.GetParserResult(ClrTypeMappingTestModelBuilder.PrimitiveTypeOverflowTest());
            var annotations = edmModel.FindVocabularyAnnotations(edmModel.FindType("NS1.Person"));

            Func <string, IEdmIntegerConstantExpression> GetIntegerExpression = (termName) =>
            {
                var valueAnnotation = annotations.Single(n => n.Term.Name == termName) as IEdmValueAnnotation;
                return((IEdmIntegerConstantExpression)valueAnnotation.Value);
            };
            Func <string, IEdmFloatingConstantExpression> GetFloatExpression = (termName) =>
            {
                var valueAnnotation = annotations.Single(n => n.Term.Name == termName) as IEdmValueAnnotation;
                return((IEdmFloatingConstantExpression)valueAnnotation.Value);
            };
            Func <string, IEdmValue> GetEdmValue = (termName) =>
            {
                var valueAnnotation   = annotations.Single(n => n.Term.Name == termName) as IEdmValueAnnotation;
                var edmToClrEvaluator = new EdmToClrEvaluator(null);
                return(edmToClrEvaluator.Evaluate(valueAnnotation.Value));
            };

            var edmToClrConverter = new EdmToClrConverter();

            Assert.AreEqual(edmToClrConverter.AsClrValue(GetFloatExpression("SingleValue"), typeof(Single)), float.PositiveInfinity, "It should return Infinit for Single when the value is greater than Single.MaxValue.");
            Assert.AreEqual(edmToClrConverter.AsClrValue(GetFloatExpression("NegativeSingleValue"), typeof(Single)), float.NegativeInfinity, "It should return Negative Infinit for Single when the value is less than Single.MinValue.");
            this.VerifyThrowsException(typeof(OverflowException), () => edmToClrConverter.AsClrValue(GetEdmValue("ByteValue"), typeof(byte)));
            this.VerifyThrowsException(typeof(OverflowException), () => edmToClrConverter.AsClrValue <byte>(GetEdmValue("ByteValue")));
            this.VerifyThrowsException(typeof(OverflowException), () => new EdmToClrEvaluator(null).EvaluateToClrValue <byte>(GetIntegerExpression("ByteValue")));
            this.VerifyThrowsException(typeof(OverflowException), () => edmToClrConverter.AsClrValue(GetEdmValue("SByteValue"), typeof(sbyte)));
            this.VerifyThrowsException(typeof(OverflowException), () => edmToClrConverter.AsClrValue <sbyte>(GetEdmValue("SByteValue")));
            this.VerifyThrowsException(typeof(OverflowException), () => new EdmToClrEvaluator(null).EvaluateToClrValue <sbyte>(GetIntegerExpression("SByteValue")));
        }
        public void ClrTypeMappingValueAnnotationCollectionPropertyToNullListTest()
        {
            var edmModel        = this.GetParserResult(ClrTypeMappingTestModelBuilder.ValueAnnotationCollectionPropertyTest());
            var valueAnnotation = this.GetValueAnnotations(edmModel, edmModel.FindType("NS1.Person"), "PersonValueAnnotation").Single();

            this.VerifyThrowsException(typeof(System.ArgumentException), () => this.ConvertToClrObject <ClassWithNullCollectionProperty>(valueAnnotation));
        }
        public void ClrTypeMappingPrimitiveTypeToObject()
        {
            var edmModel   = this.GetParserResult(ClrTypeMappingTestModelBuilder.PrimitiveTypeBasicTest());
            var annotation = edmModel.FindVocabularyAnnotations(edmModel.FindType("NS1.Person")).Where(n => n.Term == edmModel.FindValueTerm("NS1.Title1")).Single();
            var edmValue   = new EdmToClrEvaluator(null).Evaluate(((IEdmValueAnnotation)annotation).Value);

            this.VerifyThrowsException(typeof(InvalidCastException), () => new EdmToClrConverter().AsClrValue <Coordination>(edmValue));
        }
        public void ClrTypeMappingVocabularyAnnotationDuplicatePropertyNameTests()
        {
            var edmModel = this.GetParserResult(ClrTypeMappingTestModelBuilder.VocabularyAnnotationDuplicatePropertyNameTest());

            this.VerifyThrowsException(typeof(InvalidCastException),
                                       () => this.ValidateClrObjectConverter(this.GetVocabularyAnnotations(edmModel, edmModel.FindType("NS1.Person"), "PersonValueAnnotation1").Single(), new ClassWithEnum())
                                       );
        }
        public void ClrTypeMappingValueAnnotationConversionToAbstractType()
        {
            this.InitializeOperationDefinitions();

            var edmModel = this.GetParserResult(ClrTypeMappingTestModelBuilder.ValueAnnotationClassTypeBasicTest());

            this.VerifyThrowsException(typeof(MissingMethodException), () => this.ConvertToClrObject <AbstractClass>(this.GetValueAnnotations(edmModel, edmModel.FindType("NS1.Person"), "Coordination").Single()));
        }
        public void ClrTypeMappingValueAnnotationInterfacePropertyTest()
        {
            var edmModel = this.GetParserResult(ClrTypeMappingTestModelBuilder.ValueAnnotationClassTypeBasicTest());

            var valueAnnotation = this.GetValueAnnotations(edmModel, edmModel.FindType("NS1.Person"), "TVDisplay").Single();

            this.VerifyThrowsException(typeof(InvalidCastException), () => this.ConvertToClrObject <ClassWithInterfaceProperty>(valueAnnotation));
        }
        public void ClrTypeMappingValueStructTypePropertyTest()
        {
            this.InitializeOperationDefinitions();

            var edmModel = this.GetParserResult(ClrTypeMappingTestModelBuilder.ValueAnnotationClassTypeBasicTest(), this.operationDeclarationModel);

            var valueAnnotation = this.GetValueAnnotations(edmModel, edmModel.FindType("NS1.Person"), "TVDisplay").Single();

            this.VerifyThrowsException(typeof(InvalidCastException), () => this.ConvertToClrObject <ClassWithStructProperty>(valueAnnotation));
        }
        public void ClrTypeMappingValueAnnotationClassTypeWithNewProperties()
        {
            var edmModel = this.GetParserResult(ClrTypeMappingTestModelBuilder.ValueAnnotationClassTypeWithNewProperties());

            var valueAnnotation = this.GetValueAnnotations(edmModel, edmModel.FindType("NS1.Person"), "RecursivePropertyWithNewProperties").Single();

            this.ValidateClrObjectConverter(valueAnnotation, new DerivedRecursiveProperty()
            {
                X = 1, Y = 2, Origin = 4
            });
        }
        public void ClrTypeMappingGenerics()
        {
            var edmModel = this.GetParserResult(ClrTypeMappingTestModelBuilder.ValueAnnotationClassTypeBasicTest());

            var valueAnnotation = this.GetValueAnnotations(edmModel, edmModel.FindType("NS1.Person"), "InspectedBy").Single();

            this.ValidateClrObjectConverter(valueAnnotation, new Person9 <string>()
            {
                Id = 10, FirstName = "Young", LastName = "Hong"
            });
        }
        public void ClrTypeMappingValueAnnotationCollectionOfCollectionPropertyTest()
        {
            var edmModel = this.GetParserResult(ClrTypeMappingTestModelBuilder.ValueAnnotationCollectionOfCollectionPropertyTest());

            var valueAnnotation = this.GetValueAnnotations(edmModel, edmModel.FindType("NS1.Person"), "PersonValueAnnotation").Single();

            this.ValidateClrObjectConverter(valueAnnotation,
                                            new ClassWithCollectionOfCollectionProperty()
            {
                C = new int[][] { new int[] { 8, 9 } }
            });
        }
        public void ClrTypeMappingPrivateConstructor()
        {
            var edmModel = this.GetParserResult(ClrTypeMappingTestModelBuilder.ValueAnnotationClassTypeBasicTest());

            var valueAnnotation = this.GetValueAnnotations(edmModel, edmModel.FindType("NS1.Person"), "InspectedBy").Single();

            this.VerifyThrowsException(typeof(MissingMethodException), () => ConvertToClrObject <Person3>(valueAnnotation));

            this.VerifyThrowsException(typeof(MissingMethodException), () => ConvertToClrObject <Person4>(valueAnnotation));

            this.VerifyThrowsException(typeof(MissingMethodException), () => ConvertToClrObject <Person5>(valueAnnotation));
        }
        public void ClrTypeMappingValueAnnotationConvertBetweenCollectionValueAndSingularObject()
        {
            var    edmModel = this.GetParserResult(ClrTypeMappingTestModelBuilder.ValueAnnotationClassTypeBasicTest());
            Action action   = null;

            action = () =>
                     this.ValidateClrObjectConverter <IEnumerable <Coordination> >(this.GetValueAnnotations(edmModel, edmModel.FindType("NS1.Person"), "TVDisplay").Single(), null);
            this.VerifyThrowsException(typeof(InvalidCastException), action);

            action = () =>
                     this.ValidateClrObjectConverter <Coordination>(this.GetValueAnnotations(edmModel, edmModel.FindType("NS1.Person"), "MultiMonitors").Single(), null);
            this.VerifyThrowsException(typeof(InvalidCastException), action);
        }
        public void ClrTypeMappingValueAnnotationClassTypeBasicTest()
        {
            this.InitializeOperationDefinitions();

            var edmModel = this.GetParserResult(ClrTypeMappingTestModelBuilder.ValueAnnotationClassTypeBasicTest(), this.operationDeclarationModel);

            this.ValidateClrObjectConverter(this.GetValueAnnotations(edmModel, edmModel.FindType("NS1.Person"), "Coordination").Single(),
                                            new Coordination()
            {
                X = 10, Y = 20
            });
            this.ValidateClrObjectConverter(this.GetValueAnnotations(edmModel, edmModel.FindType("NS1.Person"), "InspectedBy").Single(),
                                            new Person()
            {
                Id = 10, FirstName = "Young", LastName = "Hong"
            });
            this.ValidateClrObjectConverter(this.GetValueAnnotations(edmModel, edmModel.FindType("NS1.Person"), "TVDisplay").Single(),
                                            new DisplayCoordination()
            {
                X = 10, Y = 20, Origin = new Coordination()
                {
                    X = 10, Y = 20
                }
            });
            this.ValidateClrObjectConverter(this.GetValueAnnotations(edmModel, edmModel.FindType("NS1.Person"), "TVDisplay").Single(),
                                            new Coordination()
            {
                X = 10, Y = 20
            });
            this.ValidateClrObjectConverter(this.GetValueAnnotations(edmModel, edmModel.FindType("NS1.Person"), "MultiMonitors").Single(),
                                            (IEnumerable <Coordination>) new List <Coordination>()
            {
                new Coordination()
                {
                    X = 10, Y = 20
                }, new Coordination()
                {
                    X = 30, Y = 40
                }
            });
            this.ValidateClrObjectConverter(this.GetValueAnnotations(edmModel, edmModel.FindType("NS1.Person"), "LabledMultiMonitors").Single(),
                                            (IEnumerable <Coordination>) new List <Coordination>()
            {
                new Coordination()
                {
                    X = 10, Y = 20
                }
            });
            this.ValidateClrObjectConverter(this.GetValueAnnotations(edmModel, edmModel.FindType("NS1.Person"), "EmptyCollection").Single(),
                                            (IEnumerable <Coordination>) new List <Coordination>());
        }
        public void ClrTypeMappingValueAnnotationConversionToStructType()
        {
            var edmModel = this.GetParserResult(ClrTypeMappingTestModelBuilder.ValueAnnotationClassTypeBasicTest());

            this.VerifyThrowsException(typeof(InvalidCastException), () => this.ValidateClrObjectConverter(this.GetValueAnnotations(edmModel, edmModel.FindType("NS1.Person"), "Coordination").Single(), new Display1StructType()));
            this.VerifyThrowsException(typeof(InvalidCastException), () => this.ValidateClrObjectConverter(this.GetValueAnnotations(edmModel, edmModel.FindType("NS1.Person"), "TVDisplay").Single(), new Display2StructTypeWithObjectProperty()
            {
                X = 10, Y = 20, Origin = new Display1()
            }));
            this.VerifyThrowsException(typeof(InvalidCastException), () => this.ValidateClrObjectConverter(this.GetValueAnnotations(edmModel, edmModel.FindType("NS1.Person"), "TVDisplay").Single(), new Display2StructTypeWithStructProperty()
            {
                X = 10, Y = 20, Origin = new Display1StructType()
            }));
        }
Exemple #17
0
        public void ClrTypeMappingVocabularyAnnotationClassTypeRecursiveTest()
        {
            var edmModel = this.GetParserResult(ClrTypeMappingTestModelBuilder.VocabularyAnnotationClassTypeRecursiveTest());

            var valueAnnotation = this.GetVocabularyAnnotations(edmModel, edmModel.FindType("NS1.Person"), "RecursiveProperty").Single();

            this.ValidateClrObjectConverter(valueAnnotation, new RecursiveProperty()
            {
                X = 1, Y = 2, Origin = new RecursiveProperty()
                {
                    X = 3, Y = 4
                }
            });
        }
        public void ClrTypeMappingValueAnnotationTryPopulateObjectInstance()
        {
            this.InitializeOperationDefinitions();

            EdmToClrEvaluator ev = new EdmToClrEvaluator(this.operationDefinitions);

            var edmModel = this.GetParserResult(ClrTypeMappingTestModelBuilder.ValueAnnotationClassTypeBasicTest(), this.operationDeclarationModel);
            var value    = ev.Evaluate(this.GetValueAnnotations(edmModel, edmModel.FindType("NS1.Person"), "TVDisplay").Single().Value);

            var    isObjectPopulated     = false;
            var    isObjectInitialized   = true;
            object createdObjectInstance = new Display1()
            {
                X = 0, Y = 1
            };
            TryCreateObjectInstance tryCreateObjectInstance = (IEdmStructuredValue edmValue, Type clrType, EdmToClrConverter converter, out object objectInstance, out bool objectInstanceInitialized) =>
            {
                objectInstance            = createdObjectInstance;
                objectInstanceInitialized = isObjectPopulated;
                return(isObjectInitialized);
            };

            ev.EdmToClrConverter = new EdmToClrConverter(tryCreateObjectInstance);

            this.VerifyThrowsException(typeof(InvalidCastException), () => ev.EdmToClrConverter.AsClrValue(value, typeof(Display2)));

            isObjectPopulated     = false;
            isObjectInitialized   = false;
            createdObjectInstance = new Display1()
            {
                X = 0, Y = 1
            };
            ev.EdmToClrConverter = new EdmToClrConverter(tryCreateObjectInstance);
            Assert.IsTrue(CompareObjects((Display2)ev.EdmToClrConverter.AsClrValue(value, typeof(Display2)), new Display2()
            {
                X = 10, Y = 20, Origin = new Display1()
                {
                    X = 10, Y = 20
                }
            }), "The returned object has incorrect values.");

            isObjectPopulated     = true;
            isObjectInitialized   = true;
            createdObjectInstance = new Display1()
            {
                X = 0, Y = 1
            };
            ev.EdmToClrConverter = new EdmToClrConverter(tryCreateObjectInstance);
            this.VerifyThrowsException(typeof(InvalidCastException), () => ev.EdmToClrConverter.AsClrValue(value, typeof(Display2)));
        }
        public void ClrTypeMappingValueAnnotationVirtualMemberTest()
        {
            var edmModel = this.GetParserResult(ClrTypeMappingTestModelBuilder.ValueAnnotationClassTypeBasicTest());

            var valueAnnotation = this.GetValueAnnotations(edmModel, edmModel.FindType("NS1.Person"), "TVDisplay").Single();

            this.ValidateClrObjectConverter(valueAnnotation, new ClassWithVirtualMember()
            {
                X = 10
            });
            this.ValidateClrObjectConverter(valueAnnotation, new DerivedClassWithVirtualMember()
            {
                X = 10
            });
        }
Exemple #20
0
        public void ClrTypeMappingPrivateProperties()
        {
            var edmModel = this.GetParserResult(ClrTypeMappingTestModelBuilder.VocabularyAnnotationClassTypeBasicTest());

            var valueAnnotation = this.GetVocabularyAnnotations(edmModel, edmModel.FindType("NS1.Person"), "InspectedBy").Single();

            this.ValidateClrObjectConverter(valueAnnotation, new Person6());

            this.ValidateClrObjectConverter(valueAnnotation, new Person7()
            {
                Id = 10
            });

            Person8 actual = ConvertToClrObject <Person8>(valueAnnotation);

            Assert.AreEqual(10, actual.Id, "Failed");
            Assert.AreEqual("Young", actual.FirstName, "Failed");
        }
        public void ClrTypeMappingDifferentPropertyTypes()
        {
            this.InitializeOperationDefinitions();

            var edmModel = this.GetParserResult(ClrTypeMappingTestModelBuilder.ValueAnnotationClassTypeBasicTest(), this.operationDeclarationModel);

            var valueAnnotation = this.GetValueAnnotations(edmModel, edmModel.FindType("NS1.Person"), "TVDisplay").Single();

            this.ValidateClrObjectConverter(valueAnnotation, new Display2()
            {
                X = 10, Y = 20, Origin = new Display1()
                {
                    X = 10, Y = 20
                }
            });
            this.ValidateClrObjectConverter(valueAnnotation, new Display1()
            {
                X = 10, Y = 20
            });
        }
        public void ClrTypeMappingValueAnnotationEnumTest()
        {
            var edmModel    = this.GetParserResult(ClrTypeMappingTestModelBuilder.ValueAnnotationEnumTest());
            var annotations = edmModel.FindVocabularyAnnotations(edmModel.FindType("NS1.Person"));

            Func <string, IEdmIntegerConstantExpression> GetIntegerExpression = (termName) =>
            {
                var valueAnnotation = annotations.Single(n => n.Term.Name == termName) as IEdmValueAnnotation;
                return((IEdmIntegerConstantExpression)valueAnnotation.Value);
            };

            Func <string, IEdmValue> GetEdmValue = (termName) =>
            {
                var valueAnnotation   = annotations.Single(n => n.Term.Name == termName) as IEdmValueAnnotation;
                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.GetValueAnnotations(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.GetValueAnnotations(edmModel, edmModel.FindType("NS1.Person"), "PersonValueAnnotation8").Single(),
                                            new ClassWithEnum()
            {
                EnumInt = (EnumInt)10,
            });
#endif
        }
        public void ClrTypeMappingInterface()
        {
            this.InitializeOperationDefinitions();

            var edmModel = this.GetParserResult(ClrTypeMappingTestModelBuilder.ValueAnnotationClassTypeBasicTest(), this.operationDeclarationModel);

            this.ValidateClrObjectConverter(this.GetValueAnnotations(edmModel, edmModel.FindType("NS1.Person"), "Coordination").Single(),
                                            new Coordination2()
            {
                X = 10, Y = 20
            });
            this.ValidateClrObjectConverter(this.GetValueAnnotations(edmModel, edmModel.FindType("NS1.Person"), "InspectedBy").Single(),
                                            new Person2()
            {
                Id = 10, FirstName = "Young", LastName = "Hong"
            });
            this.ValidateClrObjectConverter(this.GetValueAnnotations(edmModel, edmModel.FindType("NS1.Person"), "AdoptPet").Single(),
                                            new Pet()
            {
                Name = "Jacquine", Breed = "Bull Dog", Age = 3
            });
        }
        public void ClrTypeMappingValueAnnotationCollectionPropertyTest()
        {
            var edmModel = this.GetParserResult(ClrTypeMappingTestModelBuilder.ValueAnnotationCollectionPropertyTest());

            var valueAnnotation = this.GetValueAnnotations(edmModel, edmModel.FindType("NS1.Person"), "PersonValueAnnotation").Single();

            this.ValidateClrObjectConverter(valueAnnotation,
                                            new ClassWithCollectionProperty()
            {
                X = new int[] { 4, 5 },
                Y = new int[] { 6, 7 },
                Z = new int[] { 8, 9 },
                C = new Display1[] {
                    new Display1()
                    {
                        X = 10, Y = 11
                    },
                    new Display1()
                    {
                        X = 12, Y = 13
                    }
                },
            });
        }
        public void ClrTypeMappingValueAnnotationTryCreateObjectInstance()
        {
            this.InitializeOperationDefinitions();

            EdmToClrEvaluator ev = new EdmToClrEvaluator(this.operationDefinitions);

            var edmModel = this.GetParserResult(ClrTypeMappingTestModelBuilder.ValueAnnotationClassTypeBasicTest(), this.operationDeclarationModel);
            var value    = ev.Evaluate(this.GetValueAnnotations(edmModel, edmModel.FindType("NS1.Person"), "TVDisplay").Single().Value);

            var    isObjectPopulated     = true;
            var    isObjectInitialized   = true;
            object createdObjectInstance = null;
            TryCreateObjectInstance tryCreateObjectInstance = (IEdmStructuredValue edmValue, Type clrType, EdmToClrConverter converter, out object objectInstance, out bool objectInstanceInitialized) =>
            {
                objectInstance            = createdObjectInstance;
                objectInstanceInitialized = isObjectPopulated;
                return(isObjectInitialized);
            };

            ev.EdmToClrConverter = new EdmToClrConverter(tryCreateObjectInstance);
            Assert.IsNull((Display2)ev.EdmToClrConverter.AsClrValue(value, typeof(Display2)), "The returned object should be null.");

            isObjectPopulated    = false;
            isObjectInitialized  = true;
            ev.EdmToClrConverter = new EdmToClrConverter(tryCreateObjectInstance);
            Assert.IsNull((Display2)ev.EdmToClrConverter.AsClrValue(value, typeof(Display2)), "The returned object should be null.");

            isObjectPopulated    = true;
            isObjectInitialized  = false;
            ev.EdmToClrConverter = new EdmToClrConverter(tryCreateObjectInstance);
            Assert.IsTrue(CompareObjects((Display2)ev.EdmToClrConverter.AsClrValue(value, typeof(Display2)), new Display2()
            {
                X = 10, Y = 20, Origin = new Display1()
                {
                    X = 10, Y = 20
                }
            }), "The returned object has incorrect values.");

            isObjectPopulated    = false;
            isObjectInitialized  = false;
            ev.EdmToClrConverter = new EdmToClrConverter(tryCreateObjectInstance);
            Assert.IsTrue(CompareObjects((Display2)ev.EdmToClrConverter.AsClrValue(value, typeof(Display2)), new Display2()
            {
                X = 10, Y = 20, Origin = new Display1()
                {
                    X = 10, Y = 20
                }
            }), "The returned object has incorrect values.");

            createdObjectInstance = new Display2()
            {
                X = 0, Y = 1, Origin = new Display1 {
                    X = 3, Y = 4
                }
            };
            isObjectPopulated    = true;
            isObjectInitialized  = true;
            ev.EdmToClrConverter = new EdmToClrConverter(tryCreateObjectInstance);
            Assert.IsTrue(CompareObjects((Display2)ev.EdmToClrConverter.AsClrValue(value, typeof(Display2)), createdObjectInstance), "The returned object has incorrect values.");

            ev.EdmToClrConverter = new EdmToClrConverter((IEdmStructuredValue edmValue, Type clrType, EdmToClrConverter converter, out object objectInstance, out bool objectInstanceInitialized) =>
            {
                if (clrType == typeof(Display2))
                {
                    objectInstance = new Display2()
                    {
                        X = 0, Y = 1, Origin = new Display1 {
                            X = 3, Y = 4
                        }
                    };
                    objectInstanceInitialized = false;
                    return(true);
                }
                else if (clrType == typeof(Display1))
                {
                    objectInstance = new Display1 {
                        X = 3, Y = 4
                    };
                    objectInstanceInitialized = false;
                    return(true);
                }
                else
                {
                    objectInstance            = null;
                    objectInstanceInitialized = false;
                    return(false);
                }
            });
            Assert.IsTrue(CompareObjects((Display2)ev.EdmToClrConverter.AsClrValue(value, typeof(Display2)), new Display2()
            {
                X = 10, Y = 20, Origin = new Display1()
                {
                    X = 10, Y = 20
                }
            }), "The returned object has incorrect values.");

            isObjectPopulated     = false;
            isObjectInitialized   = true;
            createdObjectInstance = new DisplayCoordination();
            ev.EdmToClrConverter  = new EdmToClrConverter(tryCreateObjectInstance);
            Coordination actual   = (Coordination)ev.EdmToClrConverter.AsClrValue(value, typeof(Coordination));
            Coordination expected = new Coordination()
            {
                X = 10, Y = 20
            };

            Assert.AreEqual(expected.X, actual.X, "The returned object has incorrect values. X");
            Assert.AreEqual(expected.Y, actual.Y, "The returned object has incorrect values. X");
        }