コード例 #1
0
        public void ServiceDocumentNoWhitespaceTest()
        {
            var testCases = new[]
            {
                "<service xmlns:app='http://www.w3.org/2007/app' " +
                     "xmlns='http://www.w3.org/2007/app' xmlns:atom='http://www.w3.org/2005/Atom'>" +
                     "<workspace>" +
                        "<collection href='http://odata.org/Products'>" +
                            "<atom:title>Products</atom:title>" +
                        "</collection>" +
                        "<collection href='http://odata.org/Orders'>" +
                            "<atom:title>Orders</atom:title>" +
                        "</collection>" +
                    "</workspace>" +
                "</service>",
                "<service xmlns:app='http://www.w3.org/2007/app' " +
                     "xmlns='http://www.w3.org/2007/app' xmlns:atom='http://www.w3.org/2005/Atom'>" +
                     "<workspace>" +
                        "<collection href='http://odata.org/Products'>" +
                            "<atom:title>Products</atom:title>" +
                        "</collection>" +
                    "</workspace>" +
                "</service>",
                "<service xmlns:app='http://www.w3.org/2007/app' " +
                     "xmlns='http://www.w3.org/2007/app' xmlns:atom='http://www.w3.org/2005/Atom'>" +
                     "<workspace>" +
                        "<collection href='http://odata.org/Products'>" +
                        "</collection>" +
                        "<collection href='http://odata.org/Orders'>" +
                        "</collection>" +
                    "</workspace>" +
                "</service>",
                "<service xmlns:app='http://www.w3.org/2007/app' " +
                     "xmlns='http://www.w3.org/2007/app' xmlns:atom='http://www.w3.org/2005/Atom'>" +
                     "<workspace>" +
                        "<collection href='http://odata.org/Products'>" +
                        "</collection>" +
                    "</workspace>" +
                "</service>",
                "<service xmlns:app='http://www.w3.org/2007/app' " +
                     "xmlns='http://www.w3.org/2007/app' xmlns:atom='http://www.w3.org/2005/Atom'>" +
                     "<workspace>" +
                        "<collection href='http://odata.org/Products'/>" +
                        "<collection href='http://odata.org/Orders'/>" +
                    "</workspace>" +
                "</service>",
                "<service xmlns:app='http://www.w3.org/2007/app' " +
                     "xmlns='http://www.w3.org/2007/app' xmlns:atom='http://www.w3.org/2005/Atom'>" +
                     "<workspace>" +
                        "<collection href='http://odata.org/Products'/>" +
                    "</workspace>" +
                "</service>",
                "<service xmlns:app='http://www.w3.org/2007/app' " +
                     "xmlns='http://www.w3.org/2007/app' xmlns:atom='http://www.w3.org/2005/Atom'>" +
                     "<workspace>" +
                    "</workspace>" +
                "</service>",
                "<service xmlns:app='http://www.w3.org/2007/app' " +
                     "xmlns='http://www.w3.org/2007/app' xmlns:atom='http://www.w3.org/2005/Atom'>" +
                     "<workspace/>" +
                "</service>",
                "<service xmlns:app='http://www.w3.org/2007/app' " +
                     "xmlns='http://www.w3.org/2007/app' xmlns:atom='http://www.w3.org/2005/Atom'>" +
                     "<workspace>" +
                        "<collection href='http://odata.org/Products'>" +
                            "<atom:title>Products</atom:title>" +
                            "<accept>image/png</accept>" +
                            "<categories href='http://somecategories.com'/>" +
                        "</collection>" +
                    "</workspace>" +
                "</service>",
                "<service xmlns:app='http://www.w3.org/2007/app' " +
                     "xmlns='http://www.w3.org/2007/app' xmlns:atom='http://www.w3.org/2005/Atom'>" +
                     "<workspace>" +
                        "<collection href='http://odata.org/Products'>" +
                            "<accept>image/png</accept>" +
                            "<categories href='http://somecategories.com'/>" +
                            "<atom:title>Products</atom:title>" +
                        "</collection>" +
                    "</workspace>" +
                "</service>",
                "<service xmlns:app='http://www.w3.org/2007/app' " +
                     "xmlns='http://www.w3.org/2007/app' xmlns:atom='http://www.w3.org/2005/Atom'>" +
                     "<workspace>" +
                        "<collection href='http://odata.org/Products'>" +
                            "<accept>image/png</accept>" +
                            "<categories href='http://somecategories.com'/>" +
                            "<atom:title>Products</atom:title>" +
                        "</collection>" +
                        "<collection href='http://odata.org/Orders'>" +
                            "<accept>image/png</accept>" +
                            "<categories href='http://somecategories.com'/>" +
                            "<atom:title>Orders</atom:title>" +
                        "</collection>" +
                    "</workspace>" +
                "</service>",
                "<service xmlns:app='http://www.w3.org/2007/app' " +
                     "xmlns='http://www.w3.org/2007/app' xmlns:atom='http://www.w3.org/2005/Atom'>" +
                     "<workspace>" +
                        "<collection href='http://odata.org/Products'>" +
                            "<cf:cf xmlns:cf='uri'/>" +
                        "</collection>" +
                        "<collection href='http://odata.org/Orders'>" +
                            "<cf:cf xmlns:cf='uri'/>" +
                        "</collection>" +
                    "</workspace>" +
                "</service>",
                "<service xmlns:app='http://www.w3.org/2007/app' " +
                     "xmlns='http://www.w3.org/2007/app' xmlns:atom='http://www.w3.org/2005/Atom'>" +
                     "<workspace>" +
                        "<collection href='http://odata.org/Products'>" +
                            "<cf:cf xmlns:cf='uri'/>" +
                        "</collection>" +
                    "</workspace>" +
                "</service>",
                "<service xmlns:app='http://www.w3.org/2007/app' " +
                     "xmlns='http://www.w3.org/2007/app' xmlns:atom='http://www.w3.org/2005/Atom'>" +
                     "<workspace>" +
                        "<collection href='http://odata.org/Products'>" +
                            "<cf:cf xmlns:cf='uri'/>" +
                        "</collection>" +
                        "<cf:cf xmlns:cf='uri'/>" +
                        "<collection href='http://odata.org/Orders'>" +
                            "<cf:cf xmlns:cf='uri'/>" +
                        "</collection>" +
                        "<cf:cf xmlns:cf='uri'/>" +
                    "</workspace>" +
                "</service>",
                "<service xmlns:app='http://www.w3.org/2007/app' " +
                     "xmlns='http://www.w3.org/2007/app' xmlns:atom='http://www.w3.org/2005/Atom'>" +
                     "<workspace>" +
                        "<cf:cf xmlns:cf='uri'/>" +
                    "</workspace>" +
                "</service>",
            };

            this.CombinatorialEngineProvider.RunCombinations(
                testCases,
                testCase =>
                {
                    // Just validate that the input strings above don't include any whitespaces.
                    using (XmlReader xmlReader = XmlReader.Create(new StringReader(testCase)))
                    {
                        while (xmlReader.Read())
                        {
                            this.Assert.AreNotEqual(XmlNodeType.Whitespace, xmlReader.NodeType, "No whitespaces please");
                            this.Assert.AreNotEqual(XmlNodeType.SignificantWhitespace, xmlReader.NodeType, "No whitespaces please");
                        }
                    }

                    // Run the payload through the reader and make sure it doesn't fail.
                    TestResponseMessage message = new TestResponseMessage(new MemoryStream(Encoding.UTF8.GetBytes(testCase)));
                    message.SetContentType(ODataFormat.Atom, ODataPayloadKind.ServiceDocument);
                    ODataMessageReaderSettings settings = new ODataMessageReaderSettings { EnableAtom = true };

                    using (ODataMessageReader messageReader = new ODataMessageReader(message, settings))
                    {
                        messageReader.ReadServiceDocument();
                    }
                });
        }