< Summary

Class:SharpHoundCommonLib.CSVComputerStatus
Assembly:SharpHoundCommonLib
File(s):D:\a\SharpHoundCommon\SharpHoundCommon\src\CommonLib\CSVComputerStatus.cs
Covered lines:3
Uncovered lines:20
Coverable lines:23
Total lines:47
Line coverage:13% (3 of 23)
Covered branches:0
Total branches:14
Branch coverage:0% (0 of 14)

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
ToCsv()100%100%
StringToCsvCell(...)0%1400%

File(s)

D:\a\SharpHoundCommon\SharpHoundCommon\src\CommonLib\CSVComputerStatus.cs

#LineLine coverage
 1using System.Text;
 2using System.Text.RegularExpressions;
 3
 4namespace SharpHoundCommonLib
 5{
 6    public class CSVComputerStatus
 7    {
 8        public const string StatusSuccess = "Success";
 239        public string ComputerName { get; set; }
 2310        public string Task { get; set; }
 2711        public string Status { get; set; }
 12
 13        /// <summary>
 14        ///     Converts to CSV format for output
 15        /// </summary>
 16        /// <returns></returns>
 17        public string ToCsv()
 018        {
 019            return $"{StringToCsvCell(ComputerName)}, {StringToCsvCell(Task)}, {StringToCsvCell(Status)}";
 020        }
 21
 22        /// <summary>
 23        ///     Helper function to escape text before encoding to CSV
 24        /// </summary>
 25        /// <param name="str"></param>
 26        /// <returns></returns>
 27        private static string StringToCsvCell(string str)
 028        {
 029            if (str == null)
 030                return null;
 031            str = Regex.Replace(str, @"\t|\n|\r", "");
 032            var mustQuote = str.Contains(",") || str.Contains("\"") || str.Contains("\r") || str.Contains("\n");
 033            if (!mustQuote) return str;
 034            var sb = new StringBuilder();
 035            sb.Append("\"");
 036            foreach (var nextChar in str)
 037            {
 038                sb.Append(nextChar);
 039                if (nextChar == '"')
 040                    sb.Append("\"");
 041            }
 42
 043            sb.Append("\"");
 044            return sb.ToString();
 045        }
 46    }
 47}