Exemple #1
0
 public override TCObject Execute(TCObject objectToExecuteOn, TCAddOnTaskContext taskContext)
 {
     ExecutionEntry ee = objectToExecuteOn as ExecutionEntry;
     int bugid = 0;
     Int32.TryParse(ee.ActualLog.ChangeRequestId, out bugid);
     if (bugid > 0)
     {
         TFSConnector tfsc = new TFSConnector();
         Process.Start(tfsc.GetWorkItemUrl(bugid).ToString());
     }
     return null;
 }
        public override TCObject Execute(TCObject objectToExecuteOn, TCAddOnTaskContext taskContext)
        {
            DefectResult dr = new DefectResult();
            List<String> uidList = new List<String>();
            List<String> files = new List<String>();
            IEnumerable<DirectoryInfo> directories;

            ExecutionEntry ee = objectToExecuteOn as ExecutionEntry;

            // get images from failed tests

            var dirinfo = new DirectoryInfo(DefectTrackerSettings.Default.ToscaScreenshotFolder);
            if (dirinfo.Exists)
            {
                directories = dirinfo.GetDirectories().Where(d => d.LastWriteTime > DateTime.Now.AddDays(-1));
            }
            else
            {
                directories = null;
            }

            foreach (var ts in ee.TestCase.Items)
            {
                if (ts is TestStep)
                {
                    TestStep ts2 = ts as TestStep;
                    foreach (TestStepValue tsv in ts2.TestStepValues)
                    {
                        if (directories != null)
                        {
                            var result = directories.Where(b => b.Name == "surrogate " + tsv.UniqueId.ToString() && b.CreationTime > DateTime.Now.AddDays(-1)).Select(a => (tsv.UniqueId.ToString()));
                            foreach (string r in result)
                            {
                                uidList.Add("surrogate " + tsv.UniqueId.ToString());
                            }
                        }
                    }
                }
            }

            foreach (string dir in uidList)
            {
                files = Directory.GetFiles(DefectTrackerSettings.Default.ToscaScreenshotFolder + @"\" + dir).ToList();
            }

            SetTFSProject(ee);
            Defect defect;
            if (files.Count != 0)
            {
                defect = SetDefect(ee, files);
            }
            else
            {
                defect = SetDefect(ee);
            }

            TFSConnector tfs = new TFSConnector();
            dr = tfs.CreateBug(defect);
            if (dr.id != 0)
            {
                ee.ActualLog.ChangeRequestId = dr.id.ToString();
                ee.ActualLog.ChangeRequestState = dr.status;
                // open browser to view work item/defect in TFS
                Process.Start(tfs.GetWorkItemUrl(dr.id).ToString());
            }
            tfs.DisposeTFS();

            return null;
        }