public bool Equals(BranchInfo other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(Equals(other.Document, Document) && other.Line == Line && other.Column == Column && other.EndColumn == EndColumn && Equals(other.Method, Method) && other.ILOffset == ILOffset); }
public void DumpAssemblyCoverage(IPexComponent host) { StringBuilder sb = new StringBuilder(); foreach (var item in UnCoveredBranchCodeLocations) { CodeLocation codeLocation = item.Location; ISymbolManager sm = host.Services.SymbolManager; SequencePoint sp; MethodDefinitionBodyInstrumentationInfo info; if (sm.TryGetSequencePoint(codeLocation.Method, codeLocation.Offset, out sp) && codeLocation.Method.TryGetBodyInstrumentationInfo(out info)) { sb.AppendLine(codeLocation.Method.FullName + "," + sp.Document + "," + sp.Line + "," + sp.Column + " outgoingbranch label: " + item.OutgointBranchLabel + " offset: " + codeLocation.Offset.ToString("x")); var branchInfo = new BranchInfo(sp.Document, sp.Line, sp.Column, sp.EndColumn, codeLocation.Method.FullName, codeLocation.Offset); _nonCoveredBranchInfo.Branches.Add(branchInfo); } } DumpInfoToDebugFile(sb.ToString(), assemblyCovFileName + TXT); DumpInfoToFile(_nonCoveredBranchInfo, assemblyCovFileName); StringBuilder sb2 = new StringBuilder("instruction cov: \n"); foreach (var cov in InstructionCov) { sb2.AppendLine("method: " + cov.Key); foreach (var pair in cov.Value) { sb2.AppendLine("offset: " + pair.Key.ToString("x") + " covered: " + pair.Value); } } DumpInfoToDebugFile(sb2.ToString(), instructionCovFileName + TXT); DumpInfoToFile(InstructionCov, instructionCovFileName); StringBuilder sb3 = new StringBuilder("basicblockOffsets cov: \n"); foreach (var offset in BasicBlocksOffsets) { sb3.AppendLine("method: " + offset.Key); foreach (var pair in offset.Value) { sb3.AppendLine("offset: " + pair.ToString("x")); } } DumpInfoToDebugFile(sb3.ToString(), basicBlockOffsetFileName + TXT); }
private void ConvertInfoFromFieldsForUnsuccessfullyFlippedCodeLocationsToInsufficientObjectFactoryFieldInfo() { InsufficientObjectFactoryFieldInfoObj.ReleventFields.Clear(); InsufficientObjectFactoryFieldInfoObj.CodeLocationToRelevantFields.Clear(); SafeStringBuilder sb = new SafeStringBuilder(); foreach (var cl in FieldsForUnsuccessfullyFlippedCodeLocations.Keys) { HashSet <string> fs = new HashSet <string>(); HashSet <string> fs2 = new HashSet <string>(); SafeSet <Field> fields; SequencePoint sequencePoint; Services.SymbolManager.TryGetSequencePoint(cl.Method, cl.Offset, out sequencePoint); fs.Add("column: " + sequencePoint.Column); fs.Add("end column: " + sequencePoint.EndColumn); fs.Add("sp2: " + sequencePoint.Document + " line: " + sequencePoint.Line); fs.Add("offset: " + sequencePoint.Offset); fs.Add("cl offset: " + cl.Offset); var branchInfo = new BranchInfo(sequencePoint.Document, sequencePoint.Line, sequencePoint.Column, sequencePoint.EndColumn, cl.Method.FullName, cl.Offset); if (FieldsForUnsuccessfullyFlippedCodeLocations.TryGetValue(cl, out fields)) { foreach (var f in fields) { InsufficientObjectFactoryFieldInfoObj.ReleventFields.Add(f.FullName); insufficientFieldInfoWithBranchInfo.ReleventFields.Add(f.FullName); fs.Add(f.FullName); fs2.Add(f.FullName); } } if (InsufficientObjectFactoryFieldInfoObj.CodeLocationToRelevantFields.ContainsKey(cl.ToString())) { InsufficientObjectFactoryFieldInfoObj.CodeLocationToRelevantFields.Remove(cl.ToString()); } if (insufficientFieldInfoWithBranchInfo.CodeLocationToRelevantFields.ContainsKey(branchInfo)) { insufficientFieldInfoWithBranchInfo.CodeLocationToRelevantFields.Remove(branchInfo); } InsufficientObjectFactoryFieldInfoObj.CodeLocationToRelevantFields.Add(cl.ToString(), fs); insufficientFieldInfoWithBranchInfo.CodeLocationToRelevantFields.Add(branchInfo, fs2); } }
private void DumpResultTrackingInfo() { // DumpInfoToDebugFile(sb.ToString(), resultTrackingFileName+TXT); foreach (var keyValue in ExternalMethodInBranch) { var method = keyValue.Key; var locations = keyValue.Value; ISymbolManager sm = Services.SymbolManager; SequencePoint sp; MethodDefinitionBodyInstrumentationInfo info; foreach (var location in locations) { if (sm.TryGetSequencePoint(location.Method, location.Offset, out sp) && location.Method.TryGetBodyInstrumentationInfo(out info)) { // sb.AppendLine(codeLocation.Method.FullName + "," + // sp.Document + "," + // sp.Line + "," + sp.Column // + " outgoingbranch label: " + item.Value); var branchInfo = new BranchInfo(sp.Document, sp.Line, sp.Column, sp.EndColumn, location.Method.FullName, location.Offset); if (!resultTrackingInfo.UnIntrumentedMethodInBranch.ContainsKey(method.FullName)) { resultTrackingInfo.UnIntrumentedMethodInBranch.Add(method.FullName, new HashSet <BranchInfo>()); } resultTrackingInfo.UnIntrumentedMethodInBranch[method.FullName].Add(branchInfo); } } } var sb = new StringBuilder("result track: "); foreach (var branch in resultTrackingInfo.UnIntrumentedMethodInBranch) { sb.AppendLine("branch: " + branch.Key + " method: " + branch.Value); } DumpInfoToDebugFile(sb.ToString(), resultTrackingFileName + TXT); DumpInfoToFile(resultTrackingInfo, resultTrackingFileName); }
private void DumpIssuesIntoXml() { foreach (var candidateObjectCreationIssue in _candidateObjectCreationProblems) { var branchInfo = candidateObjectCreationIssue.BranchLocation; if (_nonCoveredBranchInfo.BranchLocations.Contains(branchInfo.ToLocation)) { var issue = new Problem(ProblemKind.ObjectCreation, candidateObjectCreationIssue.TargetType, candidateObjectCreationIssue.ToString()); if (!ProblemWithBranches.ContainsKey(issue)) { ProblemWithBranches.Add(issue, new HashSet <BranchInfo>()); } ProblemWithBranches[issue].Add(branchInfo); } if (candidateObjectCreationIssue.BranchLocation.Line == -1) { if (candidateObjectCreationIssue.TargetObjectType != null) { var issue = new Problem(ProblemKind.ObjectCreation, candidateObjectCreationIssue.TargetType, candidateObjectCreationIssue.ToString()); if (!ProblemWithBranches.ContainsKey(issue)) { ProblemWithBranches.Add(issue, new HashSet <BranchInfo>()); } ProblemWithBranches[issue].Add(branchInfo); } } } foreach (KeyValuePair <string, HashSet <BranchInfo> > pair in resultTrackingInfo.UnIntrumentedMethodInBranch) { var methodName = pair.Key; var infos = pair.Value; foreach (var info in infos) { if (_nonCoveredBranchInfo.Branches.Contains(info)) { var issue = new Problem(ProblemKind.UnInstrumentedMethod, methodName, "UninstrumentedMethod found in branch: " + methodName); if (!ProblemWithBranches.ContainsKey(issue)) { ProblemWithBranches.Add(issue, new HashSet <BranchInfo>()); } ProblemWithBranches[issue].Add(info); } } } foreach (var methodsFoundInObj in uninstrumentedMethodsFoundInObj) { var branchInfo = methodsFoundInObj.Value; string methodName = methodsFoundInObj.Key; var issue = new Problem(ProblemKind.UnInstrumentedMethod, methodName, "UninstrumentedMethod found in objec creation: " + methodName); if (!ProblemWithBranches.ContainsKey(issue)) { ProblemWithBranches.Add(issue, new HashSet <BranchInfo>()); } foreach (var info in branchInfo) { ProblemWithBranches[issue].Add(info); } } foreach (var exceptionExternalMethod in ExceptionExternalMethods) { int line = 0; try { line = Convert.ToInt32(exceptionExternalMethod.Line); } catch (Exception) { } var branchInfo = new BranchInfo("", line, 0, 0, exceptionExternalMethod.CallerMethod, 0); string methodName = exceptionExternalMethod.MethodName; var issue = new Problem(ProblemKind.UnInstrumentedMethod, methodName, "uninstrumented method found in exception:\n" + exceptionExternalMethod.ExceptionString); if (!ProblemWithBranches.ContainsKey(issue)) { ProblemWithBranches.Add(issue, new HashSet <BranchInfo>()); } ProblemWithBranches[issue].Add(branchInfo); } foreach (BoundaryProblem boundaryIssue in BoundaryIssues) { var issue = new Problem(ProblemKind.Boundary, boundaryIssue.FlippedLocation.Method, "boundary issue:\n" + boundaryIssue); if (!ProblemWithBranches.ContainsKey(issue)) { ProblemWithBranches.Add(issue, new HashSet <BranchInfo>()); } ProblemWithBranches[issue].Add(boundaryIssue.FlippedLocation); } try { if (! Directory.Exists(xmlFileDirectory)) { Directory.CreateDirectory(xmlFileDirectory); } } catch (Exception e) { ErrorLog.AppendLine("DumpXml problem info to " + xmlFileDirectory + " : " + e.ToString()); } FileStream stream = new FileStream(issueWithBranchesFileName + ".xml", FileMode.Create); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?><issues />"); XmlNode root = xmlDoc.DocumentElement; var settings = new XmlWriterSettings(); settings.Encoding = Encoding.UTF8; XmlWriter writer = XmlWriter.Create(stream, settings); // XmlElement root = xmlDoc.CreateElement("BranchCoverage"); // docElement.AppendChild(root); XmlWriter writerInReportPath = XmlWriter.Create(new FileStream(ReportPath + "\\" + assemblyName + ".problems.xml", FileMode.Create), settings); branchWithIssues = new Dictionary <string, Dictionary <BranchInfo, HashSet <Problem> > >(); foreach (var pair in ProblemWithBranches) { Problem issue = pair.Key; HashSet <BranchInfo> infos = pair.Value; foreach (BranchInfo branchInfo in infos) { string document = branchInfo.Document ?? "null"; if (!branchWithIssues.ContainsKey(document)) { branchWithIssues.Add(document, new Dictionary <BranchInfo, HashSet <Problem> >()); } if (!branchWithIssues[document].ContainsKey(branchInfo)) { branchWithIssues[document].Add(branchInfo, new HashSet <Problem>()); } branchWithIssues[document][branchInfo].Add(issue); } } foreach (var pair in ProblemWithBranches) { Problem issue = pair.Key; HashSet <BranchInfo> infos = pair.Value; XmlElement issueElement = xmlDoc.CreateElement("issue"); issueElement.SetAttribute("kind", issue.Kind.ToString()); issueElement.SetAttribute("type", issue.Type); issueElement.SetAttribute("description", issue.Description); foreach (var branchInfo in infos) { XmlElement methodElement = xmlDoc.CreateElement("branch"); // TypeDefinition type; // if (valuePair.Key.TryGetDeclaringType(out type)) // { // // } XmlElement branchElement = xmlDoc.CreateElement("branch"); // branchElement.SetAttribute("filename", coverageDetail.BranchInfo.Document); branchElement.SetAttribute("src", branchInfo.Document ?? "null"); branchElement.SetAttribute("line", branchInfo.Line.ToString()); branchElement.SetAttribute("column", branchInfo.Column.ToString()); branchElement.SetAttribute("endColumn", branchInfo.EndColumn.ToString()); branchElement.SetAttribute("offset", branchInfo.ILOffset.ToString()); issueElement.AppendChild(branchElement); } root.AppendChild(issueElement); } xmlDoc.Save(writer); xmlDoc.Save(writerInReportPath); writer.Close(); writerInReportPath.Close(); // DumpXml(BranchCoverageDetails, coverageDetailsFileName + ".xml"); }
private void AssignBranchesToProblems() { // foreach (var codeLocationToRelevantField in insufficientFieldInfoWithBranchInfo.CodeLocationToRelevantFields // ) // { // var BranchInfo = codeLocationToRelevantField.Key; // if (_nonCoveredBranchInfo.Branches.Contains(BranchInfo)) // { // foreach (var field in codeLocationToRelevantField.Value) // { //// var types = _issueInfo.ObjectCreationIssues[PexExplorableEventKind.GuessedClass]; //// foreach (var type in types) //// { //// if (field.Contains(type)) //// { // IssueWithBranches[BranchInfo].Add(new Issue(IssueKind.ObjectCreation, // "object creation issue:" + // field)); //// } //// } // } // } // } ProblemWithBranches.Clear(); foreach (var candidateObjectCreationProblem in _candidateObjectCreationProblems) { var branchInfo = candidateObjectCreationProblem.BranchLocation; if (_nonCoveredBranchInfo.BranchLocations.Contains(branchInfo.ToLocation)) { var problem = new Problem(ProblemKind.ObjectCreationProblem, candidateObjectCreationProblem.TargetType, candidateObjectCreationProblem.ToString()); if (!ProblemWithBranches.ContainsKey(problem)) { ProblemWithBranches.Add(problem, new HashSet<BranchInfo>()); } ProblemWithBranches[problem].Add(branchInfo); } if (candidateObjectCreationProblem.BranchLocation.Line == -1) { if (candidateObjectCreationProblem.TargetObjectType != null) { var problem = new Problem(ProblemKind.ObjectCreationProblem, candidateObjectCreationProblem.TargetType, candidateObjectCreationProblem.ToString()); if (!ProblemWithBranches.ContainsKey(problem)) { ProblemWithBranches.Add(problem, new HashSet<BranchInfo>()); } ProblemWithBranches[problem].Add(branchInfo); } } } foreach (KeyValuePair<Problem, HashSet<BranchInfo>> pair in ProblemWithBranches) { List<BranchInfo> needToRemoves = new List<BranchInfo>(); if (pair.Value.Count > 1) { foreach (BranchInfo info in pair.Value) { if (info.Line == -1) { needToRemoves.Add(info); } } } foreach (BranchInfo info in needToRemoves) { pair.Value.Remove(info); } } foreach (KeyValuePair<string, HashSet<BranchInfo>> pair in resultTrackingInfo.UnIntrumentedMethodInBranch) { var methodName = pair.Key; var infos = pair.Value; foreach (var info in infos) { if (_nonCoveredBranchInfo.Branches.Contains(info)) { var problem = new Problem(ProblemKind.ExternalMethodProblem, methodName, "External method found in branch: " + methodName); if (!ProblemWithBranches.ContainsKey(problem)) { ProblemWithBranches.Add(problem, new HashSet<BranchInfo>()); } ProblemWithBranches[problem].Add(info); } } } foreach (var methodsFoundInObj in uninstrumentedMethodsFoundInObj) { var branchInfo = methodsFoundInObj.Value; string methodName = methodsFoundInObj.Key; var problem = new Problem(ProblemKind.ExternalMethodProblem, methodName, "External method found in objec creation: " + methodName); if (!ProblemWithBranches.ContainsKey(problem)) { ProblemWithBranches.Add(problem, new HashSet<BranchInfo>()); } foreach (var info in branchInfo) { ProblemWithBranches[problem].Add(info); } } foreach (var exceptionExternalMethod in ExceptionExternalMethods) { int line = 0; try { line = Convert.ToInt32(exceptionExternalMethod.Line); } catch (Exception) { } var branchInfo = new BranchInfo("", line, 0, 0, exceptionExternalMethod.CallerMethod, 0); string methodName = exceptionExternalMethod.MethodName; if (methodName.Contains("Pex") || methodName.Contains("GetObjectData")) { return; } var problem = new Problem(ProblemKind.ExternalMethodProblem, methodName, "External method found in exception:\n" + exceptionExternalMethod.ExceptionString); if (!ProblemWithBranches.ContainsKey(problem)) { ProblemWithBranches.Add(problem, new HashSet<BranchInfo>()); } ProblemWithBranches[problem].Add(branchInfo); } }
private void ConvertInfoFromFieldsForUnsuccessfullyFlippedCodeLocationsToInsufficientObjectFactoryFieldInfo() { InsufficientObjectFactoryFieldInfoObj.ReleventFields.Clear(); InsufficientObjectFactoryFieldInfoObj.CodeLocationToRelevantFields.Clear(); SafeStringBuilder sb = new SafeStringBuilder(); foreach (var cl in FieldsForUnsuccessfullyFlippedCodeLocations.Keys) { HashSet<string> fs = new HashSet<string>(); HashSet<string> fs2 = new HashSet<string>(); SafeSet<Field> fields; SequencePoint sequencePoint; Services.SymbolManager.TryGetSequencePoint(cl.Method, cl.Offset, out sequencePoint); fs.Add("column: " + sequencePoint.Column); fs.Add("end column: " + sequencePoint.EndColumn); fs.Add("sp2: " + sequencePoint.Document + " line: " + sequencePoint.Line); fs.Add("offset: " + sequencePoint.Offset); fs.Add("cl offset: " + cl.Offset); var branchInfo = new BranchInfo(sequencePoint.Document, sequencePoint.Line, sequencePoint.Column, sequencePoint.EndColumn, cl.Method.FullName, cl.Offset); if (FieldsForUnsuccessfullyFlippedCodeLocations.TryGetValue(cl, out fields)) { foreach (var f in fields) { InsufficientObjectFactoryFieldInfoObj.ReleventFields.Add(f.FullName); insufficientFieldInfoWithBranchInfo.ReleventFields.Add(f.FullName); fs.Add(f.FullName); fs2.Add(f.FullName); } } if (InsufficientObjectFactoryFieldInfoObj.CodeLocationToRelevantFields.ContainsKey(cl.ToString())) { InsufficientObjectFactoryFieldInfoObj.CodeLocationToRelevantFields.Remove(cl.ToString()); } if (insufficientFieldInfoWithBranchInfo.CodeLocationToRelevantFields.ContainsKey(branchInfo)) { insufficientFieldInfoWithBranchInfo.CodeLocationToRelevantFields.Remove(branchInfo); } InsufficientObjectFactoryFieldInfoObj.CodeLocationToRelevantFields.Add(cl.ToString(), fs); insufficientFieldInfoWithBranchInfo.CodeLocationToRelevantFields.Add(branchInfo, fs2); } }
public bool Equals(BranchInfo other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return Equals(other.Document, Document) && other.Line == Line && other.Column == Column && other.EndColumn == EndColumn && Equals(other.Method, Method) && other.ILOffset == ILOffset; }
private void DumpResultTrackingInfo() { // DumpInfoToDebugFile(sb.ToString(), resultTrackingFileName+TXT); foreach (var keyValue in ExternalMethodInBranch) { var method = keyValue.Key; var locations = keyValue.Value; ISymbolManager sm = Services.SymbolManager; SequencePoint sp; MethodDefinitionBodyInstrumentationInfo info; foreach (var location in locations) { if (sm.TryGetSequencePoint(location.Method, location.Offset, out sp) && location.Method.TryGetBodyInstrumentationInfo(out info)) { // sb.AppendLine(codeLocation.Method.FullName + "," + // sp.Document + "," + // sp.Line + "," + sp.Column // + " outgoingbranch label: " + item.Value); var branchInfo = new BranchInfo(sp.Document, sp.Line, sp.Column, sp.EndColumn, location.Method.FullName, location.Offset); if (!resultTrackingInfo.UnIntrumentedMethodInBranch.ContainsKey(method.FullName)) { resultTrackingInfo.UnIntrumentedMethodInBranch.Add(method.FullName, new HashSet<BranchInfo>()); } resultTrackingInfo.UnIntrumentedMethodInBranch[method.FullName].Add(branchInfo); } } } var sb = new StringBuilder("result track: "); foreach (var branch in resultTrackingInfo.UnIntrumentedMethodInBranch) { sb.AppendLine("branch: " + branch.Key + " method: " + branch.Value); } DumpInfoToDebugFile(sb.ToString(), resultTrackingFileName + TXT); DumpInfoToFile(resultTrackingInfo, resultTrackingFileName); }
private void DumpIssuesIntoXml() { foreach (var candidateObjectCreationIssue in _candidateObjectCreationProblems) { var branchInfo = candidateObjectCreationIssue.BranchLocation; if (_nonCoveredBranchInfo.BranchLocations.Contains(branchInfo.ToLocation)) { var issue = new Problem(ProblemKind.ObjectCreation, candidateObjectCreationIssue.TargetType, candidateObjectCreationIssue.ToString()); if (!ProblemWithBranches.ContainsKey(issue)) { ProblemWithBranches.Add(issue, new HashSet<BranchInfo>()); } ProblemWithBranches[issue].Add(branchInfo); } if (candidateObjectCreationIssue.BranchLocation.Line == -1) { if (candidateObjectCreationIssue.TargetObjectType != null) { var issue = new Problem(ProblemKind.ObjectCreation, candidateObjectCreationIssue.TargetType, candidateObjectCreationIssue.ToString()); if (!ProblemWithBranches.ContainsKey(issue)) { ProblemWithBranches.Add(issue, new HashSet<BranchInfo>()); } ProblemWithBranches[issue].Add(branchInfo); } } } foreach (KeyValuePair<string, HashSet<BranchInfo>> pair in resultTrackingInfo.UnIntrumentedMethodInBranch) { var methodName = pair.Key; var infos = pair.Value; foreach (var info in infos) { if (_nonCoveredBranchInfo.Branches.Contains(info)) { var issue = new Problem(ProblemKind.UnInstrumentedMethod, methodName, "UninstrumentedMethod found in branch: " + methodName); if (!ProblemWithBranches.ContainsKey(issue)) { ProblemWithBranches.Add(issue, new HashSet<BranchInfo>()); } ProblemWithBranches[issue].Add(info); } } } foreach (var methodsFoundInObj in uninstrumentedMethodsFoundInObj) { var branchInfo = methodsFoundInObj.Value; string methodName = methodsFoundInObj.Key; var issue = new Problem(ProblemKind.UnInstrumentedMethod, methodName, "UninstrumentedMethod found in objec creation: " + methodName); if (!ProblemWithBranches.ContainsKey(issue)) { ProblemWithBranches.Add(issue, new HashSet<BranchInfo>()); } foreach (var info in branchInfo) { ProblemWithBranches[issue].Add(info); } } foreach (var exceptionExternalMethod in ExceptionExternalMethods) { int line = 0; try { line = Convert.ToInt32(exceptionExternalMethod.Line); } catch (Exception) { } var branchInfo = new BranchInfo("", line, 0, 0, exceptionExternalMethod.CallerMethod, 0); string methodName = exceptionExternalMethod.MethodName; var issue = new Problem(ProblemKind.UnInstrumentedMethod, methodName, "uninstrumented method found in exception:\n" + exceptionExternalMethod.ExceptionString); if (!ProblemWithBranches.ContainsKey(issue)) { ProblemWithBranches.Add(issue, new HashSet<BranchInfo>()); } ProblemWithBranches[issue].Add(branchInfo); } foreach (BoundaryProblem boundaryIssue in BoundaryIssues) { var issue = new Problem(ProblemKind.Boundary, boundaryIssue.FlippedLocation.Method, "boundary issue:\n" + boundaryIssue); if (!ProblemWithBranches.ContainsKey(issue)) { ProblemWithBranches.Add(issue, new HashSet<BranchInfo>()); } ProblemWithBranches[issue].Add(boundaryIssue.FlippedLocation); } try { if (! Directory.Exists(xmlFileDirectory)) Directory.CreateDirectory(xmlFileDirectory); } catch (Exception e) { ErrorLog.AppendLine("DumpXml problem info to " + xmlFileDirectory + " : " + e.ToString()); } FileStream stream = new FileStream(issueWithBranchesFileName + ".xml", FileMode.Create); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?><issues />"); XmlNode root = xmlDoc.DocumentElement; var settings = new XmlWriterSettings(); settings.Encoding = Encoding.UTF8; XmlWriter writer = XmlWriter.Create(stream, settings); // XmlElement root = xmlDoc.CreateElement("BranchCoverage"); // docElement.AppendChild(root); XmlWriter writerInReportPath = XmlWriter.Create(new FileStream(ReportPath + "\\" + assemblyName+".problems.xml",FileMode.Create),settings); branchWithIssues = new Dictionary<string, Dictionary<BranchInfo, HashSet<Problem>>>(); foreach (var pair in ProblemWithBranches) { Problem issue = pair.Key; HashSet<BranchInfo> infos = pair.Value; foreach (BranchInfo branchInfo in infos) { string document = branchInfo.Document ?? "null"; if (!branchWithIssues.ContainsKey(document)) { branchWithIssues.Add(document, new Dictionary<BranchInfo, HashSet<Problem>>()); } if (!branchWithIssues[document].ContainsKey(branchInfo)) { branchWithIssues[document].Add(branchInfo, new HashSet<Problem>()); } branchWithIssues[document][branchInfo].Add(issue); } } foreach (var pair in ProblemWithBranches) { Problem issue = pair.Key; HashSet<BranchInfo> infos = pair.Value; XmlElement issueElement = xmlDoc.CreateElement("issue"); issueElement.SetAttribute("kind", issue.Kind.ToString()); issueElement.SetAttribute("type", issue.Type); issueElement.SetAttribute("description", issue.Description); foreach (var branchInfo in infos) { XmlElement methodElement = xmlDoc.CreateElement("branch"); // TypeDefinition type; // if (valuePair.Key.TryGetDeclaringType(out type)) // { // // } XmlElement branchElement = xmlDoc.CreateElement("branch"); // branchElement.SetAttribute("filename", coverageDetail.BranchInfo.Document); branchElement.SetAttribute("src", branchInfo.Document ?? "null"); branchElement.SetAttribute("line", branchInfo.Line.ToString()); branchElement.SetAttribute("column", branchInfo.Column.ToString()); branchElement.SetAttribute("endColumn", branchInfo.EndColumn.ToString()); branchElement.SetAttribute("offset", branchInfo.ILOffset.ToString()); issueElement.AppendChild(branchElement); } root.AppendChild(issueElement); } xmlDoc.Save(writer); xmlDoc.Save(writerInReportPath); writer.Close(); writerInReportPath.Close(); // DumpXml(BranchCoverageDetails, coverageDetailsFileName + ".xml"); }