Ejemplo n.º 1
0
        public void CreateCollectionReaderArgumentTest()
        {
            IEdmEntityType      entityType                         = null;
            IEdmComplexType     complexType                        = null;
            IEdmModel           model                              = this.CreateTestMetadata(out entityType, out complexType);
            IEdmEntityContainer defaultContainer                   = model.FindEntityContainer("TestNS.TestContainer");
            IEdmOperationImport primitiveValueFunctionImport       = defaultContainer.FindOperationImports("PrimitiveValueFunctionImport").Single();
            IEdmOperationImport collectionOfEntitiesFunctionImport = defaultContainer.FindOperationImports("CollectionOfEntitiesFunctionImport").Single();

            this.CombinatorialEngineProvider.RunCombinations(
                this.ReaderTestConfigurationProvider.ExplicitFormatConfigurations,
                (testConfiguration) =>
            {
                TestMessage message = TestReaderUtils.CreateInputMessageFromStream(new TestStream(), testConfiguration);
                ODataMessageReaderTestWrapper messageReader = TestReaderUtils.CreateMessageReader(message, null, testConfiguration);
                this.Assert.ExpectedException(
                    () => messageReader.CreateODataCollectionReader(new EdmComplexTypeReference(complexType, false)),
                    ODataExpectedExceptions.ArgumentException("ODataMessageReader_ExpectedTypeSpecifiedWithoutMetadata", "expectedItemTypeReference"),
                    this.ExceptionVerifier);

                messageReader = TestReaderUtils.CreateMessageReader(message, model, testConfiguration);
                this.Assert.ExpectedException(
                    () => messageReader.CreateODataCollectionReader(new EdmEntityTypeReference(entityType, false)),
                    ODataExpectedExceptions.ArgumentException("ODataMessageReader_ExpectedCollectionTypeWrongKind", "Entity"),
                    this.ExceptionVerifier);

                messageReader = TestReaderUtils.CreateMessageReader(message, model, testConfiguration);
                this.Assert.ExpectedException(
                    () => messageReader.CreateODataCollectionReader(collectionOfEntitiesFunctionImport),
                    ODataExpectedExceptions.ArgumentException("ODataMessageReader_ExpectedCollectionTypeWrongKind", "Entity"),
                    this.ExceptionVerifier);
            });
        }
Ejemplo n.º 2
0
        private void WriteTopLevelFeed(ODataMessageWriterTestWrapper messageWriter, ODataMessageReaderTestWrapper messageReader, ODataFeed feed)
        {
            var feedWriter = messageWriter.CreateODataFeedWriter();
            Lazy <ODataReader> lazyReader = new Lazy <ODataReader>(() => messageReader.CreateODataFeedReader());

            this.WriteFeed(feedWriter, lazyReader, feed);
        }
Ejemplo n.º 3
0
        private void WriteTopLevelEntry(ODataMessageWriterTestWrapper messageWriter, ODataMessageReaderTestWrapper messageReader, ODataEntry entry)
        {
            ODataWriter        entryWriter     = messageWriter.CreateODataEntryWriter();
            Lazy <ODataReader> lazyEntryReader = new Lazy <ODataReader>(() => messageReader.CreateODataEntryReader());

            this.WriteEntry(entryWriter, lazyEntryReader, entry);
        }
        /// <summary>
        /// Called to write the payload to the specified <paramref name="messageWriter"/>.
        /// </summary>
        /// <param name="messageWriter">The <see cref="ODataMessageWriterTestWrapper"/> to use for writing the payload.</param>
        /// <param name="testConfiguration">The test configuration to generate the payload for.</param>
        protected override void WritePayload(ODataMessageWriterTestWrapper messageWriter, WriterTestConfiguration testConfiguration)
        {
            Debug.Assert(this.messageStream != null, "Streaming test stream must have been created.");
            TestMessage testMessage = this.CreateInputMessageFromStream((TestStream)this.messageStream, testConfiguration, this.PayloadKind, string.Empty, this.UrlResolver);

            testMessage.SetContentType(testConfiguration.Format, this.PayloadKind);

            Exception exception = TestExceptionUtils.RunCatching(() =>
            {
                ODataMessageReaderSettings readerSettings  = this.settings.MessageReaderSettings.Clone();
                readerSettings.EnableMessageStreamDisposal = testConfiguration.MessageWriterSettings.EnableMessageStreamDisposal;

                ReaderTestConfiguration readerConfig = new ReaderTestConfiguration(
                    testConfiguration.Format,
                    readerSettings,
                    testConfiguration.IsRequest,
                    testConfiguration.Synchronous);

                IEdmModel model = this.GetMetadataProvider();
                using (ODataMessageReaderTestWrapper messageReaderWrapper = TestReaderUtils.CreateMessageReader(testMessage, model, readerConfig))
                {
                    ODataPayloadElementToObjectModelConverter payloadElementToOMConverter = new ODataPayloadElementToObjectModelConverter(!testConfiguration.IsRequest);
                    ObjectModelToPayloadElementConverter reverseConverter = new ObjectModelToPayloadElementConverter();
                    ObjectModelWriteReadStreamer streamer = new ObjectModelWriteReadStreamer();

                    this.readObject = reverseConverter.Convert(streamer.WriteMessage(messageWriter, messageReaderWrapper, this.PayloadKind, payloadElementToOMConverter.Convert(this.PayloadElement)), !testConfiguration.IsRequest);
                }
            });
        }
Ejemplo n.º 5
0
        public void ContentTypeHeaderParsingErrorTest()
        {
            var testCases = new ContentTypeTestCase[]
            {
                new ContentTypeTestCase
                {
                    ContentType       = null,
                    ExpectedException = ODataExpectedExceptions.ODataContentTypeException("ODataMessageReader_NoneOrEmptyContentTypeHeader")
                },
                new ContentTypeTestCase
                {
                    ContentType       = string.Empty,
                    ExpectedException = ODataExpectedExceptions.ODataContentTypeException("ODataMessageReader_NoneOrEmptyContentTypeHeader")
                },
                new ContentTypeTestCase
                {
                    ContentType       = ";foo=bar",
                    ExpectedException = ODataExpectedExceptions.ODataContentTypeException("HttpUtils_MediaTypeRequiresSlash", ";foo=bar")
                },
                new ContentTypeTestCase
                {
                    ContentType       = "application/*",
                    ExpectedException = ODataExpectedExceptions.ODataContentTypeException("ODataMessageReader_WildcardInContentType", "application/*")
                },
                new ContentTypeTestCase
                {
                    ContentType       = "*/*",
                    ExpectedException = ODataExpectedExceptions.ODataContentTypeException("ODataMessageReader_WildcardInContentType", "*/*")
                },
                new ContentTypeTestCase
                {
                    ContentType       = "application/json, application/xml",
                    ExpectedException = ODataExpectedExceptions.ODataContentTypeException("MediaTypeUtils_NoOrMoreThanOneContentTypeSpecified", "application/json, application/xml")
                },
            };

            this.CombinatorialEngineProvider.RunCombinations(
                testCases,
                this.ReaderTestConfigurationProvider.AllFormatConfigurations.Where(tc => tc.Format != ODataFormat.Json),
                (testCase, testConfiguration) =>
            {
                // create a message reader and call GetFormat; this should fail with the expected error message
                TestMessage testMessage = TestReaderUtils.CreateInputMessageFromStream(new TestStream(), testConfiguration);
                testMessage.SetHeader(Microsoft.OData.Core.ODataConstants.ContentTypeHeader, testCase.ContentType);
                testMessage.SetHeader(Microsoft.OData.Core.ODataConstants.ContentLengthHeader, testCase.ContentLength.ToString());

                TestExceptionUtils.ExpectedException(
                    this.Assert,
                    () =>
                {
                    using (ODataMessageReaderTestWrapper messageReader = TestReaderUtils.CreateMessageReader(testMessage, null, testConfiguration))
                    {
                        ODataFormat actualFormat = messageReader.DetectPayloadKind().Single().Format;
                    }
                },
                    testCase.ExpectedException,
                    this.ExceptionVerifier);
            });
        }
Ejemplo n.º 6
0
        public override void RunTest(ReaderTestConfiguration testConfiguration)
        {
            //TODO: Use Logger to verify result, right now this change is only to unblock writer testcase checkin
            BaselineLogger logger = null;

            if (this.ShouldSkipForTestConfiguration(testConfiguration))
            {
                return;
            }

            var originalPayload = this.PayloadElement;

            this.PayloadElement = this.PayloadElement.DeepCopy();

            // Create messages (payload gets serialized in createInputMessage)
            TestMessage readerMessage = this.CreateInputMessage(testConfiguration);
            var         settings      = new ODataMessageWriterSettings()
            {
                Version = testConfiguration.Version,
                BaseUri = testConfiguration.MessageReaderSettings.BaseUri,
                EnableMessageStreamDisposal = testConfiguration.MessageReaderSettings.EnableMessageStreamDisposal,
            };

            settings.SetContentType(testConfiguration.Format);

            WriterTestConfiguration writerConfig  = new WriterTestConfiguration(testConfiguration.Format, settings, testConfiguration.IsRequest, testConfiguration.Synchronous);
            TestMessage             writerMessage = TestWriterUtils.CreateOutputMessageFromStream(new TestStream(new MemoryStream()), writerConfig, this.PayloadKind, String.Empty, this.UrlResolver);

            IEdmModel model = this.GetMetadataProvider(testConfiguration);
            WriterTestExpectedResults expectedResult = this.GetExpectedResult(writerConfig);

            ExceptionUtilities.Assert(expectedResult != null, "The expected result could not be determined for the test. Did you specify it?");

            Exception exception = TestExceptionUtils.RunCatching(() =>
            {
                using (ODataMessageReaderTestWrapper messageReaderWrapper = TestReaderUtils.CreateMessageReader(readerMessage, model, testConfiguration))
                    using (ODataMessageWriterTestWrapper messageWriterWrapper = TestWriterUtils.CreateMessageWriter(writerMessage, model, writerConfig, this.settings.Assert))
                    {
                        var streamer = new ObjectModelReadWriteStreamer();
                        streamer.StreamMessage(messageReaderWrapper, messageWriterWrapper, this.PayloadKind, writerConfig);
                        expectedResult.VerifyResult(writerMessage, this.PayloadKind, writerConfig, logger);
                    }
            });

            this.PayloadElement = originalPayload;

            try
            {
                expectedResult.VerifyException(exception);
            }
            catch (Exception)
            {
                this.TraceFailureInformation(testConfiguration);
                throw;
            }
        }
Ejemplo n.º 7
0
        public void CreateResourceReaderArgumentTest()
        {
            IEdmEntityType  entityType  = null;
            IEdmComplexType complexType = null;
            IEdmModel       model       = this.CreateTestMetadata(out entityType, out complexType);

            this.CombinatorialEngineProvider.RunCombinations(
                this.ReaderTestConfigurationProvider.ExplicitFormatConfigurations,
                (testConfiguration) =>
            {
                TestMessage message = TestReaderUtils.CreateInputMessageFromStream(new TestStream(), testConfiguration);
                ODataMessageReaderTestWrapper messageReader = TestReaderUtils.CreateMessageReader(message, null, testConfiguration);
                this.Assert.ExpectedException(
                    () => messageReader.CreateODataResourceReader(entityType),
                    ODataExpectedExceptions.ArgumentException("ODataMessageReader_ExpectedTypeSpecifiedWithoutMetadata", "resourceType"),
                    this.ExceptionVerifier);
            });
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Verifies that the result of the test (the message reader) is what the test expected.
        /// </summary>
        /// <param name="messageReader">The message reader which is the result of the test. This method should use it to read the results
        /// of the parsing and verify those.</param>
        /// <param name="payloadKind">The payload kind specified in the test descriptor.</param>
        /// <param name="testConfiguration">The test configuration to use.</param>
        public override void VerifyResult(
            ODataMessageReaderTestWrapper messageReader,
            ODataPayloadKind payloadKind,
            ReaderTestConfiguration testConfiguration)
        {
            object odataObject = this.settings.MessageToObjectModelReader.ReadMessage(
                messageReader,
                ODataPayloadKind.Batch,
                this.PayloadModel,
                PayloadReaderTestDescriptor.ReaderMetadata.None,
                this.ExpectedBatchPayload,
                testConfiguration);

            // only compare the payloads if the expected payload is not 'null'; null indicates to skip the comparison
            if (this.ExpectedBatchPayload != null)
            {
                ODataPayloadElement actualPayloadElement = this.settings.ObjectModelToPayloadElementConverter.Convert(odataObject, !testConfiguration.IsRequest);
                this.settings.BatchComparer.CompareBatchPayload(this.ExpectedBatchPayload, actualPayloadElement);
            }
        }
        /// <summary>
        /// Verifies that the result of the test (the message reader) is what the test expected.
        /// </summary>
        /// <param name="messageReader">The message reader which is the result of the test. This method should use it to read the results
        /// of the parsing and verify those.</param>
        /// <param name="payloadKind">The payload kind specified in the test descriptor.</param>
        /// <param name="testConfiguration">The test configuration to use.</param>
        public override void VerifyResult(
            ODataMessageReaderTestWrapper messageReader,
            ODataPayloadKind payloadKind,
            ReaderTestConfiguration testConfiguration)
        {
            object odataObject = this.settings.MessageToObjectModelReader.ReadMessage(
                messageReader,
                ODataPayloadKind.Batch,
                this.PayloadModel,
                PayloadReaderTestDescriptor.ReaderMetadata.None,
                this.ExpectedBatchPayload, 
                testConfiguration);

            // only compare the payloads if the expected payload is not 'null'; null indicates to skip the comparison
            if (this.ExpectedBatchPayload != null)
            {
                ODataPayloadElement actualPayloadElement = this.settings.ObjectModelToPayloadElementConverter.Convert(odataObject, !testConfiguration.IsRequest);
                this.settings.BatchComparer.CompareBatchPayload(this.ExpectedBatchPayload, actualPayloadElement);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Creates an ODataParameterReader with the given input.
        /// </summary>
        /// <param name="model">Model containing the function import.</param>
        /// <param name="functionImport">function import whose parameters are being read.</param>
        /// <param name="testConfiguration">test configuration.</param>
        /// <param name="payload">optional parameter payload.</param>
        /// <returns>Returns the created ODataParameterReader</returns>
        internal static ODataParameterReaderTestWrapper CreateODataParameterReader(IEdmModel model, IEdmOperationImport functionImport, ReaderTestConfiguration testConfiguration, string payload = null)
        {
            // TODO: ODataLib test item: Add new ODataPayloadElement for parameters payload
            // Once the bug is fixed, we should generate the parameters payload from the new ODataPayloadElement to make
            // tests in this file format agnostic.
            TestStream messageStream;

            if (payload != null)
            {
                messageStream = new TestStream(new MemoryStream(Encoding.UTF8.GetBytes(payload)));
            }
            else
            {
                messageStream = new TestStream();
            }

            TestMessage message = TestReaderUtils.CreateInputMessageFromStream(messageStream, testConfiguration, ODataPayloadKind.Parameter, /*customContentTypeHeader*/ null, /*urlResolver*/ null);
            ODataMessageReaderTestWrapper messageReader = TestReaderUtils.CreateMessageReader(message, model, testConfiguration);

            return(messageReader.CreateODataParameterReader(functionImport));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Write payload kind to message.
        /// </summary>
        /// <param name="messageWriter">Message writer to write payload to.</param>
        /// <param name="payloadKind">The kind of payload we are writing.</param>
        /// <param name="payload">The payload to write.</param>
        /// <param name="functionImport">Function import whose parameters are to be written when the payload kind is Parameters.</param>
        /// <returns>The object read after writing.</returns>
        public ODataItem WriteMessage(ODataMessageWriterTestWrapper messageWriter, ODataMessageReaderTestWrapper messageReader, ODataPayloadKind payloadKind, object payload, IEdmOperationImport functionImport = null)
        {
            ExceptionUtilities.CheckArgumentNotNull(messageWriter, "messageWriter");
            ExceptionUtilities.CheckArgumentNotNull(messageReader, "messageReader");

            switch (payloadKind)
            {
            case ODataPayloadKind.Feed:
                this.WriteTopLevelFeed(messageWriter, messageReader, (ODataFeed)payload);
                break;

            case ODataPayloadKind.Entry:
                this.WriteTopLevelEntry(messageWriter, messageReader, (ODataEntry)payload);
                break;

            default:
                ExceptionUtilities.Assert(false, "The payload kind '{0}' is not yet supported by ObjectModelWriteReadStreamer.", payloadKind);
                break;
            }

            return(readItems.SingleOrDefault());
        }
Ejemplo n.º 12
0
        public void SyncAsyncMismatchTest()
        {
            var model = new EdmModel();
            var payloadDescriptors = Test.OData.Utils.ODataLibTest.TestFeeds.GetFeeds(model, true /*withTypeNames*/);
            var testDescriptors    = this.PayloadDescriptorsToReaderDescriptors(payloadDescriptors);

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.ExplicitFormatConfigurations,
                (testDescriptor, testConfiguration) =>
            {
                var message = TestReaderUtils.CreateInputMessage(testConfiguration, testDescriptor, this.Settings, false);
                message.IgnoreSynchronousError            = true;
                message.TestStream.IgnoreSynchronousError = true;

                Exception exception = TestExceptionUtils.RunCatching(() =>
                {
                    using (ODataMessageReaderTestWrapper messageReaderWrapper = TestReaderUtils.CreateMessageReader(message, model, testConfiguration))
                    {
                        var feedReader = messageReaderWrapper.MessageReader.CreateODataResourceSetReader(model.EntityContainer.FindEntitySet("MyBaseType"), model.EntityTypes().FirstOrDefault());
                        if (testConfiguration.Synchronous)
                        {
                            feedReader.Read();
                            feedReader.ReadAsync();
                        }
                        else
                        {
                            feedReader.ReadAsync();
                            feedReader.Read();
                        }
                    }
                });

                var expected = ODataExpectedExceptions.ODataException("ODataReaderCore_AsyncCallOnSyncReader");
                ExceptionVerifier.VerifyExceptionResult(expected, exception);
            });
        }
        public void StreamMessage(ODataMessageReaderTestWrapper reader, ODataMessageWriterTestWrapper writer, ODataPayloadKind payloadKind, WriterTestConfiguration config)
        {
            ExceptionUtilities.CheckArgumentNotNull(reader, "reader is required");
            ExceptionUtilities.CheckArgumentNotNull(writer, "writer is required");
            ExceptionUtilities.CheckArgumentNotNull(payloadKind, "payloadKind is required");
            ExceptionUtilities.CheckArgumentNotNull(config, "config is required");

            this.testConfiguration = config;

            switch (payloadKind)
            {
            case ODataPayloadKind.Entry:
                this.StartRead(reader.CreateODataEntryReader(), writer.CreateODataEntryWriter());
                break;

            case ODataPayloadKind.Feed:
                this.StartRead(reader.CreateODataFeedReader(), writer.CreateODataFeedWriter());
                break;

            default:
                throw new NotSupportedException("ObjectModelReadWriteStreamer currently supports only feed and entry");
            }
            ;
        }
Ejemplo n.º 14
0
        public void ReadPropertyArgumentTest()
        {
            IEdmEntityType      entityType  = null;
            IEdmComplexType     complexType = null;
            IEdmModel           model       = this.CreateTestMetadata(out entityType, out complexType);
            IEdmEntityContainer container   = model.FindEntityContainer("TestContainer");
            IEdmOperationImport entityValueFunctionImport           = container.FindOperationImports("EntityValueFunctionImport").Single();
            IEdmOperationImport entityCollectionValueFunctionImport = container.FindOperationImports("CollectionOfEntitiesFunctionImport").Single();

            IEdmStructuralProperty entityValueStructuralProperty           = (IEdmStructuralProperty)complexType.FindProperty("EntityProp");
            IEdmStructuralProperty entityCollectionValueStructuralProperty = (IEdmStructuralProperty)complexType.FindProperty("EntityCollectionProp");

            this.CombinatorialEngineProvider.RunCombinations(
                this.ReaderTestConfigurationProvider.ExplicitFormatConfigurations,
                (testConfiguration) =>
            {
                TestMessage message = TestReaderUtils.CreateInputMessageFromStream(new TestStream(), testConfiguration);

                ODataMessageReaderTestWrapper messageReader = TestReaderUtils.CreateMessageReader(message, null, testConfiguration);
                this.Assert.ExpectedException(
                    () => messageReader.ReadProperty(new EdmComplexTypeReference(complexType, false)),
                    ODataExpectedExceptions.ArgumentException("ODataMessageReader_ExpectedTypeSpecifiedWithoutMetadata", "expectedPropertyTypeReference"),
                    this.ExceptionVerifier);

                messageReader = TestReaderUtils.CreateMessageReader(message, model, testConfiguration);
                this.Assert.ExpectedException(
                    () => messageReader.ReadProperty(new EdmEntityTypeReference(entityType, false)),
                    ODataExpectedExceptions.ArgumentException("ODataMessageReader_ExpectedPropertyTypeEntityKind"),
                    this.ExceptionVerifier);

                messageReader = TestReaderUtils.CreateMessageReader(message, model, testConfiguration);
                this.Assert.ExpectedException(
                    () => messageReader.ReadProperty(new EdmCollectionType(new EdmEntityTypeReference(entityType, false)).ToTypeReference()),
                    ODataExpectedExceptions.ArgumentException("ODataMessageReader_ExpectedPropertyTypeEntityCollectionKind"),
                    this.ExceptionVerifier);

                messageReader = TestReaderUtils.CreateMessageReader(message, model, testConfiguration);
                this.Assert.ExpectedException(
                    () => messageReader.ReadProperty(entityValueFunctionImport),
                    ODataExpectedExceptions.ArgumentException("ODataMessageReader_ExpectedPropertyTypeEntityKind"),
                    this.ExceptionVerifier);

                messageReader = TestReaderUtils.CreateMessageReader(message, model, testConfiguration);
                this.Assert.ExpectedException(
                    () => messageReader.ReadProperty(entityCollectionValueFunctionImport),
                    ODataExpectedExceptions.ArgumentException("ODataMessageReader_ExpectedPropertyTypeEntityCollectionKind"),
                    this.ExceptionVerifier);

                messageReader = TestReaderUtils.CreateMessageReader(message, model, testConfiguration);
                this.Assert.ExpectedException(
                    () => messageReader.ReadProperty(entityValueStructuralProperty),
                    ODataExpectedExceptions.ArgumentException("ODataMessageReader_ExpectedPropertyTypeEntityKind"),
                    this.ExceptionVerifier);

                messageReader = TestReaderUtils.CreateMessageReader(message, model, testConfiguration);
                this.Assert.ExpectedException(
                    () => messageReader.ReadProperty(entityCollectionValueStructuralProperty),
                    ODataExpectedExceptions.ArgumentException("ODataMessageReader_ExpectedPropertyTypeEntityCollectionKind"),
                    this.ExceptionVerifier);
            });
        }
Ejemplo n.º 15
0
        public void BatchContentTypeHeaderParsingTest()
        {
            IEnumerable <ContentTypeTestCase> testCases = new ContentTypeTestCase[]
            {
                // correct batch content type
                new ContentTypeTestCase
                {
                    ContentType    = "multipart/mixed;boundary=--aa_bb_cc--",
                    ExpectedFormat = ODataFormat.Batch,
                },

                // missing batch boundary
                new ContentTypeTestCase
                {
                    ContentType       = "multipart/mixed",
                    ExpectedFormat    = ODataFormat.Batch,
                    ExpectedException = ODataExpectedExceptions.ODataException("MediaTypeUtils_BoundaryMustBeSpecifiedForBatchPayloads", "multipart/mixed", "boundary")
                },

                // multiple batch boundary parameters
                new ContentTypeTestCase
                {
                    ContentType       = "multipart/mixed;boundary=boundary1;boundary=boundary2",
                    ExpectedFormat    = ODataFormat.Batch,
                    ExpectedException = ODataExpectedExceptions.ODataException("MediaTypeUtils_BoundaryMustBeSpecifiedForBatchPayloads", "multipart/mixed;boundary=boundary1;boundary=boundary2", "boundary")
                },

                // invalid batch content types
                new ContentTypeTestCase
                {
                    ContentType       = "multipart/bar",
                    ExpectedFormat    = ODataFormat.Batch,
                    ExpectedException = ODataExpectedExceptions.ODataContentTypeException("MediaTypeUtils_CannotDetermineFormatFromContentType", TestMediaTypeUtils.GetSupportedMediaTypes(ODataPayloadKind.Batch), "multipart/bar")
                },
                new ContentTypeTestCase
                {
                    ContentType       = "foo/mixed",
                    ExpectedFormat    = ODataFormat.Batch,
                    ExpectedException = ODataExpectedExceptions.ODataContentTypeException("MediaTypeUtils_CannotDetermineFormatFromContentType", TestMediaTypeUtils.GetSupportedMediaTypes(ODataPayloadKind.Batch), "foo/mixed")
                },
                new ContentTypeTestCase
                {
                    ContentType       = "abc/pqr",
                    ExpectedFormat    = ODataFormat.Batch,
                    ExpectedException = ODataExpectedExceptions.ODataContentTypeException("MediaTypeUtils_CannotDetermineFormatFromContentType", TestMediaTypeUtils.GetSupportedMediaTypes(ODataPayloadKind.Batch), "abc/pqr")
                },
                new ContentTypeTestCase
                {
                    ContentType       = ApplicationJson,
                    ExpectedFormat    = ODataFormat.Batch,
                    ExpectedException = ODataExpectedExceptions.ODataContentTypeException("MediaTypeUtils_CannotDetermineFormatFromContentType", TestMediaTypeUtils.GetSupportedMediaTypes(ODataPayloadKind.Batch), ApplicationJson)
                }
            };

            this.CombinatorialEngineProvider.RunCombinations(
                testCases,
                this.ReaderTestConfigurationProvider.DefaultFormatConfigurations,
                (testCase, testConfiguration) =>
            {
                // create a message reader and call GetFormat; this should fail with the expected error message
                TestMessage testMessage = TestReaderUtils.CreateInputMessageFromStream(new TestStream(), testConfiguration);
                testMessage.SetHeader(Microsoft.OData.Core.ODataConstants.ContentTypeHeader, testCase.ContentType);

                TestExceptionUtils.ExpectedException(
                    this.Assert,
                    () =>
                {
                    using (ODataMessageReaderTestWrapper messageReader = TestReaderUtils.CreateMessageReader(testMessage, null, testConfiguration))
                    {
                        messageReader.CreateODataBatchReader();
                        ODataFormat actualFormat = ODataUtils.GetReadFormat(messageReader.MessageReader);
                        this.Assert.AreEqual(testCase.ExpectedFormat, actualFormat, "Formats don't match.");
                    }
                },
                    testCase.ExpectedException,
                    this.ExceptionVerifier);
            });
        }