public void FindProperty_SearchExistingProperty_PositionMustNotBeNullAndSupplyCorrectLinenumber()
        {
            PropertyElement propertyElement = new PropertyElement("get_AutoProperty");

            var propertyPosition = SourceCodeAnalyzer.FindSourceElement(classFile, propertyElement);

            Assert.IsNotNull(propertyPosition, "PropertyPosition must not be null.");

            Assert.AreEqual(44, propertyPosition.Start, "Start line number does not match.");
            Assert.AreEqual(44, propertyPosition.End, "End line number does not match.");
        }
        public void FindProperty_SearchNonExistingProperty_PositionIsNull()
        {
            PropertyElement propertyElement = new PropertyElement("get_DoesNotExist");

            var propertyPosition = SourceCodeAnalyzer.FindSourceElement(classFile, propertyElement);

            Assert.IsNull(propertyPosition, "PropertyPosition is not null.");
        }
        /// <summary>
        /// Adds the coverage data of auto properties.
        /// </summary>
        /// <param name="report">The report file as XContainer.</param>
        private static void AddCoverageDataOfAutoProperties(XContainer report)
        {
            Func<XElement, bool> isProperty = v => v.HasAttributeWithValue("isGetter", "true") || v.HasAttributeWithValue("isSetter", "true");

            var unexecutedProperties = report.Descendants("Module")
                                    .Elements("Classes")
                                    .Elements("Class")
                                    .Elements("Methods")
                                    .Elements("Method")
                                    .Where(m => m.Attribute("skippedDueTo") == null
                                        && isProperty(m)
                                        && m.Element("SequencePoints") != null
                                        && !m.Element("SequencePoints").Elements().Any())
                                    .ToArray();

            foreach (var property in unexecutedProperties)
            {
                var filenameByFileIdDictionary = property.Parent.Parent.Parent.Parent
                    .Element("Files")
                    .Elements("File")
                    .ToDictionary(f => f.Attribute("uid").Value, f => f.Attribute("fullPath").Value);

                string methodName = Regex.Match(property.Element("Name").Value, MethodRegex).Groups["MethodName"].Value;
                PropertyElement openCoverProperty = new PropertyElement(methodName);

                // Get files in which property could be defined
                var fileIds = property.Parent.Elements("Method").Elements("FileRef").Select(f => f.Attribute("uid").Value).Distinct();

                foreach (var file in fileIds)
                {
                    var elementPosition = SourceCodeAnalyzer.FindSourceElement(filenameByFileIdDictionary[file], openCoverProperty);

                    if (elementPosition == null)
                    {
                        continue;
                    }

                    property.Add(new XElement("FileRef", new XAttribute("uid", file)));

                    var seqpnt = new XElement(
                        "SequencePoint",
                        new XAttribute("vc", property.Element("MethodPoint").Attribute("vc").Value),
                        new XAttribute("sl", elementPosition.Start));

                    property.Element("SequencePoints").Add(seqpnt);

                    break;
                }
            }
        }
        /// <summary>
        /// Adds the coverage data of auto properties.
        /// </summary>
        /// <param name="report">The report file as XContainer.</param>
        private static void AddCoverageDataOfAutoProperties(XContainer report)
        {
            Func<string, bool> isProperty = v => v.StartsWith("get_", StringComparison.Ordinal) || v.StartsWith("set_", StringComparison.Ordinal);

            var unexecutedProperties = report.Descendants("Method").Where(m => isProperty(m.Attribute("name").Value)
                && (!m.Elements().Any() || !m.Elements().Any(pt => pt.Attribute("sl") != null)));

            var filenameByFileIdDictionary = report.Descendants("File").ToDictionary(f => f.Attribute("id").Value, f => f.Attribute("url").Value);

            foreach (var property in unexecutedProperties)
            {
                PropertyElement propertyElement = new PropertyElement(property.Attribute("name").Value);

                // Get files in which method could be defined
                var fileIds = property.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], propertyElement);

                    if (elementPosition == null)
                    {
                        continue;
                    }

                    if (!property.Elements().Any())
                    {
                        var seqpnt = new XElement(
                            "pt",
                            new XAttribute("visit", "0"),
                            new XAttribute("fid", file),
                            new XAttribute("sl", elementPosition.Start));

                        property.Add(seqpnt);
                    }
                    else
                    {
                        foreach (var pt in property.Elements().Take(1))
                        {
                            pt.Add(new XAttribute("sl", elementPosition.Start));
                            pt.Add(new XAttribute("fid", file));
                        }
                    }

                    break;
                }
            }
        }