Ejemplo n.º 1
0
        public void FeatureCodeComposer_ComposesFileCorrectly()
        {
            var src = @"testdata\test_featureCodes_en.txt";
            var dst = @"testdata\test_featureCodes_en.out.txt";

            GeoFileWriter.WriteFeatureCodes(dst, GeoFileReader.ReadFeatureCodes(src));

            FileUtil.EnsureFilesAreFunctionallyEqual(src, dst, 3, 0, new[] { '\t' }, Encoding.UTF8, true);
        }
Ejemplo n.º 2
0
        public void FeatureCodeParser_ParsesFileCorrectly()
        {
            var target = GeoFileReader.ReadFeatureCodes(@"testdata\test_featureCodes_en.txt").ToArray();

            Assert.AreEqual(3, target.Length);

            //A.ADM1 should result in a "A" class and "ADM1" code
            Assert.AreEqual("A", target[0].Class);
            Assert.AreEqual("ADM1", target[0].Code);

            Assert.AreEqual("first-order administrative division", target[0].Name);
            Assert.AreEqual("a primary administrative division of a country, such as a state in the United States", target[0].Description);

            ///When no dot in the featurecode is found, the class property should contain the entire string and code property should be null
            Assert.AreEqual("XXX", target[1].Class);
            Assert.IsNull(target[1].Code);

            //When the featurecode is "null" both the code and class property should be null
            Assert.IsNull(target[2].Class);
            Assert.IsNull(target[2].Code);
        }
Ejemplo n.º 3
0
 public void FileReader_FeatureCodes_StreamOverload()
 {
     using (var s = File.OpenRead(@"testdata\test_featurecodes_en.txt"))
         GeoFileReader.ReadFeatureCodes(s).Count();
 }
Ejemplo n.º 4
0
        private static GeoFile[] GetCountryDumps(GeoFileDownloader downloader)
        {
            var w        = new WebClient();
            var document = w.DownloadString(downloader.BaseUri);

            var countries = new Regex("href=\"([A-Z]{2}.zip)", RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase)
                            .Matches(document)
                            .Cast <Match>()
                            .Select(m => new GeoFile {
                Filename = m.Groups[1].Value, Test = (f) => ExecuteTest(f, (fn) => { return(GeoFileReader.ReadExtendedGeoNames(fn).Count()); })
            });

            var featurecodes = new Regex("href=\"(featureCodes_[A-Z]{2}.txt)", RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase)
                               .Matches(document)
                               .Cast <Match>()
                               .Select(m => new GeoFile {
                Filename = m.Groups[1].Value, Test = (f) => ExecuteTest(f, (fn) => { return(GeoFileReader.ReadFeatureCodes(fn).Count()); })
            });

            return(countries.Union(featurecodes).OrderBy(m => m.Filename).ToArray());
        }