public void DeferredLinkTest()
        {
            IEdmModel model    = Test.OData.Utils.Metadata.TestModels.BuildTestModel();
            var       cityType = model.FindType("TestModel.CityType");

            Debug.Assert(cityType != null, "cityType != null");

            // TODO: add test cases that use relative URIs

            // Few hand-crafted payloads
            IEnumerable <PayloadReaderTestDescriptor> testDescriptors = new PayloadReaderTestDescriptor[]
            {
                // Single deferred link
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadDescriptor = new PayloadTestDescriptor(),
                    PayloadElement    = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).WithTypeAnnotation(cityType)
                                        .NavigationProperty("CityHall", "http://odata.org/CityHall"),
                    PayloadEdmModel = model
                },

                // Multiple deferred links
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadDescriptor = new PayloadTestDescriptor(),
                    PayloadElement    = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).WithTypeAnnotation(cityType)
                                        .NavigationProperty("CityHall", "http://odata.org/CityHall")
                                        .NavigationProperty("DOL", "http://odata.org/DOL"),
                    PayloadEdmModel = model
                },

                // Multiple deferred links with primitive properties in between
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadDescriptor = new PayloadTestDescriptor(),
                    PayloadElement    = PayloadBuilder.Entity("TestModel.CityType").WithTypeAnnotation(cityType)
                                        .Property("Id", PayloadBuilder.PrimitiveValue(1))
                                        .NavigationProperty("CityHall", "http://odata.org/CityHall")
                                        .Property("Name", PayloadBuilder.PrimitiveValue("Vienna"))
                                        .NavigationProperty("DOL", "http://odata.org/DOL"),
                    PayloadEdmModel = model
                },
            };

            // Add standard deferred link payloads
            testDescriptors = testDescriptors.Concat(PayloadReaderTestDescriptorGenerator.CreateDeferredNavigationLinkTestDescriptors(this.Settings, true));

            // Generate interesting payloads around the entry
            testDescriptors = testDescriptors.SelectMany(td => this.PayloadGenerator.GenerateReaderPayloads(td));

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                // Deferred links are response only.
                // TODO: Reenable Json Light support
                this.ReaderTestConfigurationProvider.ExplicitFormatConfigurations.Where(tc => !tc.IsRequest && tc.Format == ODataFormat.Atom),
                (testDescriptor, testConfiguration) =>
            {
                testDescriptor.RunTest(testConfiguration);
            });
        }
        public void ExpandedLinkTest()
        {
            IEdmModel model = Microsoft.Test.OData.Utils.Metadata.TestModels.BuildTestModel();

            // TODO: add test cases that use relative URIs

            IEnumerable <PayloadReaderTestDescriptor> testDescriptors = PayloadReaderTestDescriptorGenerator.CreateDeferredNavigationLinkTestDescriptors(this.Settings, true);

            // Generate interesting payloads around the navigation property
            // Note that this will actually expand the deferred nav links as well.
            testDescriptors = testDescriptors.SelectMany(td => this.PayloadGenerator.GenerateReaderPayloads(td));

            IEnumerable <PayloadReaderTestDescriptor> customTestDescriptors = new PayloadReaderTestDescriptor[]
            {
                // Expanded null entry
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadDescriptor = new PayloadTestDescriptor(),
                    PayloadEdmModel   = model,
                    PayloadElement    = PayloadBuilder.Entity("TestModel.CityType")
                                        .PrimitiveProperty("Id", 1)
                                        .ExpandedNavigationProperty("PoliceStation", PayloadBuilder.NullEntity()),
                },
                // Expanded null entry after another expanded collection link
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadDescriptor = new PayloadTestDescriptor(),
                    PayloadEdmModel   = model,
                    PayloadElement    = PayloadBuilder.Entity("TestModel.CityType")
                                        .PrimitiveProperty("Id", 1)
                                        .ExpandedNavigationProperty("CityHall", PayloadBuilder.EntitySet())
                                        .ExpandedNavigationProperty("PoliceStation", PayloadBuilder.NullEntity()),
                },
                // incorrect type at related end
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadDescriptor = new PayloadTestDescriptor(),
                    PayloadEdmModel   = model,
                    PayloadElement    = PayloadBuilder.Entity("TestModel.CityType")
                                        .PrimitiveProperty("Id", 1)
                                        .ExpandedNavigationProperty("PoliceStation", PayloadBuilder.Entity("TestModel.CityType")),
                    ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_EntryTypeNotAssignableToExpectedType", "TestModel.CityType", "TestModel.OfficeType"),
                },
                // Nested entry of depth 4 should fail because we set MaxNestingDepth = 3 below
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadDescriptor = new PayloadTestDescriptor(),
                    PayloadEdmModel   = model,
                    PayloadElement    = PayloadBuilder.Entity("TestModel.Person").PrimitiveProperty("Id", 1),
                    ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_MaxDepthOfNestedEntriesExceeded", "3"),
                }.InEntryWithExpandedLink(true /* isSingleton */)
                .InEntryWithExpandedLink(true)
                .InEntryWithExpandedLink(true),

                // Nested entry of depth 4 within expanded feeds should fail
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadDescriptor = new PayloadTestDescriptor(),
                    PayloadEdmModel   = model,
                    PayloadElement    = PayloadBuilder.Entity("TestModel.Person").PrimitiveProperty("Id", 1),
                    ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_MaxDepthOfNestedEntriesExceeded", "3"),
                }.InFeed()
                .InEntryWithExpandedLink(false /* isSingleton */)
                .InFeed()
                .InEntryWithExpandedLink(false)
                .InFeed()
                .InEntryWithExpandedLink(false),

                // Nested entry of depth 3 should succeed
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadDescriptor = new PayloadTestDescriptor(),
                    PayloadEdmModel   = model,
                    PayloadElement    = PayloadBuilder.Entity("TestModel.Person").PrimitiveProperty("Id", 1)
                }.InEntryWithExpandedLink(true /* isSingleton */)
                .InEntryWithExpandedLink(true),

                // Nested entry of depth 3 within expanded feeds should succeed
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadDescriptor = new PayloadTestDescriptor(),
                    PayloadEdmModel   = model,
                    PayloadElement    = PayloadBuilder.Entity("TestModel.Person").PrimitiveProperty("Id", 1)
                }.InFeed()
                .InEntryWithExpandedLink(false /* isSingleton */)
                .InFeed()
                .InEntryWithExpandedLink(false),

                // Expanded feed with a number of child entries greater than recursive depth limit should succeed.
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadDescriptor = new PayloadTestDescriptor(),
                    PayloadEdmModel   = model,
                    PayloadElement    = PayloadBuilder.EntitySet().Append(
                        PayloadBuilder.Entity("TestModel.Person").PrimitiveProperty("Id", 1),
                        PayloadBuilder.Entity("TestModel.Person").PrimitiveProperty("Id", 2),
                        PayloadBuilder.Entity("TestModel.Person").PrimitiveProperty("Id", 3),
                        PayloadBuilder.Entity("TestModel.Person").PrimitiveProperty("Id", 4),
                        PayloadBuilder.Entity("TestModel.Person").PrimitiveProperty("Id", 5)),
                }.InEntryWithExpandedLink(false /* isSingleton */)
                .InEntryWithExpandedLink(true),
            };

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors.Concat(customTestDescriptors),
                this.ReaderTestConfigurationProvider.ExplicitFormatConfigurations,
                (testDescriptor, testConfiguration) =>
            {
                testConfiguration = new ReaderTestConfiguration(testConfiguration);
                testConfiguration.MessageReaderSettings.MessageQuotas.MaxNestingDepth = 3;

                testDescriptor.RunTest(testConfiguration);
            });
        }