public void ParameterReaderJsonLightTest() { EdmModel model = new EdmModel(); model.Fixup(); EdmEntityContainer container = model.EntityContainer as EdmEntityContainer; EdmFunction function = new EdmFunction(container.Namespace, "f1", EdmCoreModel.Instance.GetInt32(true)); function.AddParameter("p1", EdmCoreModel.Instance.GetInt32(false) as EdmTypeReference); function.AddParameter("p2", EdmCoreModel.Instance.GetString(false) as EdmTypeReference); model.AddElement(function); EdmOperationImport f1 = container.FunctionImport(function); ComplexInstance f1Params = PayloadBuilder.ComplexValue().PrimitiveProperty("p1", 42).PrimitiveProperty("p2", "Vienna") .ExpectedFunctionImport(f1); var testCases = new[] { new { DebugDescription = "Custom property annotation for a valid parameter property (before property) - should work.", Json = "{\"" + JsonLightUtils.GetPropertyAnnotationName("p1", "my.custom") + "\":42, \"p1\":42, \"p2\":\"Vienna\"}", ExpectedException = (ExpectedException)null, }, new { DebugDescription = "Custom property annotation for a valid parameter property (after property) - should fail.", Json = "{\"p1\":42, \"" + JsonLightUtils.GetPropertyAnnotationName("p1", "my.custom") + "\":42, \"p2\":\"Vienna\"}", ExpectedException = ODataExpectedExceptions.ODataException("DuplicatePropertyNamesChecker_PropertyAnnotationAfterTheProperty", "my.custom", "p1"), }, new { DebugDescription = "OData property annotation for a valid parameter property (before property) - should work.", Json = "{\"" + JsonLightUtils.GetPropertyAnnotationName("p1", JsonLightConstants.ODataTypeAnnotationName) + "\":42, \"p1\":42, \"p2\":\"Vienna\"}", ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightParameterDeserializer_PropertyAnnotationForParameters"), }, new { DebugDescription = "OData property annotation for a valid parameter property (after property) - should fail.", Json = "{\"p1\":42, \"" + JsonLightUtils.GetPropertyAnnotationName("p1", JsonLightConstants.ODataTypeAnnotationName) + "\":42, \"p2\":\"Vienna\"}", ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightParameterDeserializer_PropertyAnnotationForParameters"), }, new { DebugDescription = "Custom property annotation for an invalid parameter property - should fail.", Json = "{\"" + JsonLightUtils.GetPropertyAnnotationName("p0", "my.custom") + "\":42, \"p1\":42, \"p2\":\"Vienna\"}", ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightParameterDeserializer_PropertyAnnotationWithoutPropertyForParameters", "p0"), }, new { DebugDescription = "Custom instance annotation - should work.", Json = "{\"@my.custom\":42, \"p1\":42, \"p2\":\"Vienna\"}", ExpectedException = (ExpectedException)null, }, new { DebugDescription = "OData instance annotation - should fail.", Json = "{\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataTypeAnnotationName + "\":\"Edm.Int32\", \"p1\":42, \"p2\":\"Vienna\"}", ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightPropertyAndValueDeserializer_UnexpectedAnnotationProperties", JsonLightConstants.ODataTypeAnnotationName), }, }; var testDescriptors = testCases.Select(testCase => new PayloadReaderTestDescriptor(this.Settings) { DebugDescription = testCase.DebugDescription, PayloadElement = f1Params.DeepCopy().JsonRepresentation(testCase.Json), PayloadEdmModel = model, PayloadKind = ODataPayloadKind.Parameter, ExpectedException = testCase.ExpectedException, }); this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.ReaderTestConfigurationProvider.JsonLightFormatConfigurations.Where(c => c.IsRequest), (testDescriptor, testConfiguration) => { testDescriptor.ExpectedResultNormalizers.Add(tc => ParameterReaderTests.FixupExpectedCollectionParameterPayloadElement); // These descriptors are already tailored specifically for Json Light and // do not require normalization. testDescriptor.TestDescriptorNormalizers.Clear(); testDescriptor.RunTest(testConfiguration); }); }