public void FindMethod_SearchNonExistingGenericMethod_PositionIsNull() { PartCoverMethodElement partCoverMethodElement = new PartCoverMethodElement( "AnalyzerTestClass", "GenericMethod", "void (int)"); var methodPosition = SourceCodeAnalyzer.FindSourceElement(classFile, partCoverMethodElement); Assert.IsNull(methodPosition, "MethodPosition is not null."); }
public void FindMethod_SearchNonExistingGenericMethod_PositionIsNull() { PartCoverMethodElement partCoverMethodElement = new PartCoverMethodElement( "TestNamespace.AnalyzerTestClass", "GenericMethod", "void (int)"); var methodPosition = SourceCodeAnalyzer.FindSourceElement(elementClassFile, partCoverMethodElement); Assert.IsNull(methodPosition, "MethodPosition is not null."); }
public void FindMethod_SearchExistingMethod_PositionMustNotBeNullAndSupplyCorrectLinenumber() { PartCoverMethodElement partCoverMethodElement = new PartCoverMethodElement( "AnalyzerTestClass", "DoSomething", "string (string, string[], System.Guid, string, string, System.Decimal, int, stringint, ref int, float, double, bool, unsigned byte, char, object, byte, short, unsigned int, unsigned long, unsigned short, ICSharpCode.NRefactory.Ast.INode)"); var methodPosition = SourceCodeAnalyzer.FindSourceElement(classFile, partCoverMethodElement); Assert.IsNotNull(methodPosition, "MethodPosition must not be null."); Assert.AreEqual(35, methodPosition.Start, "Start line number does not match."); Assert.AreEqual(38, methodPosition.End, "End line number does not match."); }
public void FindMethod_SearchExistingConstructor_PositionMustNotBeNullAndSupplyCorrectLinenumber() { PartCoverMethodElement partCoverMethodElement = new PartCoverMethodElement( "AnalyzerTestClass", ".ctor", "void ()"); var methodPosition = SourceCodeAnalyzer.FindSourceElement(classFile, partCoverMethodElement); Assert.IsNotNull(methodPosition, "MethodPosition must not be null."); Assert.AreEqual(10, methodPosition.Start, "Start line number does not match."); Assert.AreEqual(12, methodPosition.End, "End line number does not match."); }
public void FindMethod_SearchExistingConstructor_PositionMustNotBeNullAndSupplyCorrectLinenumber() { PartCoverMethodElement partCoverMethodElement = new PartCoverMethodElement( "TestNamespace.AnalyzerTestClass", ".ctor", "void ()"); var methodPosition = SourceCodeAnalyzer.FindSourceElement(elementClassFile, partCoverMethodElement); Assert.IsNotNull(methodPosition, "MethodPosition must not be null."); Assert.AreEqual(10, methodPosition.Start, "Start line number does not match."); Assert.AreEqual(12, methodPosition.End, "End line number does not match."); }
public void FindMethod_SearchExistingMethod_PositionMustNotBeNullAndSupplyCorrectLinenumber() { PartCoverMethodElement partCoverMethodElement = new PartCoverMethodElement( "TestNamespace.AnalyzerTestClass", "DoSomething", "string (string, string[], System.Guid, string, string, System.Decimal, int, long, stringint, ref int, float, double, bool, unsigned byte, char, object, byte, short, unsigned int, unsigned long, unsigned short, ICSharpCode.NRefactory.Ast.INode)"); var methodPosition = SourceCodeAnalyzer.FindSourceElement(elementClassFile, partCoverMethodElement); Assert.IsNotNull(methodPosition, "MethodPosition must not be null."); Assert.AreEqual(37, methodPosition.Start, "Start line number does not match."); Assert.AreEqual(40, methodPosition.End, "End line number does not match."); }
/// <summary> /// Adds the coverage data of unexecuted methods. /// </summary> /// <param name="filenameByFileIdDictionary">Dictionary containing all files used in the report by their corresponding id.</param> private void AddCoverageDataOfUnexecutedMethods(Dictionary <string, string> filenameByFileIdDictionary) { var unexecutedMethods = this.Report.Descendants("Type") .Where(type => !type.Attribute("name").Value.Contains("__")) .Elements("Method") .Where(m => !m.Attribute("name").Value.StartsWith("get_", StringComparison.Ordinal) && !m.Attribute("name").Value.StartsWith("set_", StringComparison.Ordinal)) .Where(m => !m.Elements().Any()) .ToArray(); long counter = 0; foreach (var method in unexecutedMethods) { PartCoverMethodElement partCoverMethodElement = new PartCoverMethodElement( method.Parent.Attribute("name").Value, method.Attribute("name").Value, method.Attribute("sig").Value); // Get files in which property could be defined var fileIds = method.Parent.Descendants("pt") .Where(p => p.Attribute("fid") != null) .Select(p => p.Attribute("fid").Value) .Distinct() .ToArray(); if (this.SearchElement( partCoverMethodElement, filenameByFileIdDictionary, fileIds, method, UpdateMethodElement, this.Report)) { counter++; } } if (unexecutedMethods.LongLength > 0) { logger.DebugFormat(" " + Resources.AddedCoverageInformationUnexecutedMethods, counter, unexecutedMethods.LongLength); } }
/// <summary> /// Adds the coverage data of unexecuted methods. /// </summary> /// <param name="report">The report file as XContainer.</param> private static void AddCoverageDataOfUnexecutedMethods(XContainer report) { var unexecutedMethods = report.Descendants("Method").Where(m => !m.Elements().Any()); var filenameByFileIdDictionary = report.Descendants("File").ToDictionary(f => f.Attribute("id").Value, f => f.Attribute("url").Value); foreach (var method in unexecutedMethods) { PartCoverMethodElement partCoverMethodElement = new PartCoverMethodElement( method.Parent.Attribute("name").Value, method.Attribute("name").Value, method.Attribute("sig").Value); // Get files in which method could be defined var fileIds = method.Parent.Descendants("pt").Where(p => p.Attribute("fid") != null).Select(p => p.Attribute("fid").Value).Distinct(); foreach (var file in fileIds) { var elementPosition = SourceCodeAnalyzer.FindSourceElement(filenameByFileIdDictionary[file], partCoverMethodElement); if (elementPosition == null) { continue; } for (int i = elementPosition.Start; i <= elementPosition.End; i++) { var seqpnt = new XElement( "pt", new XAttribute("visit", "0"), new XAttribute("fid", file), new XAttribute("sl", i)); method.Add(seqpnt); } break; } } }