Beispiel #1
0
        public void NullValueNonPropertyErrorTests()
        {
            EdmModel model = new EdmModel();
            var entityType = model.EntityType("OwningType", "TestModel").KeyProperty("ID", EdmCoreModel.Instance.GetInt32(false) as EdmTypeReference);
            model.EntityContainer("DefaultContainer");
            var entitySet = model.EntitySet("EntitySet", entityType);

            IEnumerable<PayloadReaderTestDescriptor> testDescriptors = new[]
            {
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "null collection - should fail.",
                    PayloadEdmModel = model,
                    PayloadElement = PayloadBuilder.PrimitiveCollection().ExpectedCollectionItemType(EdmDataTypes.Int32)
                        .JsonRepresentation(
                            "{" + 
                            "\"@odata.context\":\"http://odata.org/test/$metadata#Edm.Null\"" +
                            "}"),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightContextUriParser_ContextUriDoesNotMatchExpectedPayloadKind", "http://odata.org/test/$metadata#Edm.Null", "Collection")
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "null entry - should fail.",
                    PayloadEdmModel = model,
                    PayloadElement = PayloadBuilder.NullEntity().ExpectedEntityType(entityType, entitySet)
                        .JsonRepresentation(
                            "{" + 
                            "\"@odata.context\":\"http://odata.org/test/$metadata#Edm.Null\"" +
                            "}"),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightContextUriParser_ContextUriDoesNotMatchExpectedPayloadKind", "http://odata.org/test/$metadata#Edm.Null", "Entry")
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "null feed - should fail.",
                    PayloadEdmModel = model,
                    PayloadElement = PayloadBuilder.EntitySet().ExpectedEntityType(entityType, entitySet)
                        .JsonRepresentation(
                            "{" + 
                            "\"@odata.context\":\"http://odata.org/test/$metadata#Edm.Null\"" +
                            "}"),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightContextUriParser_ContextUriDoesNotMatchExpectedPayloadKind", "http://odata.org/test/$metadata#Edm.Null", "Feed")
                },
            };

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.JsonLightFormatConfigurations,
                (testDescriptor, testConfiguration) =>
                {
                    if (testConfiguration.IsRequest)
                    {
                        return;
                    }

                    // These descriptors are already tailored specifically for Json Light and 
                    // do not require normalization.
                    testDescriptor.TestDescriptorNormalizers.Clear();
                    testDescriptor.RunTest(testConfiguration);
                });
        }
        public void ActionAndFunctionTest()
        {
            // <m:action Metadata=URI title?="title" target=URI />

            Uri actionMetadata = new Uri("http://odata.org/test/$metadata#defaultAction");
            Uri actionMetadata2 = new Uri("#action escaped relative metadata", UriKind.Relative);
            Uri actionMetadata3 = new Uri("../#action escaped relative metadata", UriKind.Relative);
            string actionTitle = "Default Action";
            Uri actionTarget = new Uri("http://odata.org/defaultActionTarget");
            Uri actionTarget2 = new Uri("http://odata.org/defaultActionTarget2");

            ODataAction action_r1_t1 = new ODataAction() { Metadata = actionMetadata, Title = actionTitle, Target = actionTarget };
            ODataAction action_r1_t2 = new ODataAction() { Metadata = actionMetadata, Title = actionTitle, Target = actionTarget2 };
            ODataAction action_r2_t1 = new ODataAction() { Metadata = actionMetadata2, Title = actionTitle, Target = actionTarget };
            ODataAction action_r3_t1 = new ODataAction() { Metadata = actionMetadata3, Title = actionTitle, Target = actionTarget };

            Uri functionMetadata = new Uri("http://odata.org/test/$metadata#defaultFunction");
            Uri functionMetadata2 = new Uri("#function escaped relative metadata", UriKind.Relative);
            Uri functionMetadata3 = new Uri("\\#function escaped relative metadata", UriKind.Relative);
            string functionTitle = "Default Function";
            Uri functionTarget = new Uri("http://odata.org/defaultFunctionTarget");
            Uri functionTarget2 = new Uri("http://odata.org/defaultFunctionTarget2");

            ODataFunction function_r1_t1 = new ODataFunction() { Metadata = functionMetadata, Title = functionTitle, Target = functionTarget };
            ODataFunction function_r1_t2 = new ODataFunction() { Metadata = functionMetadata, Title = functionTitle, Target = functionTarget2 };
            ODataFunction function_r2_t1 = new ODataFunction() { Metadata = functionMetadata2, Title = functionTitle, Target = functionTarget };
            ODataFunction function_r3_t1 = new ODataFunction() { Metadata = functionMetadata3, Title = functionTitle, Target = functionTarget };

            var actionCases = new[]
            {
                new {
                    ODataActions = new ODataAction[] { action_r1_t1 },
                    Atom = GetAtom(action_r1_t1),
                    JsonLight = GetJsonLightForRelGroup(action_r1_t1),
                },
                new {
                    ODataActions = new ODataAction[] { action_r1_t1, action_r1_t2 },
                    Atom = GetAtom(action_r1_t1) + GetAtom(action_r1_t2),
                    JsonLight = GetJsonLightForRelGroup(action_r1_t1, action_r1_t2),
                },
                new {
                    ODataActions = new ODataAction[] { action_r1_t1, action_r2_t1 },
                    Atom = GetAtom(action_r1_t1) + GetAtom(action_r2_t1),
                    JsonLight = GetJsonLightForRelGroup(action_r1_t1) + "," + GetJsonLightForRelGroup(action_r2_t1),
                },
                new {
                    ODataActions = new ODataAction[] { action_r1_t1, action_r2_t1, action_r1_t2 },
                    Atom = GetAtom(action_r1_t1) + GetAtom(action_r2_t1) + GetAtom(action_r1_t2),
                    JsonLight = GetJsonLightForRelGroup(action_r1_t1, action_r1_t2) + "," + GetJsonLightForRelGroup(action_r2_t1),
                },
                new {
                    ODataActions = new ODataAction[] { action_r3_t1 },
                    Atom = GetAtom(action_r3_t1),
                    JsonLight = GetJsonLightForRelGroup(action_r3_t1),
                },
            };

            var functionCases = new[]
            {
                new {
                    ODataFunctions = new ODataFunction[] { function_r1_t1 },
                    Atom = GetAtom(function_r1_t1),
                    JsonLight = GetJsonLightForRelGroup(function_r1_t1),
                },
                new {
                    ODataFunctions = new ODataFunction[] { function_r1_t1, function_r1_t2 },
                    Atom = GetAtom(function_r1_t1) + GetAtom(function_r1_t2),
                    JsonLight = GetJsonLightForRelGroup(function_r1_t1, function_r1_t2),
                },
                new {
                    ODataFunctions = new ODataFunction[] { function_r1_t1, function_r2_t1 },
                    Atom = GetAtom(function_r1_t1) + GetAtom(function_r2_t1),
                    JsonLight = GetJsonLightForRelGroup(function_r1_t1) + "," + GetJsonLightForRelGroup(function_r2_t1),
                },
                new {
                    ODataFunctions = new ODataFunction[] { function_r1_t1, function_r2_t1, function_r1_t2 },
                    Atom = GetAtom(function_r1_t1) + GetAtom(function_r2_t1) + GetAtom(function_r1_t2),
                    JsonLight = GetJsonLightForRelGroup(function_r1_t1, function_r1_t2) + "," + GetJsonLightForRelGroup(function_r2_t1),
                },
                new {
                    ODataFunctions = new ODataFunction[] { function_r3_t1 },
                    Atom = GetAtom(function_r3_t1),
                    JsonLight = GetJsonLightForRelGroup(function_r3_t1),
                },
            };

            var queryResults =
                from actionCase in actionCases
                from functionCase in functionCases
                select new
                {
                    actionCase.ODataActions,
                    functionCase.ODataFunctions,
                    Atom = string.Concat(actionCase.Atom, functionCase.Atom),
                    JsonLight = string.Join(",", new[] { actionCase.JsonLight, functionCase.JsonLight }.Where(x => x != null))
                };

            EdmModel model = new EdmModel();
            EdmEntityType edmEntityTypeCustomer = model.EntityType("Customer", "TestModel");
            EdmEntityContainer edmEntityContainer = model.EntityContainer("DefaultContainer","TestModel" );
            EdmEntitySet edmEntitySetCustermors = model.EntitySet("Customers", edmEntityTypeCustomer);

            var testDescriptors = queryResults.Select(testCase =>
            {
                ODataEntry entry = ObjectModelUtils.CreateDefaultEntry("TestModel.Customer");

                if (testCase.ODataActions != null)
                {
                    foreach (var action in testCase.ODataActions)
                    {
                        entry.AddAction(action);
                    }
                }

                if (testCase.ODataFunctions != null)
                {
                    foreach (var function in testCase.ODataFunctions)
                    {
                        entry.AddFunction(function);
                    }
                }

                return new PayloadWriterTestDescriptor<ODataItem>(
                    this.Settings,
                    entry,
                    (testConfiguration) =>
                    {
                        if (testConfiguration.Format == ODataFormat.Atom)
                        {
                            return new AtomWriterTestExpectedResults(this.Settings.ExpectedResultSettings)
                            {
                                Xml = "<ODataOperations>" + testCase.Atom + "</ODataOperations>",
                                ExpectedException2 =
                                    entry.Actions != null && entry.Actions.Contains(null)
                                        ? ODataExpectedExceptions.ODataException("ValidationUtils_EnumerableContainsANullItem", "ODataEntry.Actions")
                                        : testConfiguration.IsRequest && entry.Actions != null && entry.Actions.Any()
                                            ? ODataExpectedExceptions.ODataException("WriterValidationUtils_OperationInRequest", GetFirstOperationMetadata(entry))
                                            : entry.Functions != null && entry.Functions.Contains(null)
                                                ? ODataExpectedExceptions.ODataException("ValidationUtils_EnumerableContainsANullItem", "ODataEntry.Functions")
                                                : testConfiguration.IsRequest && entry.Functions != null && entry.Functions.Any()
                                                    ? ODataExpectedExceptions.ODataException("WriterValidationUtils_OperationInRequest", GetFirstOperationMetadata(entry))
                                                    : null,
                                FragmentExtractor = (result) =>
                                {
                                    var actions = result.Elements(TestAtomConstants.ODataMetadataXNamespace + "action");
                                    var functions = result.Elements(TestAtomConstants.ODataMetadataXNamespace + "function");
                                    result = new XElement("ODataOperations", actions, functions);
                                    if (result.FirstNode == null)
                                    {
                                        result.Add(string.Empty);
                                    }

                                    return result;
                                }
                            };
                        }
                        else if (testConfiguration.Format == ODataFormat.Json)
                        {
                            return new JsonWriterTestExpectedResults(this.Settings.ExpectedResultSettings)
                            {
                                Json = string.Join(
                                    "$(NL)",
                                    "{",
                                    testCase.JsonLight,
                                    "}"),
                                ExpectedException2 =
                                    entry.Actions != null && entry.Actions.Contains(null)
                                        ? ODataExpectedExceptions.ODataException("ValidationUtils_EnumerableContainsANullItem", "ODataEntry.Actions")
                                        : testConfiguration.IsRequest && entry.Actions != null && entry.Actions.Any()
                                            ? ODataExpectedExceptions.ODataException("WriterValidationUtils_OperationInRequest", GetFirstOperationMetadata(entry))
                                            : entry.Actions != null && entry.Actions.Any(a => !a.Metadata.IsAbsoluteUri && !a.Metadata.OriginalString.StartsWith("#"))
                                                ? ODataExpectedExceptions.ODataException("ValidationUtils_InvalidMetadataReferenceProperty", entry.Actions.First(a => a.Metadata.OriginalString.Contains(" ")).Metadata.OriginalString)
                                            : entry.Functions != null && entry.Functions.Contains(null)
                                                ? ODataExpectedExceptions.ODataException("ValidationUtils_EnumerableContainsANullItem", "ODataEntry.Functions")
                                                : testConfiguration.IsRequest && entry.Functions != null && entry.Functions.Any()
                                                    ? ODataExpectedExceptions.ODataException("WriterValidationUtils_OperationInRequest", GetFirstOperationMetadata(entry))
                                                        : entry.Functions != null && entry.Functions.Any(f => !f.Metadata.IsAbsoluteUri && !f.Metadata.OriginalString.StartsWith("#"))
                                                            ? ODataExpectedExceptions.ODataException("ValidationUtils_InvalidMetadataReferenceProperty", entry.Functions.First(f => f.Metadata.OriginalString.Contains(" ")).Metadata.OriginalString)
                                                    : null,
                                FragmentExtractor = (result) =>
                                {
                                    var actionsAndFunctions = result.Object().Properties.Where(p => p.Name.Contains("#")).ToList();

                                    var jsonResult = new JsonObject();
                                    actionsAndFunctions.ForEach(p =>
                                    {
                                        // NOTE we remove all annotations here and in particular the text annotations to be able to easily compare
                                        //      against the expected results. This however means that we do not distinguish between the indented and non-indented case here.
                                        p.RemoveAllAnnotations(true);
                                        jsonResult.Add(p);
                                    });
                                    return jsonResult;
                                }
                            };
                        }
                        else
                        {
                            string formatName = testConfiguration.Format == null ? "null" : testConfiguration.Format.GetType().Name;
                            throw new NotSupportedException("Invalid format detected: " + formatName);
                        }
                    });
            });

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors.PayloadCases(WriterPayloads.EntryPayloads),
                this.WriterTestConfigurationProvider.ExplicitFormatConfigurationsWithIndent,
                (testDescriptor, testConfiguration) =>
                {
                    testConfiguration = testConfiguration.Clone();
                    testConfiguration.MessageWriterSettings.SetServiceDocumentUri(ServiceDocumentUri);

                    if (testConfiguration.Format == ODataFormat.Json)
                    {
                        if (testDescriptor.IsGeneratedPayload)
                        {
                            return;
                        }

                        // We need a model, entity set and entity type for JSON Light
                        testDescriptor = new PayloadWriterTestDescriptor<ODataItem>(testDescriptor)
                        {
                            Model = model,
                            PayloadEdmElementContainer = edmEntitySetCustermors,
                            PayloadEdmElementType = edmEntityTypeCustomer,
                        };
                    }

                    TestWriterUtils.WriteAndVerifyODataPayload(testDescriptor, testConfiguration, this.Assert, this.Logger);
                });
        }
        public void StreamPropertiesProjectionTest()
        {
            EdmModel model = new EdmModel();
            var container = new EdmEntityContainer("TestModel", "DefaultContainer");
            model.AddElement(container);
            EdmEntityType townType = model.EntityType("TownType");
            townType.KeyProperty("Id", EdmCoreModel.Instance.GetInt32(false));
            townType.StreamProperty("MapSmall");
            townType.StreamProperty("MapMedium");
            townType.NavigationProperty("NavProp", townType);

            EdmEntityType cityType = model.EntityType("CityType", null, townType);
            cityType.StreamProperty("CityLogo");

            EdmEntitySet townsSet = model.EntitySet("Towns", townType);
            model.Fixup();

            var testCases = new ProjectionTestCase[]
            {
                #region No $select
                new ProjectionTestCase
                {
                    DebugDescription = "No $select => three templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapSmall").StreamProperty("MapMedium").StreamProperty("CityLogo").NavigationProperty("NavProp", /*url*/null),
                    ProjectionString = null,
                },
                new ProjectionTestCase
                {
                    DebugDescription = "No $select + one property in the payload => two templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapSmall", "http://odata.org/stream/read"),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapSmall", "http://odata.org/stream/read").StreamProperty("MapMedium").StreamProperty("CityLogo").NavigationProperty("NavProp", /*url*/null),
                    ProjectionString = null,
                },
                new ProjectionTestCase
                {
                    DebugDescription = "No $select + three properties in the payload => no templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapSmall", "http://odata.org/stream/read").StreamProperty("MapMedium", "http://odata.org/stream/read").StreamProperty("CityLogo", "http://odata.org/stream/read"),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapSmall", "http://odata.org/stream/read").StreamProperty("MapMedium", "http://odata.org/stream/read").StreamProperty("CityLogo", "http://odata.org/stream/read").NavigationProperty("NavProp", /*url*/null),
                    ProjectionString = null,
                },
                #endregion No $select
                #region Empty $select
                new ProjectionTestCase
                {
                    DebugDescription = "Empty $select => no templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1),
                    ProjectionString = string.Empty,
                },
                new ProjectionTestCase
                {
                    DebugDescription = "Empty $select + one property in the payload => no templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapSmall", "http://odata.org/stream/read"),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapSmall", "http://odata.org/stream/read"),
                    ProjectionString = string.Empty,
                },
                new ProjectionTestCase
                {
                    DebugDescription = "Empty $select + three properties in the payload => no templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapSmall", "http://odata.org/stream/read").StreamProperty("MapMedium", "http://odata.org/stream/read").StreamProperty("CityLogo", "http://odata.org/stream/read"),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapSmall", "http://odata.org/stream/read").StreamProperty("MapMedium", "http://odata.org/stream/read").StreamProperty("CityLogo", "http://odata.org/stream/read"),
                    ProjectionString = string.Empty,
                },
                #endregion Empty $select
                #region $select=*
                new ProjectionTestCase
                {
                    DebugDescription = "$select=* => three templatized stream properties and and one templatized navigation.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapSmall").StreamProperty("MapMedium").StreamProperty("CityLogo").NavigationProperty("NavProp", /*url*/null),
                    ProjectionString = "*",
                },
                new ProjectionTestCase
                {
                    DebugDescription = "$select=* + one property in the payload => two templatized stream properties and one templatized navigation.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapSmall", "http://odata.org/stream/read"),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapSmall", "http://odata.org/stream/read").StreamProperty("MapMedium").StreamProperty("CityLogo").NavigationProperty("NavProp", /*url*/null),
                    ProjectionString = "*",
                },
                new ProjectionTestCase
                {
                    DebugDescription = "$select=* + three properties in the payload => no templatized stream properties, one templatized navigation.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapSmall", "http://odata.org/stream/read").StreamProperty("MapMedium", "http://odata.org/stream/read").StreamProperty("CityLogo", "http://odata.org/stream/read"),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapSmall", "http://odata.org/stream/read").StreamProperty("MapMedium", "http://odata.org/stream/read").StreamProperty("CityLogo", "http://odata.org/stream/read").NavigationProperty("NavProp", /*url*/null),
                    ProjectionString = "*",
                },
                #endregion $select=*
                #region $select=MapMedium
                new ProjectionTestCase
                {
                    DebugDescription = "$select=MapMedium => one templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapMedium"),
                    ProjectionString = "MapMedium",
                },
                new ProjectionTestCase
                {
                    DebugDescription = "$select=MapMedium + MapMedium property in the payload => no templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapMedium", "http://odata.org/stream/read"),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapMedium", "http://odata.org/stream/read"),
                    ProjectionString = "MapMedium",
                },
                new ProjectionTestCase
                {
                    DebugDescription = "$select=MapMedium + MapSmall property in the payload => one templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapSmall", "http://odata.org/stream/read"),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapSmall", "http://odata.org/stream/read").StreamProperty("MapMedium"),
                    ProjectionString = "MapMedium",
                },
                new ProjectionTestCase
                {
                    DebugDescription = "$select=MapMedium + three properties in the payload => no templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapSmall", "http://odata.org/stream/read").StreamProperty("MapMedium", "http://odata.org/stream/read").StreamProperty("CityLogo", "http://odata.org/stream/read"),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapSmall", "http://odata.org/stream/read").StreamProperty("MapMedium", "http://odata.org/stream/read").StreamProperty("CityLogo", "http://odata.org/stream/read"),
                    ProjectionString = "MapMedium",
                },
                #endregion $select=MapMedium
                #region $select=NavProp/*
                new ProjectionTestCase
                {
                    DebugDescription = "$select=NavProp/* => three templatized stream properties and and one templatized navigation.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).ExpandedNavigationProperty("NavProp", PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 2)),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).ExpandedNavigationProperty("NavProp", PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 2).StreamProperty("MapSmall").StreamProperty("MapMedium").StreamProperty("CityLogo").NavigationProperty("NavProp", /*url*/null)),
                    ProjectionString = "NavProp/*",
                },
                new ProjectionTestCase
                {
                    DebugDescription = "$select=NavProp/* + one property in the payload => two templatized stream properties and one templatized navigation.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).ExpandedNavigationProperty("NavProp", PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 2).StreamProperty("MapSmall", "http://odata.org/stream/read")),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).ExpandedNavigationProperty("NavProp", PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 2).StreamProperty("MapSmall", "http://odata.org/stream/read").StreamProperty("MapMedium").StreamProperty("CityLogo").NavigationProperty("NavProp", /*url*/null)),
                    ProjectionString = "NavProp/*",
                },
                new ProjectionTestCase
                {
                    DebugDescription = "$select=NavProp/* + three properties in the payload => no templatized stream properties, one templatized navigation.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).ExpandedNavigationProperty("NavProp", PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 2).StreamProperty("MapSmall", "http://odata.org/stream/read").StreamProperty("MapMedium", "http://odata.org/stream/read").StreamProperty("CityLogo", "http://odata.org/stream/read")),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).ExpandedNavigationProperty("NavProp", PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 2).StreamProperty("MapSmall", "http://odata.org/stream/read").StreamProperty("MapMedium", "http://odata.org/stream/read").StreamProperty("CityLogo", "http://odata.org/stream/read").NavigationProperty("NavProp", /*url*/null)),
                    ProjectionString = "NavProp/*",
                },
                #endregion $select=NavProp/*
                #region $select=NavProp/NavProp/MapMedium
                new ProjectionTestCase
                {
                    DebugDescription = "$select=NavProp/NavProp/MapMedium => one templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).ExpandedNavigationProperty("NavProp", PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 2).ExpandedNavigationProperty("NavProp", PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 3))),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).ExpandedNavigationProperty("NavProp", PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 2).ExpandedNavigationProperty("NavProp", PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 3).StreamProperty("MapMedium"))),
                    ProjectionString = "NavProp/NavProp/MapMedium",
                },
                #endregion $select=NavProp/NavProp/MapMedium
                #region $select=NavProp/NavProp
                new ProjectionTestCase
                {
                    DebugDescription = "$select=NavProp/NavProp => three templatized stream properties and one navigation property.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).ExpandedNavigationProperty("NavProp", PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 2).ExpandedNavigationProperty("NavProp", PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 3))),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).ExpandedNavigationProperty("NavProp", PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 2).ExpandedNavigationProperty("NavProp", PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 3).StreamProperty("MapSmall").StreamProperty("MapMedium").StreamProperty("CityLogo").NavigationProperty("NavProp", /*url*/null))),
                    ProjectionString = "NavProp/NavProp",
                },
                #endregion $select=NavProp/NavProp
                #region $select=TestModel.CityType/CityLogo
                new ProjectionTestCase
                {
                    DebugDescription = "$select=TestModel.CityType/CityLogo on base type => no templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.TownType").PrimitiveProperty("Id", 1),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.TownType").PrimitiveProperty("Id", 1),
                    ProjectionString = "TestModel.CityType/CityLogo",
                },
                new ProjectionTestCase
                {
                    DebugDescription = "$select=TestModel.CityType/CityLogo on derived type => specific property templatized.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("CityLogo"),
                    ProjectionString = "TestModel.CityType/CityLogo",
                },
                #endregion $select=TestModel.CityType/CityLogo
                #region $select=TestModel.CityType/MapSmall
                new ProjectionTestCase
                {
                    DebugDescription = "$select=TestModel.CityType/MapSmall on base type => no templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.TownType").PrimitiveProperty("Id", 1),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.TownType").PrimitiveProperty("Id", 1),
                    ProjectionString = "TestModel.CityType/MapSmall",
                },
                new ProjectionTestCase
                {
                    DebugDescription = "$select=TestModel.CityType/MapSmall on derived type => specific property templatized.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapSmall"),
                    ProjectionString = "TestModel.CityType/MapSmall",
                },
                #endregion $select=TestModel.CityType/MapSmall
                #region $select=TestModel.TownType/MapSmall
                new ProjectionTestCase
                {
                    DebugDescription = "$select=TestModel.TownType/MapSmall on base type => specific property templatized..",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.TownType").PrimitiveProperty("Id", 1),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.TownType").PrimitiveProperty("Id", 1).StreamProperty("MapSmall"),
                    ProjectionString = "TestModel.TownType/MapSmall",
                },
                new ProjectionTestCase
                {
                    DebugDescription = "$select=TestModel.TownType/MapSmall on derived type => specific property templatized.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapSmall"),
                    ProjectionString = "TestModel.TownType/MapSmall",
                },
                #endregion $select=TestModel.TownType/MapSmall
            };

            IEnumerable<PayloadReaderTestDescriptor> testDescriptors = testCases.Select(testCase =>
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = testCase.DebugDescription,
                    PayloadEdmModel = model,
                    PayloadElement = testCase.PayloadEntity
                        .WithContextUriProjection(testCase.ProjectionString)
                        .ExpectedEntityType(townType, townsSet),
                    ExpectedResultPayloadElement = tc => testCase.ExpectedEntity,
                    ExpectedException = testCase.ExpectedException,
                });

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.JsonLightFormatConfigurations.Where(tc => !tc.IsRequest),
                (testDescriptor, testConfiguration) =>
                {
                    // These descriptors are already tailored specifically for Json Light and 
                    // do not require normalization.
                    testDescriptor.TestDescriptorNormalizers.Clear();
                    testDescriptor.RunTest(testConfiguration);
                });
        }
        public void NavigationPropertiesProjectionTest()
        {
            EdmModel model = new EdmModel();

            EdmEntityType townType = model.EntityType("TownType");
            townType.KeyProperty("Id", EdmCoreModel.Instance.GetInt32(false) as EdmTypeReference);
            townType.NavigationProperty("NavProp1", townType);
            EdmEntitySet townsSet = model.EntitySet("Towns", townType);

            EdmEntityType cityType = new EdmEntityType("TestModel", "CityType", townType);
            model.AddElement(cityType);
            cityType.NavigationProperty("NavProp2", townType);
            model.EntitySet("Cities", cityType);

            EdmEntityType cityType2 = new EdmEntityType("TestModel", "DuplicateCityType", townType);
            model.AddElement(cityType2);
            cityType2.NavigationProperty("NavProp2", townType);
            model.EntitySet("DuplicateCities", cityType2);

            model.Fixup();

            var testCases = new ProjectionTestCase[]
            {
                #region No $select
                new ProjectionTestCase
                {
                    DebugDescription = "No $select => two templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1)
                        .NavigationProperty("NavProp1", /*url*/null).NavigationProperty("NavProp2", /*url*/null),
                    ProjectionString = null,
                },
                new ProjectionTestCase
                {
                    DebugDescription = "No $select + one property in the payload => one templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp1", "http://odata.org/nav1"),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1)
                        .NavigationProperty("NavProp1", "http://odata.org/nav1").NavigationProperty("NavProp2", /*url*/null),
                    ProjectionString = null,
                },
                new ProjectionTestCase
                {
                    DebugDescription = "No $select + two properties in the payload => no templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp1", "http://odata.org/nav1").NavigationProperty("NavProp2", "http://odata.org/nav2"),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1)
                        .NavigationProperty("NavProp1", "http://odata.org/nav1").NavigationProperty("NavProp2", "http://odata.org/nav2"),
                    ProjectionString = null,
                },
                #endregion No $select
                #region Empty $select
                new ProjectionTestCase
                {
                    DebugDescription = "Empty $select => no templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1),
                    ProjectionString = string.Empty,
                },
                new ProjectionTestCase
                {
                    DebugDescription = "Empty $select + one property in the payload => no templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp1", "http://odata.org/nav1"),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp1", "http://odata.org/nav1"),
                    ProjectionString = string.Empty,
                },
                new ProjectionTestCase
                {
                    DebugDescription = "Empty $select + two properties in the payload => no templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp1", "http://odata.org/nav1").NavigationProperty("NavProp2", "http://odata.org/nav2"),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp1", "http://odata.org/nav1").NavigationProperty("NavProp2", "http://odata.org/nav2"),
                    ProjectionString = string.Empty,
                },
                #endregion Empty $select
                #region $select=*
                new ProjectionTestCase
                {
                    DebugDescription = "$select=* => two templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp1", /*url*/null).NavigationProperty("NavProp2", /*url*/null),
                    ProjectionString = "*",
                },
                new ProjectionTestCase
                {
                    DebugDescription = "$select=* + one property in the payload => one templatized property.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp2", "http://odata.org/nav2"),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp2", "http://odata.org/nav2").NavigationProperty("NavProp1", /*url*/null),
                    ProjectionString = "*",
                },
                new ProjectionTestCase
                {
                    DebugDescription = "$select=* + two properties in the payload => no templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp1", "http://odata.org/nav1").NavigationProperty("NavProp2", "http://odata.org/nav2"),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp1", "http://odata.org/nav1").NavigationProperty("NavProp2", "http://odata.org/nav2"),
                    ProjectionString = "*",
                },
                #endregion $select=*
                #region $select=NavProp2,*
                new ProjectionTestCase
                {
                    DebugDescription = "$select=NavProp2,* => two templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp1", /*url*/null).NavigationProperty("NavProp2", /*url*/null),
                    ProjectionString = "NavProp2,*",
                },
                new ProjectionTestCase
                {
                    DebugDescription = "$select=NavProp2,* + NavProp2 property in the payload => one templatized property.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp2", "http://odata.org/nav2"),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp2", "http://odata.org/nav2").NavigationProperty("NavProp1", /*url*/null),
                    ProjectionString = "NavProp2,*",
                },
                new ProjectionTestCase
                {
                    DebugDescription = "$select=NavProp2,* + NavProp1 property in the payload => one templatized property.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp1", "http://odata.org/nav1"),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp1", "http://odata.org/nav1").NavigationProperty("NavProp2", /*url*/null),
                    ProjectionString = "NavProp2,*",
                },
                new ProjectionTestCase
                {
                    DebugDescription = "$select=NavProp2,* + two properties in the payload => no templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp1", "http://odata.org/nav1").NavigationProperty("NavProp2", "http://odata.org/nav2"),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp1", "http://odata.org/nav1").NavigationProperty("NavProp2", "http://odata.org/nav2"),
                    ProjectionString = "NavProp2,*",
                },
                #endregion $select=NavProp2,*
                #region $select=NavProp1,NavProp2
                new ProjectionTestCase
                {
                    DebugDescription = "$select=NavProp1,NavProp2 => two templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp1", /*url*/null).NavigationProperty("NavProp2", /*url*/null),
                    ProjectionString = "NavProp1,NavProp2",
                },
                new ProjectionTestCase
                {
                    DebugDescription = "$select=NavProp1,NavProp2 + NavProp2 property in the payload => one templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp2", "http://odata.org/nav2"),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp2", "http://odata.org/nav2").NavigationProperty("NavProp1", /*url*/null),
                    ProjectionString = "NavProp1,NavProp2",
                },
                new ProjectionTestCase
                {
                    DebugDescription = "$select=NavProp1,NavProp2 + two properties in the payload => no templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp1", "http://odata.org/nav1").NavigationProperty("NavProp2", "http://odata.org/nav2"),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp1", "http://odata.org/nav1").NavigationProperty("NavProp2", "http://odata.org/nav2"),
                    ProjectionString = "NavProp1,NavProp2",
                },
                #endregion $select=NavProp1,NavProp2
                #region $select=NavProp2
                new ProjectionTestCase
                {
                    DebugDescription = "$select=NavProp2 => one templatized property.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp2", /*url*/null),
                    ProjectionString = "NavProp2",
                },
                new ProjectionTestCase
                {
                    DebugDescription = "$select=NavProp2 + NavProp2 property in the payload => no templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp2", "http://odata.org/nav2"),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp2", "http://odata.org/nav2"),
                    ProjectionString = "NavProp2",
                },
                new ProjectionTestCase
                {
                    DebugDescription = "$select=NavProp2 + NavProp1 property in the payload => one templatized property.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp1", "http://odata.org/nav1"),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp1", "http://odata.org/nav1").NavigationProperty("NavProp2", /*url*/null),
                    ProjectionString = "NavProp2",
                },
                new ProjectionTestCase
                {
                    DebugDescription = "$select=NavProp2 + two properties in the payload => no templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp1", "http://odata.org/nav1").NavigationProperty("NavProp2", "http://odata.org/nav2"),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp1", "http://odata.org/nav1").NavigationProperty("NavProp2", "http://odata.org/nav2"),
                    ProjectionString = "NavProp2",
                },
                #endregion $select=NavProp2
                #region $select=NavProp1/*
                new ProjectionTestCase
                {
                    DebugDescription = "$select=NavProp1/* => three templatized stream properties and and one templatized navigation.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).ExpandedNavigationProperty("NavProp1", PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 2)),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).ExpandedNavigationProperty("NavProp1", PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 2).NavigationProperty("NavProp1", /*url*/null).NavigationProperty("NavProp2", /*url*/null)),
                    ProjectionString = "NavProp1/*",
                },
                #endregion $select=NavProp/*
                #region $select=NavProp1/NavProp1
                new ProjectionTestCase
                {
                    DebugDescription = "$select=NavProp1/NavProp1 => one templatized navigation property.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).ExpandedNavigationProperty("NavProp1", PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 2)),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).ExpandedNavigationProperty("NavProp1", PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 2).NavigationProperty("NavProp1", /*url*/null)),
                    ProjectionString = "NavProp1/NavProp1",
                },
                new ProjectionTestCase
                {
                    DebugDescription = "$select=NavProp1/NavProp1 with expand => two templatized navigation properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).ExpandedNavigationProperty("NavProp1", PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 2).ExpandedNavigationProperty("NavProp1", PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 3))),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).ExpandedNavigationProperty("NavProp1", PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 2).ExpandedNavigationProperty("NavProp1", PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 3).NavigationProperty("NavProp1", /*url*/null).NavigationProperty("NavProp2", /*url*/null))),
                    ProjectionString = "NavProp1/NavProp1",
                },
                #endregion $select=NavProp1/NavProp1
                #region $select=TestModel.CityType/NavProp2
                new ProjectionTestCase
                {
                    DebugDescription = "$select=TestModel.CityType/NavProp2 on base type => no templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.TownType").PrimitiveProperty("Id", 1),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.TownType").PrimitiveProperty("Id", 1),
                    ProjectionString = "TestModel.CityType/NavProp2",
                },
                new ProjectionTestCase
                {
                    DebugDescription = "$select=TestModel.CityType/NavProp2 on derived type => specific property templatized.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp2", /*url*/null),
                    ProjectionString = "TestModel.CityType/NavProp2",
                },
                new ProjectionTestCase
                {
                    DebugDescription = "$select=TestModel.CityType/NavProp2 on different derived type => no templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.DuplicateCityType").PrimitiveProperty("Id", 1),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.DuplicateCityType").PrimitiveProperty("Id", 1),
                    ProjectionString = "TestModel.CityType/NavProp2",
                },
                #endregion $select=TestModel.CityType/NavProp2
                #region $select=TestModel.CityType/NavProp1
                new ProjectionTestCase
                {
                    DebugDescription = "$select=TestModel.CityType/NavProp1 on base type => no templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.TownType").PrimitiveProperty("Id", 1),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.TownType").PrimitiveProperty("Id", 1),
                    ProjectionString = "TestModel.CityType/NavProp1",
                },
                new ProjectionTestCase
                {
                    DebugDescription = "$select=TestModel.CityType/NavProp1 on derived type => specific property templatized.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp1", /*url*/null),
                    ProjectionString = "TestModel.CityType/NavProp1",
                },
                #endregion $select=TestModel.CityType/NavProp1
                #region $select=TestModel.TownType/NavProp1
                new ProjectionTestCase
                {
                    DebugDescription = "$select=TestModel.TownType/NavProp1 on base type => specific property templatized..",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.TownType").PrimitiveProperty("Id", 1),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.TownType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp1", /*url*/null),
                    ProjectionString = "TestModel.TownType/NavProp1",
                },
                new ProjectionTestCase
                {
                    DebugDescription = "$select=TestModel.TownType/NavProp1 on derived type => specific property templatized.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp1", /*url*/null),
                    ProjectionString = "TestModel.TownType/NavProp1",
                },
                #endregion $select=TestModel.TownType/NavProp1
                #region $select=NavProp1/TestModel.City/NavProp2
                new ProjectionTestCase
                {
                    DebugDescription = "$select=NavProp1/TestModel.TownType/NavProp2 on expanded base type => no templatized property.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.TownType").PrimitiveProperty("Id", 1).ExpandedNavigationProperty("NavProp1", PayloadBuilder.Entity("TestModel.TownType").PrimitiveProperty("Id", 2)),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.TownType").PrimitiveProperty("Id", 1).ExpandedNavigationProperty("NavProp1", PayloadBuilder.Entity("TestModel.TownType").PrimitiveProperty("Id", 2)),
                    ProjectionString = "NavProp1/TestModel.TownType/NavProp2",
                },
                new ProjectionTestCase
                {
                    DebugDescription = "$select=NavProp1/TestModel.TownType/NavProp2 on expanded derived type type => specific templatized property.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.TownType").PrimitiveProperty("Id", 1).ExpandedNavigationProperty("NavProp1", PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 2)),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.TownType").PrimitiveProperty("Id", 1).ExpandedNavigationProperty("NavProp1", PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 2).NavigationProperty("NavProp2", /*url*/null)),
                    ProjectionString = "NavProp1/TestModel.TownType/NavProp2",
                },
                new ProjectionTestCase
                {
                    DebugDescription = "$select=TestModel.CityType/* on different derived type => no templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.TownType").PrimitiveProperty("Id", 1).ExpandedNavigationProperty("NavProp1", PayloadBuilder.Entity("TestModel.DuplicateCityType").PrimitiveProperty("Id", 2)),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.TownType").PrimitiveProperty("Id", 1).ExpandedNavigationProperty("NavProp1", PayloadBuilder.Entity("TestModel.DuplicateCityType").PrimitiveProperty("Id", 2)),
                    ProjectionString = "TestModel.CityType/*",
                },
                #endregion $select=NavProp1/TestModel.City/NavProp2
            };

            IEnumerable<PayloadReaderTestDescriptor> testDescriptors = testCases.Select(testCase =>
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = testCase.DebugDescription,
                    PayloadEdmModel = model,
                    PayloadElement = testCase.PayloadEntity
                        .WithContextUriProjection(testCase.ProjectionString)
                        .ExpectedEntityType(townType, townsSet),
                    ExpectedResultPayloadElement = tc => testCase.ExpectedEntity,
                    ExpectedException = testCase.ExpectedException,
                });

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.JsonLightFormatConfigurations.Where(tc => !tc.IsRequest),
                (testDescriptor, testConfiguration) =>
                {
                    // These descriptors are already tailored specifically for Json Light and 
                    // do not require normalization.
                    testDescriptor.TestDescriptorNormalizers.Clear();
                    testDescriptor.RunTest(testConfiguration);
                });
        }
        public void BatchReaderMixedEncodingTest()
        {
            EdmModel model = new EdmModel();
            EdmEntityType personType = model.EntityType("Person")
                .KeyProperty("Id", EdmCoreModel.Instance.GetInt32(false) as EdmTypeReference)
                .Property("Name", EdmPrimitiveTypeKind.String, isNullable: true);
            model.Fixup();

            EdmEntitySet personSet = model.EntitySet("Person", personType);

            EntityInstance personInstance = PayloadBuilder.Entity("TestModel.Person")
                .Property("Id", PayloadBuilder.PrimitiveValue(1))
                .Property("Name", PayloadBuilder.PrimitiveValue("Mr Foo Baz"));

            ODataUriSegment root = ODataUriBuilder.Root(new Uri("http://www.odata.org"));
            ODataUri testUri = new ODataUri(root, ODataUriBuilder.EntitySet(personSet));


            Encoding[] encodings = new Encoding[] 
            { 
                Encoding.UTF8, 
                Encoding.BigEndianUnicode, 
                Encoding.Unicode 
            };

            IEnumerable<BatchReaderMixedEncodingTestCase> testCases =
                encodings.SelectMany(batchEncoding =>
                    encodings.Select(changesetEncoding =>
                        new BatchReaderMixedEncodingTestCase
                        {
                            BatchEncoding = batchEncoding,
                            Changesets = new[]
                            {
                                new BatchReaderMixedEncodingChangeset
                                {
                                    ChangesetEncoding = changesetEncoding,
                                    Operations = new[]
                                    {
                                       new BatchReaderMixedEncodingOperation
                                       {
                                           OperationEncoding = Encoding.Unicode,
                                           PayloadFormat = ODataFormat.Atom,
                                       },
                                       new BatchReaderMixedEncodingOperation
                                       {
                                           // Uses changeset's encoding
                                           PayloadFormat = ODataFormat.Atom,
                                       },
                                    },
                                },
                                new BatchReaderMixedEncodingChangeset
                                {
                                    Operations = new[]
                                    {
                                        new BatchReaderMixedEncodingOperation
                                        {
                                            // Uses batch's encoding
                                            OperationEncoding = batchEncoding,
                                            PayloadFormat = ODataFormat.Atom,
                                        },
                                    },
                                },
                            },
                        }
                    ));

            this.CombinatorialEngineProvider.RunCombinations(
                testCases,
                this.ReaderTestConfigurationProvider.DefaultFormatConfigurations,
                (testCase, testConfiguration) =>
                {
                    var testPayload = personInstance.DeepCopy();
                    if (!testConfiguration.IsRequest)
                    {
                        testPayload.AddAnnotation(new PayloadFormatVersionAnnotation() { Response = true, ResponseWrapper = true });
                    }

                    var testDescriptor = this.CreateTestDescriptor(testCase, testPayload, testUri, testConfiguration.IsRequest);
                    testDescriptor.PayloadEdmModel = model;
                    testDescriptor.RunTest(testConfiguration);
                });
        }