public void TestDeserialize_Polymorphic()
        {
            var typeHandler = new DefaultOpenApiTypeHandler();

            typeHandler.ResolveType(typeof(Base));
            typeHandler.ResolveType(typeof(Sub1));
            typeHandler.ResolveType(typeof(Sub2));

            var objects = Deserialize <OpenApiQueryResult <Base> >(@"
            {
                ""@odata.count"": 2,
                ""value"": [
                    {
                        ""@odata.type"": ""Sub1"",
                        ""baseProp"": 1,
                        ""sub1Prop"": 47.11,
                        ""subProp"": 47
                    },
                    {
                        ""@odata.type"": ""Sub2"",
                        ""baseProp"": 2,
                        ""sub2Prop"": ""Test"",
                        ""subProp"": -47
                    }
                ]
            }", typeHandler);

            Assert.AreEqual(2, objects.TotalCount);
            Assert.AreEqual(2, objects.ResultItems.Length);

            Assert.IsInstanceOfType(objects.ResultItems[0], typeof(Sub1));
            var sub1 = (Sub1)objects.ResultItems[0];

            Assert.AreEqual(1, sub1.BaseProp);
            Assert.AreEqual(47.11, sub1.Sub1Prop);
            Assert.AreEqual(47, sub1.SubProp);

            Assert.IsInstanceOfType(objects.ResultItems[1], typeof(Sub2));
            var sub2 = (Sub2)objects.ResultItems[1];

            Assert.AreEqual(2, sub2.BaseProp);
            Assert.AreEqual("Test", sub2.Sub2Prop);
            Assert.AreEqual(-47, sub2.SubProp);
        }
        public void TestDeserialize_ObjectArrays_Polymorphic()
        {
            var typeHandler = new DefaultOpenApiTypeHandler();

            typeHandler.ResolveType(typeof(Base));
            typeHandler.ResolveType(typeof(Sub1));
            typeHandler.ResolveType(typeof(Sub2));

            var objects = Deserialize <OpenApiQueryResult <ArrayWrapper <Base> > >(@"
            {
                ""@odata.count"": 2,
                ""value"": [
                    {
                        ""items"": [
                            {
                                ""@odata.type"": ""Sub1"",
                                ""baseProp"": 1,
                                ""sub1Prop"": 47.11,
                                ""subProp"": 47
                            },
                            {
                                ""@odata.type"": ""Sub2"",
                                ""baseProp"": 2,
                                ""sub2Prop"": ""Test"",
                                ""subProp"": -47
                            }
                        ]
                    },
                    {
                        ""items"": [
                            {
                                ""@odata.type"": ""Sub2"",
                                ""baseProp"": 3,
                                ""sub2Prop"": ""A"",
                                ""subProp"": -11
                            },
                            {
                                ""@odata.type"": ""Sub1"",
                                ""baseProp"": 4,
                                ""sub1Prop"": 47.14,
                                ""subProp"": 12
                            }

                        ]
                    }
                ]
            }", typeHandler);

            Assert.AreEqual(2, objects.TotalCount);
            Assert.AreEqual(2, objects.ResultItems.Length);

            Assert.AreEqual(2, objects.ResultItems[0].Items.Length);
            Assert.IsInstanceOfType(objects.ResultItems[0].Items[0], typeof(Sub1));
            Assert.AreEqual(1, ((Sub1)objects.ResultItems[0].Items[0]).BaseProp);
            Assert.AreEqual(47.11, ((Sub1)objects.ResultItems[0].Items[0]).Sub1Prop);
            Assert.AreEqual(47, ((Sub1)objects.ResultItems[0].Items[0]).SubProp);

            Assert.IsInstanceOfType(objects.ResultItems[0].Items[1], typeof(Sub2));
            Assert.AreEqual(2, ((Sub2)objects.ResultItems[0].Items[1]).BaseProp);
            Assert.AreEqual("Test", ((Sub2)objects.ResultItems[0].Items[1]).Sub2Prop);
            Assert.AreEqual(-47, ((Sub2)objects.ResultItems[0].Items[1]).SubProp);

            Assert.AreEqual(2, objects.ResultItems[1].Items.Length);
            Assert.IsInstanceOfType(objects.ResultItems[1].Items[0], typeof(Sub2));
            Assert.AreEqual(3, ((Sub2)objects.ResultItems[1].Items[0]).BaseProp);
            Assert.AreEqual("A", ((Sub2)objects.ResultItems[1].Items[0]).Sub2Prop);
            Assert.AreEqual(-11, ((Sub2)objects.ResultItems[1].Items[0]).SubProp);

            Assert.IsInstanceOfType(objects.ResultItems[1].Items[1], typeof(Sub1));
            Assert.AreEqual(4, ((Sub1)objects.ResultItems[1].Items[1]).BaseProp);
            Assert.AreEqual(47.14, ((Sub1)objects.ResultItems[1].Items[1]).Sub1Prop);
            Assert.AreEqual(12, ((Sub1)objects.ResultItems[1].Items[1]).SubProp);
        }