Esempio n. 1
0
        public void Search()
        {
            Helper.PrintMem();

            //预热
            ChinaAdCode.Search("广东省");

            Helper.Time("编码查询", () =>
            {
                var info = ChinaAdCode.Get(440402);
            }, 1000000);

            Helper.Time("省份查询", () =>
            {
                var c = ChinaAdCode.Search("广东省");
            }, 1000000);

            Helper.Time("省市查询", () =>
            {
                var c = ChinaAdCode.Search("广东省", "深圳");
            }, 1000000);

            Helper.Time("省市县查询", () =>
            {
                var c = ChinaAdCode.Search("广东省", "珠海", "香洲");
            }, 1000000);
        }
Esempio n. 2
0
        public void Can_Match_SourceFile()
        {
            var t = typeof(ChinaAdCode);

            using (var stream = t.Assembly.GetManifestResourceStream($"{t.Namespace}.{t.Name}.txt"))
            {
                using (StreamReader sr = new StreamReader(stream))
                {
                    string line;
                    while (!string.IsNullOrEmpty((line = sr.ReadLine())))
                    {
                        var values = line.Split('|');

                        if (values.Length != 13)
                        {
                            continue;
                        }

                        var id        = int.Parse(values[0]);
                        var parentId  = int.Parse(values[1]);
                        var level     = int.Parse(values[2]);
                        var name      = values[3];
                        var shortName = values[4];
                        var province  = values[5];
                        var city      = values[6];
                        var district  = values[7];
                        var lng       = double.Parse(values[8]);
                        var lat       = double.Parse(values[9]);
                        var cityCode  = values[10];
                        var zipCode   = values[11];
                        var pinYin    = values[12];

                        var info = ChinaAdCode.Get(id);

                        Assert.Equal(id, info.Id);
                        Assert.Equal(parentId, info.ParentId);
                        Assert.Equal(level, info.Level);
                        Assert.Equal(name, info.Name);
                        Assert.Equal(shortName, info.ShortName);
                        Assert.Equal(province, info.Province);
                        Assert.Equal(city, info.City);
                        Assert.Equal(district, info.District);
                        Assert.Equal(lng, info.Lng);
                        Assert.Equal(lat, info.Lat);
                        Assert.Equal(cityCode, info.CityCode);
                        Assert.Equal(zipCode, info.ZipCode);
                        Assert.Equal(pinYin, info.PinYin);
                    }
                }
            }
        }
Esempio n. 3
0
        public void Can_Match_AdCode()
        {
            var adCode = ChinaAdCode.Get(110107);

            Assert.Equal(110107, adCode.Id);
        }