public void TestDeserializeZipCode()
        {
            string        json          = Request.GetString(new Uri("https://viacep.com.br/ws/01001000/json/"));
            ZipCodeItem   zipCodeItem   = Deserialize.ConvertTo <ZipCodeItem>(json);
            ZipCodeResult zipCodeResult = new ZipCodeResult(zipCodeItem);

            Assert.IsInstanceOfType(zipCodeItem.GetType(), typeof(ZipCodeItem).GetType());
            Assert.IsTrue(zipCodeResult);
            Assert.IsTrue(zipCodeResult.IsValid);
        }
예제 #2
0
    public static void InitialCache()
    {
        if (ZipCodeCache != null)
        {
            return;
        }

        string ZipCodeSourceString = "";

        StreamReader StreamReader = new System.IO.StreamReader(HttpContext.Current.Request.PhysicalApplicationPath + "_Element/ZipCodeBuilder/ZipSource.csv", System.Text.Encoding.Default);

        ZipCodeSourceString = StreamReader.ReadToEnd();//(各筆資料分隔符號為\r\n)
        ZipCodeSourceString = ZipCodeSourceString.Replace(" ", "");
        StreamReader.Dispose();

        ZipCodeCache = new List <ZipCodeItem>();
        foreach (string ZipCodeString in ZipCodeSourceString.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries))
        {
            string[] ZipCodeValue = ZipCodeString.Split(',');

            //ZipCode
            int ZipCode;
            if (int.TryParse(ZipCodeValue[0], out ZipCode) == false)
            {
                continue;
            }

            //City
            string City = ZipCodeValue[1];

            //Area
            string Area = ZipCodeValue[2];

            //Road
            string Road = ZipCodeValue[3];

            //Scope
            string Scope = ZipCodeValue[4];

            ZipCodeItem NewZipCodeItem = new ZipCodeItem(ZipCode.ToString(), City, Area, Road, Scope);
            ZipCodeCache.Add(NewZipCodeItem);
        }
    }
    public static void InitialCache()
    {
        if (ZipCodeCache != null) { return; }

        string ZipCodeSourceString = "";

        StreamReader StreamReader = new System.IO.StreamReader(HttpContext.Current.Request.PhysicalApplicationPath + "_Element/ZipCodeBuilder/ZipSource.csv", System.Text.Encoding.Default);
        ZipCodeSourceString = StreamReader.ReadToEnd();//(各筆資料分隔符號為\r\n)
        ZipCodeSourceString = ZipCodeSourceString.Replace(" ", "");
        StreamReader.Dispose();

        ZipCodeCache = new List<ZipCodeItem>();
        foreach (string ZipCodeString in ZipCodeSourceString.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries))
        {
            string[] ZipCodeValue = ZipCodeString.Split(',');

            //ZipCode
            int ZipCode;
            if (int.TryParse(ZipCodeValue[0], out ZipCode) == false) { continue; }

            //City
            string City = ZipCodeValue[1];

            //Area
            string Area = ZipCodeValue[2];

            //Road
            string Road = ZipCodeValue[3];

            //Scope
            string Scope = ZipCodeValue[4];

            ZipCodeItem NewZipCodeItem = new ZipCodeItem(ZipCode.ToString(), City, Area, Road, Scope);
            ZipCodeCache.Add(NewZipCodeItem);
        }
    }
예제 #4
0
 internal ZipCodeResult(ZipCodeItem value)
 {
     IsValid = !string.IsNullOrEmpty(value.Zip);
     Value   = value;
 }