示例#1
0
        private static string RunTest(CaseFolding caseFolding, string doctype, bool format, string source, XmlReaderTestCallback callback)
        {
            var pseudoBaseUri = new Uri(string.Format(
                                            "rsrc://{0}/{1}/",
                                            typeof(Tests).Assembly.FullName.Split(',')[0],
                                            typeof(Tests).Namespace));

            // initialize sgml reader
            XmlReader reader = new SgmlReader(
                new StringReader(source),
                pseudoBaseUri,
                pseudoUri =>                    // Stream opener (Uri --> Stream callback)
            {
                var resourcePath = string.Join(
                    ".",
                    pseudoUri.PathAndQuery.Split(
                        new[] { '/' },
                        StringSplitOptions.RemoveEmptyEntries));
                return(new StreamInformation
                {
                    Stream = typeof(Tests).Assembly.GetManifestResourceStream(resourcePath),
                    DefaultEncoding = Encoding.UTF8
                });
            })
            {
                CaseFolding        = caseFolding,
                DocType            = doctype,
                WhitespaceHandling = format == false
            };

            // check if we need to use the LoggingXmlReader
            if (_debug)
            {
                reader = new LoggingXmlReader(reader, Console.Out);
            }

            // initialize xml writer
            var stringWriter  = new StringWriter();
            var xmlTextWriter = new XmlTextWriter(stringWriter);

            if (format)
            {
                xmlTextWriter.Formatting = Formatting.Indented;
            }
            callback(reader, xmlTextWriter);
            xmlTextWriter.Close();

            // reproduce the parsed document
            var actual = stringWriter.ToString();

            // ensure that output can be parsed again
            try
            {
                using (var stringReader = new StringReader(actual))
                {
                    var doc = new XmlDocument();
                    doc.Load(stringReader);
                }
            }
            catch (Exception)
            {
                Assert.Fail("unable to parse sgml reader output:\n{0}", actual);
            }
            return(actual.Trim().Replace("\r", ""));
        }
		private static string RunTest(CaseFolding caseFolding, string doctype, bool format, string source, XmlReaderTestCallback callback)
		{

			var pseudoBaseUri = new Uri(string.Format(
				"rsrc://{0}/{1}/",
				typeof(Tests).Assembly.FullName.Split(',')[0],
				typeof(Tests).Namespace));

			// initialize sgml reader
			XmlReader reader = new SgmlReader(
				new StringReader(source),
				pseudoBaseUri,
				pseudoUri =>	// Stream opener (Uri --> Stream callback)
				{
					var resourcePath = string.Join(
						".",
						pseudoUri.PathAndQuery.Split(
							new[] { '/' },
							StringSplitOptions.RemoveEmptyEntries));
					return new StreamInformation
						{
							Stream = typeof(Tests).Assembly.GetManifestResourceStream(resourcePath),
							DefaultEncoding = Encoding.UTF8
						};
				})
				{
					CaseFolding = caseFolding,
					DocType = doctype,
					WhitespaceHandling = format == false
				};

			// check if we need to use the LoggingXmlReader
			if (_debug)
			{
				reader = new LoggingXmlReader(reader, Console.Out);
			}

			// initialize xml writer
			var stringWriter = new StringWriter();
			var xmlTextWriter = new XmlTextWriter(stringWriter);
			if (format)
			{
				xmlTextWriter.Formatting = Formatting.Indented;
			}
			callback(reader, xmlTextWriter);
			xmlTextWriter.Close();

			// reproduce the parsed document
			var actual = stringWriter.ToString();

			// ensure that output can be parsed again
			try
			{
				using (var stringReader = new StringReader(actual))
				{
					var doc = new XmlDocument();
					doc.Load(stringReader);
				}
			}
			catch (Exception)
			{
				Assert.Fail("unable to parse sgml reader output:\n{0}", actual);
			}
			return actual.Trim().Replace("\r", "");
		}