public void BatchReaderStreamProcessPartHeaderTest()
        {
            IEnumerable <PartHeaderTestCase> testCases = new PartHeaderTestCase[]
            {
                #region Missing required headers
                new PartHeaderTestCase
                {
                    DebugDescription = "Read a part header with no headers; this will fail since the Content-Type header is required.",
                    PayloadFunc      = builder => builder
                                       .LineFeed()
                                       .ResetMemoryStream(),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataBatchReaderStream_MissingContentTypeHeader"),
                },
                new PartHeaderTestCase
                {
                    DebugDescription = "Read a part header with only a Content-Type header; since there is Content-Transfer-Encoding header this test will fail.",
                    PayloadFunc      = builder => builder
                                       .Header("Content-Type", "application/http")
                                       .ResetMemoryStream(),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataBatchReaderStream_MissingOrInvalidContentEncodingHeader"),
                },
                #endregion
                #region Content-Type header and boundary
                new PartHeaderTestCase
                {
                    DebugDescription = "Read a part header with an invalid content type; this will fail.",
                    PayloadFunc      = builder => builder
                                       .Header("Content-Type", "application/xml")
                                       .Header("Content-Transfer-Encoding", "binary")
                                       .ResetMemoryStream(),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataBatchReaderStream_InvalidContentTypeSpecified", "Content-Type", "application/xml", "multipart/mixed", "application/http"),
                },
                new PartHeaderTestCase
                {
                    DebugDescription = "Read a part header with only a Content-Type and Content-Transfer-Encoding header; since there is no empty line after the header we try to continue reading headers but run out of data from the stream.",
                    PayloadFunc      = builder => builder
                                       .Header("Content-Type", "application/http")
                                       .Header("Content-Transfer-Encoding", "binary")
                                       .ResetMemoryStream(),
                },
                #endregion
                #region Content-Transfer-Encoding header
                new PartHeaderTestCase
                {
                    DebugDescription = "Read a part header with an invalid Content-Transfer-Encoding.",
                    PayloadFunc      = builder => builder
                                       .Header("Content-Type", "application/http")
                                       .Header("Content-Transfer-Encoding", "non-binary")
                                       .ResetMemoryStream(),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataBatchReaderStream_MissingOrInvalidContentEncodingHeader", "Content-Transfer-Encoding", "binary"),
                },
                #endregion
                #region Line feeds after headers
                new PartHeaderTestCase
                {
                    DebugDescription = "Read an operation part header with a line feed after the header and some content.",
                    PayloadFunc      = builder => builder
                                       .Header("Content-Type", "application/http")
                                       .Header("Content-Transfer-Encoding", "binary")
                                       .LineFeed()
                                       .String("Some payload")
                                       .ResetMemoryStream(),
                    ExpectChangeSetPart = false,
                    ExpectedHeaders     = new Dictionary <string, string>
                    {
                        { "Content-Type", "application/http" },
                        { "Content-Transfer-Encoding", "binary" },
                    }
                },
                new PartHeaderTestCase
                {
                    DebugDescription = "Read an operation part header with no line feed after the header and some content; will fail.",
                    PayloadFunc      = builder => builder
                                       .Header("Content-Type", "application/http")
                                       .Header("Content-Transfer-Encoding", "binary")
                                       .String("Some payload")
                                       .ResetMemoryStream(),
                    ExpectChangeSetPart = false,
                    ExpectedException   = ODataExpectedExceptions.ODataException("ODataBatchReaderStream_InvalidHeaderSpecified", "Some payload"),
                },
                new PartHeaderTestCase
                {
                    DebugDescription = "Read an operation part header with multiple line feeds after the header and some content.",
                    PayloadFunc      = builder => builder
                                       .Header("Content-Type", "application/http")
                                       .Header("Content-Transfer-Encoding", "binary")
                                       .LineFeed()
                                       .LineFeed()
                                       .String("Some payload")
                                       .ResetMemoryStream(),
                    ExpectChangeSetPart = false,
                    ExpectedHeaders     = new Dictionary <string, string>
                    {
                        { "Content-Type", "application/http" },
                        { "Content-Transfer-Encoding", "binary" },
                    }
                },
                new PartHeaderTestCase
                {
                    DebugDescription = "Read a changeset part header with a line feed after the header and some content.",
                    PayloadFunc      = builder => builder
                                       .Header("Content-Type", "multipart/mixed;boundary=my_boundary")
                                       .LineFeed()
                                       .String("Some payload")
                                       .ResetMemoryStream(),
                    ExpectChangeSetPart = true,
                    ExpectedHeaders     = new Dictionary <string, string>
                    {
                        { "Content-Type", "multipart/mixed;boundary=my_boundary" },
                    }
                },
                new PartHeaderTestCase
                {
                    DebugDescription = "Read a changeset part header with no line feed after the header and some content; will fail.",
                    PayloadFunc      = builder => builder
                                       .Header("Content-Type", "multipart/mixed;boundary=my_boundary")
                                       .String("Some payload")
                                       .ResetMemoryStream(),
                    ExpectChangeSetPart = true,
                    ExpectedException   = ODataExpectedExceptions.ODataException("ODataBatchReaderStream_InvalidHeaderSpecified", "Some payload"),
                },
                new PartHeaderTestCase
                {
                    DebugDescription = "Read a changeset part header with multiple line feeds after the header and some content.",
                    PayloadFunc      = builder => builder
                                       .Header("Content-Type", "multipart/mixed;boundary=my_boundary")
                                       .LineFeed()
                                       .LineFeed()
                                       .String("Some payload")
                                       .ResetMemoryStream(),
                    ExpectChangeSetPart = true,
                    ExpectedHeaders     = new Dictionary <string, string>
                    {
                        { "Content-Type", "multipart/mixed;boundary=my_boundary" },
                    }
                },
                #endregion
                #region Multiple (non-OData) headers
                new PartHeaderTestCase
                {
                    DebugDescription = "Read an operation part header with multiple headers.",
                    PayloadFunc      = builder => builder
                                       .Header("a", "b")
                                       .Header("Content-Type", "application/http")
                                       .Header("c", "d")
                                       .Header("Content-Transfer-Encoding", "binary")
                                       .Header("e", "f")
                                       .LineFeed()
                                       .String("Some payload")
                                       .ResetMemoryStream(),
                    ExpectChangeSetPart = false,
                    ExpectedHeaders     = new Dictionary <string, string>
                    {
                        { "Content-Type", "application/http" },
                        { "Content-Transfer-Encoding", "binary" },
                        { "a", "b" },
                        { "c", "d" },
                        { "e", "f" },
                    }
                },
                new PartHeaderTestCase
                {
                    DebugDescription = "Read an operation part header with an invalid header.",
                    PayloadFunc      = builder => builder
                                       .Header("Content-Type", "application/http")
                                       .Header("Content-Transfer-Encoding", "binary")
                                       .String("InvalidHeader Does not use a colon!")
                                       .ResetMemoryStream(),
                    ExpectChangeSetPart = false,
                    ExpectedException   = ODataExpectedExceptions.ODataException("ODataBatchReaderStream_InvalidHeaderSpecified", "InvalidHeader Does not use a colon!"),
                },
                new PartHeaderTestCase
                {
                    DebugDescription = "Read an operation part header with a duplicate header.",
                    PayloadFunc      = builder => builder
                                       .Header("Content-Type", "application/http")
                                       .Header("Content-Transfer-Encoding", "binary")
                                       .Header("a", "b")
                                       .Header("a", "c")
                                       .LineFeed()
                                       .ResetMemoryStream(),
                    ExpectChangeSetPart = false,
                    ExpectedException   = ODataExpectedExceptions.ODataException("ODataBatchReaderStream_DuplicateHeaderFound", "a"),
                },
                #endregion
            };

            this.CombinatorialEngineProvider.RunCombinations(
                testCases,
                (testCase) =>
            {
                this.Injector.InjectDependenciesInto(testCase);
                testCase.Run();
            });
        }
        public void BatchReaderStreamProcessPartHeaderTest()
        {
            IEnumerable<PartHeaderTestCase> testCases = new PartHeaderTestCase[]
            {
                #region Missing required headers
                new PartHeaderTestCase
                {
                    DebugDescription = "Read a part header with no headers; this will fail since the Content-Type header is required.",
                    PayloadFunc = builder => builder
                        .LineFeed()
                        .ResetMemoryStream(),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataBatchReaderStream_MissingContentTypeHeader"),
                },
                new PartHeaderTestCase
                {
                    DebugDescription = "Read a part header with only a Content-Type header; since there is Content-Transfer-Encoding header this test will fail.",
                    PayloadFunc = builder => builder
                        .Header("Content-Type", "application/http")
                        .ResetMemoryStream(),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataBatchReaderStream_MissingOrInvalidContentEncodingHeader"),
                },
                #endregion
                #region Content-Type header and boundary
                new PartHeaderTestCase
                {
                    DebugDescription = "Read a part header with an invalid content type; this will fail.",
                    PayloadFunc = builder => builder
                        .Header("Content-Type", "application/xml")
                        .Header("Content-Transfer-Encoding", "binary")
                        .ResetMemoryStream(),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataBatchReaderStream_InvalidContentTypeSpecified", "Content-Type", "application/xml", "multipart/mixed", "application/http"),
                },
                new PartHeaderTestCase
                {
                    DebugDescription = "Read a part header with only a Content-Type and Content-Transfer-Encoding header; since there is no empty line after the header we try to continue reading headers but run out of data from the stream.",
                    PayloadFunc = builder => builder
                        .Header("Content-Type", "application/http")
                        .Header("Content-Transfer-Encoding", "binary")
                        .ResetMemoryStream(),
                },
                #endregion
                #region Content-Transfer-Encoding header
                new PartHeaderTestCase
                {
                    DebugDescription = "Read a part header with an invalid Content-Transfer-Encoding.",
                    PayloadFunc = builder => builder
                        .Header("Content-Type", "application/http")
                        .Header("Content-Transfer-Encoding", "non-binary")
                        .ResetMemoryStream(),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataBatchReaderStream_MissingOrInvalidContentEncodingHeader", "Content-Transfer-Encoding", "binary"),
                },
                #endregion
                #region Line feeds after headers
                new PartHeaderTestCase
                {
                    DebugDescription = "Read an operation part header with a line feed after the header and some content.",
                    PayloadFunc = builder => builder
                        .Header("Content-Type", "application/http")
                        .Header("Content-Transfer-Encoding", "binary")
                        .LineFeed()
                        .String("Some payload")
                        .ResetMemoryStream(),
                    ExpectChangeSetPart = false,
                    ExpectedHeaders = new Dictionary<string, string>
                    {
                        { "Content-Type", "application/http" },
                        { "Content-Transfer-Encoding", "binary" },
                    }
                },
                new PartHeaderTestCase
                {
                    DebugDescription = "Read an operation part header with no line feed after the header and some content; will fail.",
                    PayloadFunc = builder => builder
                        .Header("Content-Type", "application/http")
                        .Header("Content-Transfer-Encoding", "binary")
                        .String("Some payload")
                        .ResetMemoryStream(),
                    ExpectChangeSetPart = false,
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataBatchReaderStream_InvalidHeaderSpecified", "Some payload"),
                },
                new PartHeaderTestCase
                {
                    DebugDescription = "Read an operation part header with multiple line feeds after the header and some content.",
                    PayloadFunc = builder => builder
                        .Header("Content-Type", "application/http")
                        .Header("Content-Transfer-Encoding", "binary")
                        .LineFeed()
                        .LineFeed()
                        .String("Some payload")
                        .ResetMemoryStream(),
                    ExpectChangeSetPart = false,
                    ExpectedHeaders = new Dictionary<string, string>
                    {
                        { "Content-Type", "application/http" },
                        { "Content-Transfer-Encoding", "binary" },
                    }
                },
                new PartHeaderTestCase
                {
                    DebugDescription = "Read a changeset part header with a line feed after the header and some content.",
                    PayloadFunc = builder => builder
                        .Header("Content-Type", "multipart/mixed;boundary=my_boundary")
                        .LineFeed()
                        .String("Some payload")
                        .ResetMemoryStream(),
                    ExpectChangeSetPart = true,
                    ExpectedHeaders = new Dictionary<string, string>
                    {
                        { "Content-Type", "multipart/mixed;boundary=my_boundary" },
                    }
                },
                new PartHeaderTestCase
                {
                    DebugDescription = "Read a changeset part header with no line feed after the header and some content; will fail.",
                    PayloadFunc = builder => builder
                        .Header("Content-Type", "multipart/mixed;boundary=my_boundary")
                        .String("Some payload")
                        .ResetMemoryStream(),
                    ExpectChangeSetPart = true,
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataBatchReaderStream_InvalidHeaderSpecified", "Some payload"),
                },
                new PartHeaderTestCase
                {
                    DebugDescription = "Read a changeset part header with multiple line feeds after the header and some content.",
                    PayloadFunc = builder => builder
                        .Header("Content-Type", "multipart/mixed;boundary=my_boundary")
                        .LineFeed()
                        .LineFeed()
                        .String("Some payload")
                        .ResetMemoryStream(),
                    ExpectChangeSetPart = true,
                    ExpectedHeaders = new Dictionary<string, string>
                    {
                        { "Content-Type", "multipart/mixed;boundary=my_boundary" },
                    }
                },
                #endregion
                #region Multiple (non-OData) headers
                new PartHeaderTestCase
                {
                    DebugDescription = "Read an operation part header with multiple headers.",
                    PayloadFunc = builder => builder
                        .Header("a", "b")
                        .Header("Content-Type", "application/http")
                        .Header("c", "d")
                        .Header("Content-Transfer-Encoding", "binary")
                        .Header("e", "f")
                        .LineFeed()
                        .String("Some payload")
                        .ResetMemoryStream(),
                    ExpectChangeSetPart = false,
                    ExpectedHeaders = new Dictionary<string, string>
                    {
                        { "Content-Type", "application/http" },
                        { "Content-Transfer-Encoding", "binary" },
                        { "a", "b" },
                        { "c", "d" },
                        { "e", "f" },
                    }
                },
                new PartHeaderTestCase
                {
                    DebugDescription = "Read an operation part header with an invalid header.",
                    PayloadFunc = builder => builder
                        .Header("Content-Type", "application/http")
                        .Header("Content-Transfer-Encoding", "binary")
                        .String("InvalidHeader Does not use a colon!")
                        .ResetMemoryStream(),
                    ExpectChangeSetPart = false,
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataBatchReaderStream_InvalidHeaderSpecified", "InvalidHeader Does not use a colon!"),
                },
                new PartHeaderTestCase
                {
                    DebugDescription = "Read an operation part header with a duplicate header.",
                    PayloadFunc = builder => builder
                        .Header("Content-Type", "application/http")
                        .Header("Content-Transfer-Encoding", "binary")
                        .Header("a", "b")
                        .Header("a", "c")
                        .LineFeed()
                        .ResetMemoryStream(),
                    ExpectChangeSetPart = false,
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataBatchReaderStream_DuplicateHeaderFound", "a"),
                },
                #endregion
            };

            this.CombinatorialEngineProvider.RunCombinations(
                testCases,
                (testCase) =>
                {
                    this.Injector.InjectDependenciesInto(testCase);
                    testCase.Run();
                });
        }
        public void BatchReaderStreamHeaderNameValidationTest()
        {
            IEnumerable <PartHeaderTestCase> testCases = new PartHeaderTestCase[]
            {
                new PartHeaderTestCase
                {
                    DebugDescription = "Read two content type headers with differnet casing.",
                    PayloadFunc      = builder => builder
                                       .Header("cOnTenT-tYpE", "multipart/mixed;boundary=changeset_boundary")
                                       .ResetMemoryStream(),
                    ExpectedHeaders = new Dictionary <string, string>
                    {
                        { "cOnTenT-tYpE", "multipart/mixed;boundary=changeset_boundary" },
                    }
                },
                new PartHeaderTestCase
                {
                    DebugDescription = "Different case of header names.",
                    PayloadFunc      = builder => builder
                                       .Header("ab", "b")
                                       .Header("content-type", "application/http")
                                       .Header("c", "d")
                                       .Header("content-transfer-encoding", "binary")
                                       .LineFeed()
                                       .String("Some payload")
                                       .ResetMemoryStream(),
                    ExpectChangeSetPart = false,
                    ExpectedHeaders     = new Dictionary <string, string>
                    {
                        { "Content-Type", "application/http" },
                        { "Content-Transfer-Encoding", "binary" },
                        { "AB", "b" },
                        { "c", "d" },
                    }
                },
                new PartHeaderTestCase
                {
                    DebugDescription = "Two headers with different cases; one case-sensitive match.",
                    PayloadFunc      = builder => builder
                                       .Header("ab", "b1")
                                       .Header("Ab", "b2")
                                       .Header("content-type", "application/http")
                                       .Header("content-transfer-encoding", "binary")
                                       .LineFeed()
                                       .String("Some payload")
                                       .ResetMemoryStream(),
                    ExpectChangeSetPart = false,
                    ExpectedHeaders     = new Dictionary <string, string>
                    {
                        { "Content-Type", "application/http" },
                        { "Content-Transfer-Encoding", "binary" },
                        { "Ab", "b2" },
                    },
                },
                new PartHeaderTestCase
                {
                    DebugDescription = "Two headers with different cases; no case-sensitive match.",
                    PayloadFunc      = builder => builder
                                       .Header("ab", "b1")
                                       .Header("Ab", "b2")
                                       .Header("content-type", "application/http")
                                       .Header("content-transfer-encoding", "binary")
                                       .LineFeed()
                                       .String("Some payload")
                                       .ResetMemoryStream(),
                    ExpectChangeSetPart = false,
                    ExpectedHeaders     = new Dictionary <string, string>
                    {
                        { "Content-Type", "application/http" },
                        { "Content-Transfer-Encoding", "binary" },
                        { "AB", "b3" },
                    },
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataBatchOperationHeaderDictionary_DuplicateCaseInsensitiveKeys", "AB")
                },
                new PartHeaderTestCase
                {
                    DebugDescription = "Multiple headers with different cases; one case-sensitive match.",
                    PayloadFunc      = builder => builder
                                       .Header("ab", "b1")
                                       .Header("Ab", "b2")
                                       .Header("AB", "b3")
                                       .Header("content-type", "application/http")
                                       .Header("content-transfer-encoding", "binary")
                                       .LineFeed()
                                       .String("Some payload")
                                       .ResetMemoryStream(),
                    ExpectChangeSetPart = false,
                    ExpectedHeaders     = new Dictionary <string, string>
                    {
                        { "Content-Type", "application/http" },
                        { "Content-Transfer-Encoding", "binary" },
                        { "AB", "b3" },
                    },
                },
            };

            this.CombinatorialEngineProvider.RunCombinations(
                testCases,
                (testCase) =>
            {
                this.Injector.InjectDependenciesInto(testCase);
                testCase.Run();
            });
        }
        public void BatchReaderStreamHeaderNameValidationTest()
        {
            IEnumerable<PartHeaderTestCase> testCases = new PartHeaderTestCase[]
            {
                new PartHeaderTestCase
                {
                    DebugDescription = "Read two content type headers with differnet casing.",
                    PayloadFunc = builder => builder
                        .Header("cOnTenT-tYpE", "multipart/mixed;boundary=changeset_boundary")
                        .ResetMemoryStream(),
                    ExpectedHeaders = new Dictionary<string, string> 
                    {
                        { "cOnTenT-tYpE", "multipart/mixed;boundary=changeset_boundary" },
                    }
                },
                new PartHeaderTestCase
                {
                    DebugDescription = "Different case of header names.",
                    PayloadFunc = builder => builder
                        .Header("ab", "b")
                        .Header("content-type", "application/http")
                        .Header("c", "d")
                        .Header("content-transfer-encoding", "binary")
                        .LineFeed()
                        .String("Some payload")
                        .ResetMemoryStream(),
                    ExpectChangeSetPart = false,
                    ExpectedHeaders = new Dictionary<string, string>
                    {
                        { "Content-Type", "application/http" },
                        { "Content-Transfer-Encoding", "binary" },
                        { "AB", "b" },
                        { "c", "d" },
                    }
                },
                new PartHeaderTestCase
                {
                    DebugDescription = "Two headers with different cases; one case-sensitive match.",
                    PayloadFunc = builder => builder
                        .Header("ab", "b1")
                        .Header("Ab", "b2")
                        .Header("content-type", "application/http")
                        .Header("content-transfer-encoding", "binary")
                        .LineFeed()
                        .String("Some payload")
                        .ResetMemoryStream(),
                    ExpectChangeSetPart = false,
                    ExpectedHeaders = new Dictionary<string, string>
                    {
                        { "Content-Type", "application/http" },
                        { "Content-Transfer-Encoding", "binary" },
                        { "Ab", "b2" },
                    },
                },
                new PartHeaderTestCase
                {
                    DebugDescription = "Two headers with different cases; no case-sensitive match.",
                    PayloadFunc = builder => builder
                        .Header("ab", "b1")
                        .Header("Ab", "b2")
                        .Header("content-type", "application/http")
                        .Header("content-transfer-encoding", "binary")
                        .LineFeed()
                        .String("Some payload")
                        .ResetMemoryStream(),
                    ExpectChangeSetPart = false,
                    ExpectedHeaders = new Dictionary<string, string>
                    {
                        { "Content-Type", "application/http" },
                        { "Content-Transfer-Encoding", "binary" },
                        { "AB", "b3" },
                    },
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataBatchOperationHeaderDictionary_DuplicateCaseInsensitiveKeys", "AB")
                },
                new PartHeaderTestCase
                {
                    DebugDescription = "Multiple headers with different cases; one case-sensitive match.",
                    PayloadFunc = builder => builder
                        .Header("ab", "b1")
                        .Header("Ab", "b2")
                        .Header("AB", "b3")
                        .Header("content-type", "application/http")
                        .Header("content-transfer-encoding", "binary")
                        .LineFeed()
                        .String("Some payload")
                        .ResetMemoryStream(),
                    ExpectChangeSetPart = false,
                    ExpectedHeaders = new Dictionary<string, string>
                    {
                        { "Content-Type", "application/http" },
                        { "Content-Transfer-Encoding", "binary" },
                        { "AB", "b3" },
                    },
                },
            };

            this.CombinatorialEngineProvider.RunCombinations(
                testCases,
                (testCase) =>
                {
                    this.Injector.InjectDependenciesInto(testCase);
                    testCase.Run();
                });
        }