public VstsTestCaseResult CsvToVsts(CsvResultItem csvRawData, string additionalComment = null)
        {
            if (null == csvRawData)
            {
                throw new ArgumentNullException("Raw data is null!");
            }

            var res = new VstsTestCaseResult();

            //res.Id = csvRawData.Id.Replace("VSTS", string.Empty);
            res.Id = Regex.Replace(csvRawData.Id, @"^VSTS", string.Empty, RegexOptions.Compiled | RegexOptions.IgnoreCase);

            if (csvRawData.Result.ToUpper() == "PASS")
            {
                res.Outcome = "passed";
            }
            else if (csvRawData.Result == "TBD")
            {
                var defects = GetKnownDefects(csvRawData.Description);
                if (defects == null)
                {
                    throw new Exception($"Test {csvRawData.Id} fail without defect linked!");
                }
                //if (defects == null) return default(VstsTestCaseResult);
                if (defects.Count != 0)
                {
                    if (FailTagRegex.IsMatch(csvRawData.Description))
                    {
                        res.Outcome = "failed";
                    }
                    else if (PassTagRegex.IsMatch(csvRawData.Description))
                    {
                        res.Outcome = "passed";
                    }
                    //else return default(VstsTestCaseResult);
                    else
                    {
                        throw new Exception($"Test {csvRawData.Id} outcome is not following specification!");
                    }
                    res.AssociatedBugs = new List <string>();
                    res.AssociatedBugs.AddRange(defects);
                }
            }
            else
            {
                //return default(VstsTestCaseResult);
                throw new Exception($"Test {csvRawData.Id} outcome is not following specification!");
            }

            res.Description = csvRawData.Description;

            res.Comment = Regex.Match(csvRawData.Note, @"(?<media>Media\d+)\.iso", RegexOptions.IgnoreCase | RegexOptions.Compiled).Groups["media"].Value;
            if (!string.IsNullOrWhiteSpace(additionalComment))
            {
                res.Comment = additionalComment + "," + res.Comment;
            }

            return(res);
        }
Esempio n. 2
0
 public bool Equals(VstsTestCaseResult result)
 {
     return(result != null &&
            Id == result.Id &&
            Description == result.Description &&
            Outcome == result.Outcome &&
            Comment == result.Comment &&
            EqualityComparer <List <string> > .Default.Equals(AssociatedBugs, result.AssociatedBugs));
 }