Example #1
0
        public void TestFinesseCityName()
        {
            var testOutput = UsCityStateZip.FinesseCityName("CANDLER-MCAFEE");

            Assert.AreEqual("Candler-McAfee", testOutput);
            Console.WriteLine(testOutput);
            testOutput = UsCityStateZip.FinesseCityName("MC LEAN");
            Assert.AreEqual("McLean", testOutput);
            Console.WriteLine(testOutput);
        }
Example #2
0
        /// <summary>
        /// Picks a single xml element at random from the US Banks data file
        /// first attempting to match on <see cref="ca"/>, if given.
        /// </summary>
        /// <param name="ca"></param>
        /// <returns></returns>
        internal static XmlElement GetBankXmlElement(CityArea ca)
        {
            UsBanksXml = UsBanksXml ?? XmlDocXrefIdentifier.GetEmbeddedXmlDoc(US_BANKS, Assembly.GetExecutingAssembly());
            if (UsBanksXml == null)
            {
                return(null);
            }
            XmlElement bankXmlElem  = null;
            var        pickFromList = new List <XmlElement>();

            if (!string.IsNullOrWhiteSpace(ca?.City) &&
                !string.IsNullOrWhiteSpace(ca.GetRegionAbbrev()))
            {
                var cityName = UsCityStateZip.FinesseCityName(ca.City);

                var nodes = UsBanksXml.SelectNodes($"//com[@us-state='{ca.GetRegionAbbrev().ToUpper()}']");
                if (nodes != null && nodes.Count > 0)
                {
                    foreach (var node in nodes)
                    {
                        var elem = node as XmlElement;
                        if (elem == null)
                        {
                            continue;
                        }
                        if (!elem.HasAttributes)
                        {
                            continue;
                        }
                        if (elem.GetAttribute("city") != cityName)
                        {
                            continue;
                        }
                        pickFromList.Add(elem);
                    }
                }
            }

            if (!pickFromList.Any())
            {
                var allNodes = UsBanksXml.SelectNodes("//com");
                if (allNodes == null)
                {
                    return(null);
                }
                foreach (var node in allNodes)
                {
                    var elem = node as XmlElement;
                    if (elem == null)
                    {
                        continue;
                    }
                    if (!elem.HasAttributes)
                    {
                        continue;
                    }
                    pickFromList.Add(elem);
                }
            }

            if (pickFromList.Any())
            {
                bankXmlElem = pickFromList[Etx.RandomInteger(0, pickFromList.Count - 1)];
            }
            return(bankXmlElem);
        }