Exemple #1
0
        public void ParameterReaderReadComplexParameterWithPrimitiveValueShouldThrow()
        {
            IEdmModel           model = TestModels.BuildModelWithFunctionImport();
            IEdmOperationImport functionImport_Complex = model.FindEntityContainer("TestContainer").FindOperationImports("FunctionImport_Complex").First();

            var testConfigurations = this.ReaderTestConfigurationProvider.JsonLightFormatConfigurations.Where(c => c.IsRequest);

            this.CombinatorialEngineProvider.RunCombinations(
                testConfigurations,
                (testConfiguration) =>
            {
                this.Assert.ExpectedException(
                    () =>
                {
                    ODataParameterReaderTestWrapper reader = CreateODataParameterReader(model, functionImport_Complex, testConfiguration, "{\"complex\":1}");
                    while (reader.Read())
                    {
                        if (reader.State == ODataParameterReaderState.Resource)
                        {
                            var complexReader = reader.CreateResourceReader();
                            while (complexReader.Read())
                            {
                                ;
                            }
                        }
                    }
                },
                    ODataExpectedExceptions.ODataException("ODataJsonLightReader_UnexpectedPrimitiveValueForODataResource"),
                    this.ExceptionVerifier);
            });
        }
Exemple #2
0
        private void RunParameterReaderErrorTest(
            ODataParameterReaderTestWrapper reader,
            ExpectedException expectedException,
            ODataParameterReaderState expectedState = ODataParameterReaderState.Exception)
        {
            if (reader == null)
            {
                // Reader creation failed and we verified the exception already
                return;
            }

            this.Assert.ExpectedException(() => reader.Read(), expectedException, this.ExceptionVerifier);
            this.Assert.AreEqual(expectedState, reader.State, "Reader should be in '" + expectedState.ToString() + "' state.");
        }
Exemple #3
0
        public void ParameterReaderIgnoreMissingNullableParameterTest()
        {
            IEdmModel           model          = TestModels.BuildModelWithFunctionImport();
            IEdmOperationImport functionImport = model.FindEntityContainer("TestContainer").FindOperationImports("FunctionImport_NullablePrimitive").First();

            this.CombinatorialEngineProvider.RunCombinations(
                this.ReaderTestConfigurationProvider.JsonLightFormatConfigurations.Where(c => c.IsRequest == true),
                (testConfiguration) =>
            {
                // Reading an empty payload should not fail
                ODataParameterReaderTestWrapper reader = this.CreateParameterReaderForRequestOrResponse(model, functionImport, testConfiguration);
                this.Assert.IsFalse(reader.Read(), "Read() should return false on an empty payload.");
                this.Assert.AreEqual(ODataParameterReaderState.Completed, reader.State, "State should be completed.");

                // Reading a parameter payload with no parameter should not fail
                reader = this.CreateParameterReaderForRequestOrResponse(model, functionImport, testConfiguration, "{}");
                this.Assert.IsFalse(reader.Read(), "Read() should return false on a parameter payload with no parameter.");
                this.Assert.AreEqual(ODataParameterReaderState.Completed, reader.State, "State should be completed.");
            });
        }
        public void ParameterReaderVersioningTest()
        {
            IEdmModel           model = TestModels.BuildModelWithFunctionImport();
            IEdmOperationImport functionImport_Complex = model.FindEntityContainer("TestContainer").FindOperationImports("FunctionImport_Complex").First();

            var testConfigurations = this.ReaderTestConfigurationProvider.JsonLightFormatConfigurations.Where(c => c.IsRequest);

            this.CombinatorialEngineProvider.RunCombinations(
                testConfigurations,
                (testConfiguration) =>
            {
                this.Assert.ExpectedException(
                    () =>
                {
                    ODataParameterReaderTestWrapper reader = CreateODataParameterReader(model, functionImport_Complex, testConfiguration, "{\"complex\":null}");
                    while (reader.Read())
                    {
                        ;
                    }
                },
                    null,
                    this.ExceptionVerifier);
            });
        }
Exemple #5
0
        public void ParameterReaderErrorTests()
        {
            IEdmModel           model                 = TestModels.BuildModelWithFunctionImport();
            IEdmOperationImport functionImport        = model.FindEntityContainer("TestContainer").FindOperationImports("FunctionImport_Primitive").First();
            IEdmOperationImport functionImport_Stream = model.FindEntityContainer("TestContainer").FindOperationImports("FunctionImport_Stream").First();
            IEdmOperationImport functionImport_Entry  = model.FindEntityContainer("TestContainer").FindOperationImports("FunctionImport_Entry").First();
            IEdmOperationImport functionImport_Feed   = model.FindEntityContainer("TestContainer").FindOperationImports("FunctionImport_Feed").First();

            var testConfigurations = this.ReaderTestConfigurationProvider.JsonLightFormatConfigurations.Where(c => c.IsRequest);

            this.CombinatorialEngineProvider.RunCombinations(
                testConfigurations,
                (testConfiguration) =>
            {
                // Reading an empty payload should fail.
                ODataParameterReaderTestWrapper reader = this.CreateParameterReaderForRequestOrResponse(model, functionImport, testConfiguration);
                this.RunParameterReaderErrorTest(reader,
                                                 ODataExpectedExceptions.ODataException("ODataParameterReaderCore_ParametersMissingInPayload", "FunctionImport_Primitive", "primitive"));

                // Calling Read/ReadAsync in 'Exception' state should fail.
                this.RunParameterReaderErrorTest(reader,
                                                 ODataExpectedExceptions.ODataException("ODataParameterReaderCore_ReadOrReadAsyncCalledInInvalidState", "Exception"));

                // Reading a parameter payload with no parameter should fail because of the missing parameter
                reader = this.CreateParameterReaderForRequestOrResponse(model, functionImport, testConfiguration, "{}");
                this.RunParameterReaderErrorTest(reader,
                                                 ODataExpectedExceptions.ODataException("ODataParameterReaderCore_ParametersMissingInPayload", "FunctionImport_Primitive", "primitive"));

                // Duplicated parameter name in the payload should fail.
                reader = this.CreateParameterReaderForRequestOrResponse(model, functionImport, testConfiguration, "{ primitive: \"foo\", primitive: \"bar\" }");
                if (reader != null)
                {
                    this.RunParameterReaderErrorTest(reader, null, ODataParameterReaderState.Value);
                    this.Assert.AreEqual(ODataParameterReaderState.Value, reader.State, "Reader should be in Value state.");
                    this.Assert.AreEqual("primitive", reader.Name, "Parameter name should be 'primitive'.");
                    this.Assert.AreEqual("foo", reader.Value, "Parameter value should be 'foo'.");
                    this.RunParameterReaderErrorTest(reader,
                                                     ODataExpectedExceptions.ODataException("ODataParameterReaderCore_DuplicateParametersInPayload", "primitive"));
                }

                // Read until we are in Completed state.
                reader = this.CreateParameterReaderForRequestOrResponse(model, functionImport, testConfiguration, "{ primitive: \"foo\" }");
                if (reader != null)
                {
                    this.RunParameterReaderErrorTest(reader, null, ODataParameterReaderState.Value);
                    this.Assert.AreEqual("primitive", reader.Name, "Parameter name should be 'primitive'.");
                    this.Assert.AreEqual("foo", reader.Value, "Parameter value should be 'foo'.");
                    this.RunParameterReaderErrorTest(reader, null, ODataParameterReaderState.Completed);
                }

                // Calling Read/ReadAsync in 'Completed' state should fail.
                this.RunParameterReaderErrorTest(reader,
                                                 ODataExpectedExceptions.ODataException("ODataParameterReaderCore_ReadOrReadAsyncCalledInInvalidState", "Completed"),
                                                 ODataParameterReaderState.Completed);

                // Calling Read in async reader or ReadAsync in sync reader should fail.
                reader = this.CreateParameterReaderForRequestOrResponse(model, functionImport, testConfiguration);
                if (reader != null)
                {
                    if (testConfiguration.Synchronous)
                    {
                        this.Assert.ExpectedException(
                            () => ((ODataParameterReaderTestWrapper)reader).ParameterReader.ReadAsync(),
                            ODataExpectedExceptions.ODataException("ODataParameterReaderCore_AsyncCallOnSyncReader"), this.ExceptionVerifier);
                        this.Assert.AreEqual(ODataParameterReaderState.Start, reader.State, "Reader should be in 'Start' state.");
                    }
                    else
                    {
                        this.Assert.ExpectedException(
                            () => ((ODataParameterReaderTestWrapper)reader).ParameterReader.Read(),
                            ODataExpectedExceptions.ODataException("ODataParameterReaderCore_SyncCallOnAsyncReader"), this.ExceptionVerifier);
                        this.Assert.AreEqual(ODataParameterReaderState.Start, reader.State, "Reader should be in 'Start' state.");
                    }
                }

                // Reading payload with parameter not in metadata should fail.
                reader = this.CreateParameterReaderForRequestOrResponse(model, functionImport, testConfiguration, "{ p1 : \"foo\" }");
                this.RunParameterReaderErrorTest(reader,
                                                 ODataExpectedExceptions.ODataException("ODataParameterReaderCore_ParameterNameNotInMetadata", "p1", "FunctionImport_Primitive"));

                // Reading payload with first parameter not in metadata should fail.
                reader = this.CreateParameterReaderForRequestOrResponse(model, functionImport, testConfiguration, "{ p2 : \"foo\", primitive : \"bar\"  }");
                this.RunParameterReaderErrorTest(reader,
                                                 ODataExpectedExceptions.ODataException("ODataParameterReaderCore_ParameterNameNotInMetadata", "p2", "FunctionImport_Primitive"));

                // Reading payload with additional parameter not in metadata should fail.
                reader = this.CreateParameterReaderForRequestOrResponse(model, functionImport, testConfiguration, "{ primitive : \"foo\", p2 : \"bar\"  }");
                if (reader != null)
                {
                    reader.Read();
                    this.RunParameterReaderErrorTest(reader,
                                                     ODataExpectedExceptions.ODataException("ODataParameterReaderCore_ParameterNameNotInMetadata", "p2", "FunctionImport_Primitive"));
                }

                // Reading a parameter of stream primitive type should fail.
                reader = this.CreateParameterReaderForRequestOrResponse(model, functionImport_Stream, testConfiguration, "{ stream : \"foo\" }");
                this.RunParameterReaderErrorTest(reader,
                                                 ODataExpectedExceptions.ODataException("ODataJsonLightParameterDeserializer_UnsupportedPrimitiveParameterType", "stream", "Stream"));
            });
        }