예제 #1
0
        public void TestGetStateData()
        {
            var testStateName = "Maryland";
            var testState     = UsState.GetStateByName(testStateName);
            var testResult    = UsStateData.GetStateData(testState.ToString());

            Assert.IsNotNull(testResult);
            Assert.AreEqual("Maryland", testResult.StateName);
            Assert.IsNotNull(testResult.AverageEarnings);
            Assert.AreNotEqual(0, testResult.EmploymentSectors.Count);
            Assert.AreNotEqual(0, testResult.PercentOfGrads.Count);
            Assert.AreNotEqual(0, testResult.PropertyCrimeRate.Count);
            Assert.AreNotEqual(0, testResult.ViolentCrimeRate.Count);
            var percentCollegeGrad =
                testResult.PercentOfGrads.FirstOrDefault(x => x.Item1 == (OccidentalEdu.Bachelor | OccidentalEdu.Grad));

            Assert.AreNotEqual(0, percentCollegeGrad);
            System.Diagnostics.Debug.WriteLine(percentCollegeGrad);
            for (var i = 0; i < 100; i++)
            {
                var attempt = Etx.RandomRollAboveOrAt((int)Math.Round(percentCollegeGrad.Item2 * 2), Etx.Dice.OneHundred);
                System.Diagnostics.Debug.WriteLine(attempt);
            }

            //expected to resolve to national
            testResult = UsStateData.GetStateData(null);
            Assert.IsNotNull(testResult);
            Assert.AreEqual("United States", testResult.StateName);
            Assert.IsNotNull(testResult);
            Assert.IsNotNull(testResult.AverageEarnings);
            Assert.AreNotEqual(0, testResult.EmploymentSectors.Count);
            Assert.AreNotEqual(0, testResult.PercentOfGrads.Count);
            Assert.AreNotEqual(0, testResult.PropertyCrimeRate.Count);
            Assert.AreNotEqual(0, testResult.ViolentCrimeRate.Count);
        }
예제 #2
0
        public void TestGetStateByName()
        {
            var testResult = UsState.GetStateByName("New York");

            Assert.IsNotNull(testResult);

            testResult = UsState.GetStateByName("NewYork");
            Assert.IsNotNull(testResult);

            testResult = UsState.GetStateByName("Kansas");
            Assert.IsNotNull(testResult);
        }
예제 #3
0
        public static UsCityStateZip RandomAmericanCity(string zipCodePrefix = null, bool pickSuburbAtRandom = true)
        {
            const string HAS_HIGH_SCHOOL = "has-high-school";
            const string VALUE           = "value";
            //set defaults
            var ctz = new AddressData
            {
                PostalCode   = $"{UsCityStateZip.DF_ZIPCODE_PREFIX}{Etx.RandomInteger(1, 99):00}",
                RegionAbbrev = UsCityStateZip.DF_STATE_ABBREV
            };

            //pick a zip code prefix at random
            if (String.IsNullOrWhiteSpace(zipCodePrefix))
            {
                zipCodePrefix = UsCityStateZip.RandomAmericanPartialZipCode() ?? UsCityStateZip.DF_ZIPCODE_PREFIX;
            }

            //x-ref it to the zip code data
            var xpathString = $"//{UsCityStateZip.ZIP_CODE_PLURAL}//{UsCityStateZip.ZIP_CODE_SINGULAR}[@{PREFIX}='{zipCodePrefix}']";

            UsCityStateZip.UsZipCodeXml = UsCityStateZip.UsZipCodeXml ??
                                          XmlDocXrefIdentifier.GetEmbeddedXmlDoc(UsCityStateZip.US_ZIP_CODE_DATA, Assembly.GetExecutingAssembly());
            if (UsCityStateZip.UsZipCodeXml == null)
            {
                return(null);
            }
            var randZipCode = UsCityStateZip.UsZipCodeXml.SelectSingleNode(xpathString);

            if (randZipCode?.ParentNode?.Attributes?[NAME] == null)
            {
                ctz.Locality = UsCityStateZip.DF_CITY_NAME;
                return(new UsCityStateZip(ctz));
            }

            //get the containing us state
            ctz.RegionName = randZipCode.ParentNode.Attributes[NAME].Value;
            var nfState = UsState.GetStateByName(ctz.RegionName) ??
                          UsState.GetStateByPostalCode(UsCityStateZip.DF_STATE_ABBREV);

            ctz.RegionAbbrev = nfState.StateAbbrev ?? UsCityStateZip.DF_STATE_ABBREV;
            ctz.SortingCode  = $"{Etx.MyRand.Next(1, 9999):0000}";

            if (!randZipCode.HasChildNodes)
            {
                ctz.PostalCode = $"{zipCodePrefix}{Etx.RandomInteger(1, 99):00}";
            }
            else
            {
                //pick a particular zip-code (ZIP5)
                var zipCodes =
                    randZipCode.ChildNodes.Cast <XmlElement>()
                    .Where(
                        x =>
                        x.Attributes[HAS_HIGH_SCHOOL] != null &&
                        x.Attributes[HAS_HIGH_SCHOOL].Value == Boolean.TrueString)
                    .Select(x => x.Attributes[VALUE].Value).ToArray();
                if (zipCodes.Length <= 0)
                {
                    return(new UsCityStateZip(ctz));
                }
                var pickNum = Etx.RandomInteger(0, zipCodes.Length - 1);
                ctz.PostalCode = zipCodes[pickNum];
            }
            var rr = new UsCityStateZip(ctz);

            rr.SetAddrDataToXmlValues(pickSuburbAtRandom);
            return(rr);
        }