public IResult RunTest() { XMLResult result = new XMLResult(); if (!Common.IsFileAvailable(EventFilePath)) { result.Errors.Add(string.Format("File not found: [{0}]", EventFilePath)); } if (!Common.IsFileAvailable(ExposureFilePath)) { result.Errors.Add(string.Format("File not found: [{0}]", ExposureFilePath)); } if (!result.HasErrors) { XmlDocument eventXMLDoc = new XmlDocument(); XmlDocument exposureXMLDoc = new XmlDocument(); eventXMLDoc.Load(EventFilePath); exposureXMLDoc.Load(ExposureFilePath); XmlNodeList eventNodeList = eventXMLDoc.SelectNodes("/events/event"); EventCompaniesList eventCompaniesCollection = new EventCompaniesList(); foreach (XmlNode eventNode in eventNodeList) { EventCompanies eventCompanies = new EventCompanies(GetNodeIdValue(eventNode)); XmlNodeList eventRegionList = eventNode.SelectNodes("region"); foreach (XmlNode regionNode in eventRegionList) { string region = regionNode.InnerText; //get all the matching regions in the Exposure file for each region in the in the Events file XmlNodeList matchingRegions = exposureXMLDoc.SelectNodes(string.Format("descendant::company[region='{0}']", region)); foreach (XmlNode matchingRegion in matchingRegions) { //get the company id belonging to the matching region string companyId = matchingRegion.FirstChild.InnerText; if (!eventCompanies.CompanyIds.Contains(companyId)) { eventCompanies.CompanyIds.Add(companyId); } } } if (eventCompanies.CompanyIds.Count > 0) { eventCompaniesCollection.Add(eventCompanies); } } result.SetResult(FormatTestOutput(eventCompaniesCollection)); } return result; }
public IResult RunTest() { XMLResult result = new XMLResult(); if (!Common.IsFileAvailable(PuzzleFilePath)) { result.Errors.Add(string.Format("File not found: [{0}]", PuzzleFilePath)); } if (!result.HasErrors) { // Creating the LINQ to XML query var values = from v in XElement.Load(PuzzleFilePath).Elements("value") select v.Value; // Executing the query & summing the values int sum = 0; foreach (var value in values) { sum += Convert.ToInt32(value); } result.SetResult(string.Format("Sum of values: [{0}]", sum)); } return result; }