Esempio n. 1
0
        public bool Run()
        {
            if (m_listTestInfo != null)
            {
                try
                {
                    var controller = new XmlTestController();

                    m_nTotalCount = 0;
                    for (int i = 0; i < m_listTestInfo.Count; i++)
                    {
                        var info = m_listTestInfo[i];
                        if (info != null)
                        {
                            if (info.FileName != null)
                            {
                                RunTestFile(info, controller);
                            }
                            else if (info.Directory != null)
                            {
                                RunTestDirectory(info, controller);
                            }
                        }
                    }
                    return(true);
                }
                catch (Exception ex)
                {
                    XmlTestExceptionManager.Publish(ex);
                    return(false);
                }
            }
            return(false);
        }
Esempio n. 2
0
        static void RunInteractive(XmlTestType filter, bool verbose)
        {
            string fileName = String.Empty;

            XmlTestController controller = new XmlTestController();

            TestRunner runner = new TestRunner(filter, verbose);

            PrintMenu();

            fileName = Console.ReadLine().Trim();

            while (fileName != "exit")
            {
                XmlTestCollection listTests = null;
                try
                {
                    if (fileName == "default")
                    {
                        RunDefault();
                    }
                    else
                    {
                        listTests = controller.Load(fileName);
                    }
                }
                catch (Exception ex)
                {
                    XmlTestExceptionManager.Publish(ex);
                }

                if (listTests != null && listTests.Count > 0)
                {
                    listTests.TestEvent += new XmlTextEventHandler(runner.OnSimpleTest);

                    try
                    {
                        Console.WriteLine("Running...{0}", listTests.Name);

                        listTests.RunTests();

                        runner.PrintSimpleTestResult(listTests.Count);

                        runner.SimpleTestReset(XmlTestType.None, verbose);
                    }
                    catch (Exception ex)
                    {
                        XmlTestExceptionManager.Publish(ex);
                    }
                }

                PrintMenu();

                fileName = Console.ReadLine().Trim();
            }
        }
Esempio n. 3
0
 private bool RunTestDirectory(TestInfo info, XmlTestController controller)
 {
     if (info != null && info.Directory != null)
     {
         try
         {
             string   currentDir = Environment.CurrentDirectory;
             string[] files      = Directory.GetFiles(info.Directory, "*.xml");
             foreach (string file in files)
             {
                 info.FileName = file;
                 RunTestFile(info, controller);
             }
             return(true);
         }
         catch (Exception ex)
         {
             XmlTestExceptionManager.Publish(ex);
         }
         return(true);
     }
     return(false);
 }
Esempio n. 4
0
        private bool RunTestFile(TestInfo info, XmlTestController controller)
        {
            if (info != null)
            {
                XmlTestCollection listTests = null;
                try
                {
                    listTests = controller.Load(info.FileName);
                }
                catch (Exception ex)
                {
                    XmlTestExceptionManager.Publish(ex);
                }

                SimpleTestReset(info.Filter, info.Verbose);

                if (listTests != null && listTests.Count > 0)
                {
                    listTests.TestEvent += new XmlTextEventHandler(OnSimpleTest);
                    listTests.TestEvent += new XmlTextEventHandler(OnTest);

                    if (info.Exception)
                    {
                        XmlTestExceptionManager.ErrorEvent +=
                            new XmlTestErrorEventHandler(this.OnErrorEvent);
                    }

                    try
                    {
                        Console.WriteLine("Running...{0}", listTests.Name);

                        var timer = new XmlTestTimer();

                        timer.Start();

                        listTests.RunTests();

                        timer.Stop();

                        PrintSimpleTestResult(listTests.Count);

                        Console.WriteLine("Duration in milliseconds: {0}", timer.Duration * 1000);

                        elapsedTime += (timer.Duration * 1000);

                        m_nTotalCount += listTests.Count;

                        listTests.TestEvent -= new XmlTextEventHandler(OnSimpleTest);
                        listTests.TestEvent -= new XmlTextEventHandler(OnTest);

                        if (info.Exception)
                        {
                            XmlTestExceptionManager.ErrorEvent -=
                                new XmlTestErrorEventHandler(this.OnErrorEvent);
                        }
                    }
                    catch (Exception ex)
                    {
                        XmlTestExceptionManager.Publish(ex);
                    }
                }

                return(true);
            }

            return(false);
        }
Esempio n. 5
0
        public TestInfoCollection ParseProject(string projectFile)
        {
            if (!File.Exists(projectFile))
            {
                throw new ArgumentException(projectFile,
                                            "The file does not exits or the 'projectFile' is not valid.");
            }

            try
            {
                TestInfoCollection collection = new TestInfoCollection();

                XmlDocument xmldoc = new XmlDocument();

                xmldoc.Load(projectFile);

                XmlElement root = xmldoc.DocumentElement;

                // Now, handle the "case" nodes
                XmlNodeList elemList = xmldoc.GetElementsByTagName("test");
                for (int i = 0; i < elemList.Count; i++)
                {
                    XmlNode element = elemList[i];
                    if (element != null)
                    {
                        XmlTestType filterType        = XmlTestType.None;
                        bool        bDisplayException = true;
                        bool        bVerbose          = true;
                        bool        bInteractive      = false;

                        XmlAttributeCollection attributes = element.Attributes;
                        if (attributes != null && attributes.Count > 0)
                        {
                            XmlAttribute attFilter = attributes["filter"];
                            if (attFilter != null)
                            {
                                filterType = ParseXmlTestType(attFilter.InnerText);
                            }

                            XmlAttribute attException = attributes["exception"];
                            if (attException != null)
                            {
                                bDisplayException = Boolean.Parse(attException.InnerText);
                            }

                            XmlAttribute attVerbose = attributes["verbose"];
                            if (attVerbose != null)
                            {
                                bVerbose = Boolean.Parse(attVerbose.InnerText);
                            }

                            XmlAttribute attInteractive = attributes["interactive"];
                            if (attInteractive != null)
                            {
                                bInteractive = Boolean.Parse(attInteractive.InnerText);
                            }
                        }

                        XmlNodeList elemFiles = element.SelectNodes("files/file");
                        if (elemFiles != null)
                        {
                            for (int j = 0; j < elemFiles.Count; j++)
                            {
                                XmlNode xmlFile = elemFiles[j];
                                if (xmlFile != null)
                                {
                                    TestInfo info = new TestInfo(filterType);
                                    info.FileName    = xmlFile.InnerText;
                                    info.Verbose     = bVerbose;
                                    info.Exception   = bDisplayException;
                                    info.Interactive = bInteractive;

                                    collection.Add(info);
                                }
                            }
                        }

                        XmlNodeList elemDirs = element.SelectNodes("dirs/dir");
                        if (elemDirs != null)
                        {
                            for (int k = 0; k < elemDirs.Count; k++)
                            {
                                XmlNode xmlDir = elemDirs[k];
                                if (xmlDir != null)
                                {
                                    TestInfo info = new TestInfo(filterType);
                                    info.Directory   = xmlDir.InnerText;
                                    info.Verbose     = bVerbose;
                                    info.Exception   = bDisplayException;
                                    info.Interactive = bInteractive;

                                    collection.Add(info);
                                }
                            }
                        }
                    }
                }

                return(collection);
            }
            catch (Exception ex)
            {
                XmlTestExceptionManager.Publish(ex);

                return(null);
            }
        }
Esempio n. 6
0
        static void RunInteractive(XmlTestType filter, bool verbose)
        {
            string fileName = string.Empty;

            var controller = new XmlTestController();

            var runner = new TestRunner(filter, verbose);

            PrintMenu();

            fileName = Console.ReadLine().Trim();

            while (fileName != "exit")
            {
                XmlTestCollection listTests = null;
                try
                {
                    switch (fileName)
                    {
                    case "default":
                        RunDefault();
                        break;

                    case "other":
                        RunOther();
                        break;

                    case "all":
                        RunDefault();
                        RunOther();
                        break;

                    default:
                        if (Directory.Exists(fileName))
                        {
                            string tmp = Path.GetTempFileName();
                            File.AppendAllText(tmp,
                                               string.Format(
                                                   "<?xml version=\"1.0\" encoding=\"utf-8\" ?><project><test verbose=\"false\" exception=\"true\" interactive=\"false\" filter=\"none\"><dirs><dir>{0}</dir></dirs></test></project>",
                                                   fileName));
                            listTests = controller.Load(tmp);
                        }
                        else
                        {
                            listTests = controller.Load(fileName);
                        }

                        break;
                    }
                }
                catch (Exception ex)
                {
                    XmlTestExceptionManager.Publish(ex);
                }

                if (listTests != null && listTests.Count > 0)
                {
                    listTests.TestEvent += new XmlTextEventHandler(runner.OnSimpleTest);

                    try
                    {
                        Console.WriteLine("Running...{0}", listTests.Name);

                        listTests.RunTests();

                        runner.PrintSimpleTestResult(listTests.Count);

                        runner.SimpleTestReset(XmlTestType.None, verbose);
                    }
                    catch (Exception ex)
                    {
                        XmlTestExceptionManager.Publish(ex);
                    }
                }

                PrintMenu();

                fileName = Console.ReadLine().Trim();
            }
        }