Beispiel #1
0
 public static TestList LoadFromFile(string filePath)
 {
     using (var stream = new FileStream(filePath, FileMode.Open))
     {
         TestList tl = LoadFromFile(stream, Path.GetDirectoryName(filePath));
         tl.ImportedFile = new ImportFile(filePath);
         return(tl);
     }
 }
Beispiel #2
0
        static TestList()
        {
            Type[]        types       = System.Reflection.Assembly.GetExecutingAssembly().GetTypes();
            XmlAttributes listAttribs = new XmlAttributes();

            foreach (var type in types)
            {
                if (type.IsSubclassOf(typeof(Element)))
                {
                    listAttribs.XmlElements.Add(new XmlElementAttribute(type.Name, type));

                    Activator.CreateInstance(type);
                }
            }

            m_aor.Add(typeof(TestList), "Children", listAttribs);

            m_Global = new TestList();
        }
Beispiel #3
0
        public override object Clone()
        {
            TestList clone = (TestList)base.Clone();

            clone.Parent              = this;
            clone.m_children          = new List <Element>();
            clone.m_properties        = new Dictionary <string, object>();
            clone.m_bRoot             = false;
            clone.m_traces            = null;
            clone.ExternalRunFile     = null;
            clone.ExternalTracesFile  = null;
            clone.TreeNode.ImageIndex = clone.TreeNode.SelectedImageIndex = clone.m_bRunInParallel ? 4 : 5;

            foreach (var child in m_children)
            {
                clone.Add((Element)child.Clone());
            }

            return(clone);
        }
Beispiel #4
0
        private void LoadImportedFiles(string path)
        {
            for (int i = 0; i < Children.Count; i++)
            {
                Element    el  = Children[i];
                ImportFile imf = el as ImportFile;

                if (imf != null)
                {
                    TestList tl = TestList.LoadFromFile(Path.Combine(path, imf.FilePath));
                    tl.ImportedFile = imf;
                    tl.Parent       = this;
                    Children[i]     = tl;
                }

                TestList il = el as TestList;
                if (il != null)
                {
                    il.LoadImportedFiles(path);
                }
            }
        }
Beispiel #5
0
        private void LoadExternalResults()
        {
            if (RunResult != null && RunResult is TestListTestResult && SaveAfterEachRun)
            {
                if (!string.IsNullOrEmpty(ExternalRunFile))
                {
                    TestList tl = TestList.LoadFromFile(ExternalRunFile);

                    foreach (Element el in tl.Children)
                    {
                        ((TestListTestResult)RunResult).TestLists.Add((TestList)el);
                    }
                }

                /*if( !string.IsNullOrEmpty( ExternalTracesFile ) )
                 * {
                 *      TestList tl = TestList.LoadFromFile( ExternalTracesFile );
                 *
                 *      Traces.AddRange( tl.Traces );
                 * }*/
            }
        }
Beispiel #6
0
        internal override void Run()
        {
            try
            {
                if (RunResult != null)
                {
                    throw new ApplicationException("Clear the results before running again");
                }

                if (CheckBoxes && !TreeNode.Checked)
                {
                    return;
                }

                bool bMultipleRuns = false;
                int  repeatCount   = int.MaxValue;

                if (RepeatCount != null)
                {
                    int tmp;
                    if (int.TryParse(RepeatCount, out tmp))
                    {
                        repeatCount   = tmp;
                        bMultipleRuns = true;
                    }
                }

                double repeatDuration = double.MaxValue;

                if (RepeatDuration != null)
                {
                    double tmp;
                    if (double.TryParse(RepeatDuration, out tmp))
                    {
                        repeatDuration = tmp;
                        bMultipleRuns  = true;
                    }
                }

                TestResult result    = null;
                DateTime   startTime = DateTime.Now;

                if (bMultipleRuns)
                {
                    int             runCounter = 0;
                    int             errors = 0, warnings = 0;
                    List <TestList> innerLists = new List <TestList>();
                    DateTime        maxTime    = repeatDuration == double.MaxValue ? DateTime.MaxValue : startTime.AddSeconds(repeatDuration);

                    XmlWriter externalRunFileWriter = null;

                    if (SaveAfterEachRun)
                    {
                        string timestamp = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss", System.Globalization.DateTimeFormatInfo.InvariantInfo);
                        ExternalRunFile    = timestamp + "Results.xml";
                        ExternalTracesFile = timestamp + "Traces.xml";

                        externalRunFileWriter = XmlWriter.Create(ExternalRunFile);
                        externalRunFileWriter.WriteStartElement("TestList", "http://softing-ia.com/TestClient.xsd");

                        m_externalTracesFileWriter = XmlWriter.Create(ExternalTracesFile);
                        m_externalTracesFileWriter.WriteStartElement("TestList", "http://softing-ia.com/TestClient.xsd");
                        m_externalTracesFileWriter.WriteStartElement("Traces");
                    }

                    //set a temporary result to be able to refresh the view of partial results
                    RunResult           = new TestListTestResult(TestResults.Executing);
                    RunResult.StartTime = startTime;
                    ((TestListTestResult)RunResult).TestLists = innerLists;

                    while (runCounter < repeatCount && DateTime.Now <= maxTime && !IsCancelationPending())
                    {
                        TestResult runResult;

                        TestList clone = (TestList)Clone();

                        if (!SaveAfterEachRun)
                        {
                            lock ( innerLists )
                            {
                                innerLists.Add(clone);
                            }
                            ReportFinished();
                        }

                        runResult       = clone.RunOnce();
                        clone.RunResult = runResult;

                        if (SaveAfterEachRun)
                        {
                            lock ( m_serializer )
                            {
                                Element.Serializing = true;
                                m_serializer.Serialize(externalRunFileWriter, clone);
                                Element.Serializing = false;
                            }
                        }

                        switch (runResult.Type)
                        {
                        case TestResults.Failed: errors++;
                            break;

                        case TestResults.Warning: warnings++;
                            break;
                        }

                        runCounter++;
                    }

                    if (SaveAfterEachRun)
                    {
                        externalRunFileWriter.WriteEndElement();
                        externalRunFileWriter.Close();

                        m_externalTracesFileWriter.WriteEndElement();
                        m_externalTracesFileWriter.WriteEndElement();
                        m_externalTracesFileWriter.Close();
                    }

                    TestListTestResult listResult = (TestListTestResult)RunResult;

                    if (errors > 0)
                    {
                        listResult.Type = TestResults.Failed;
                    }
                    else if (warnings > 0)
                    {
                        listResult.Type = TestResults.Warning;
                    }
                    else
                    {
                        listResult.Type = TestResults.Success;
                    }

                    listResult.EndTime   = DateTime.Now;
                    listResult.StartTime = startTime;
                    result = listResult;
                }
                else
                {
                    SaveAfterEachRun    = false;
                    RunResult           = new TestResult(TestResults.Executing);
                    RunResult.StartTime = startTime;
                    ReportFinished();

                    result = RunOnce();
                }

                RunResult = result;
                ReportFinished();
            }
            finally
            {
                WaitHandle.Set();
            }
        }