Esempio n. 1
0
        /// <summary>
        /// Validates a test list or test assembly xml document.
        /// </summary>
        /// <param name="xdoc"></param>
        public static void ValidateTestListXml(XDocument xdoc)
        {
            // First, make sure it's a testcase
            if (xdoc == null)
            {
                throw new ArgumentNullException("xdoc");
            }
            if (xdoc.Root == null)
            {
                throw new ArgumentException("Xml document doesn't contain a root element.", "xdoc");
            }
            if (xdoc.Root.Name != XNames.Testlist &&
                xdoc.Root.Name != XNames.TestProject &&
                xdoc.Root.Name != XNames.TestAssembly
                )
            {
                throw new ArgumentException(String.Format("The root element \"{0}\" should be either \"{1}\", \"{2}\" or \"{3}\".", xdoc.Root.Name, XNames.Testlist, XNames.TestProject, XNames.TestAssembly));
            }

            XmlSchemaSet schemaSet = new XmlSchemaSet();

            schemaSet.Add(UnitTestingSchemaUtil.GetConcurrencySchema());
            schemaSet.Add(UnitTestingSchemaUtil.GetTestListSchema());
            schemaSet.Add(UnitTestingSchemaUtil.GetChessSchema());
            schemaSet.Compile();

            xdoc.Validate(schemaSet, null);
        }
Esempio n. 2
0
        /// <summary>
        /// Validates a test result xml document.
        /// </summary>
        /// <param name="xdoc"></param>
        public static void ValidateTestResultXml(XDocument xdoc)
        {
            // First, make sure it's a testcase
            if (xdoc == null)
            {
                throw new ArgumentNullException("xdoc");
            }
            if (xdoc.Root == null)
            {
                throw new ArgumentException("Xml document doesn't contain a root element.", "xdoc");
            }
            if (xdoc.Root.Name != XTestResultNames.TestResult)
            {
                throw new ArgumentException(String.Format("The root element should be \"{0}\" but is \"{1}\".", XTestResultNames.TestResult, xdoc.Root.Name));
            }

            XmlSchemaSet schemaSet = new XmlSchemaSet();

            schemaSet.Add(UnitTestingSchemaUtil.GetConcurrencySchema());
            schemaSet.Add(UnitTestingSchemaUtil.GetTestListSchema());
            schemaSet.Add(UnitTestingSchemaUtil.GetChessSchema());
            schemaSet.Compile();

            xdoc.Validate(schemaSet, null);
        }