public void GetCountriesWithoutPostalCode_None_77Countries()
        {
            var exp = new Country[] { Country.AE, Country.AG, Country.AO, Country.AQ, Country.AW, Country.BF, Country.BI, Country.BJ, Country.BQ, Country.BS, Country.BV, Country.BW, Country.BZ, Country.CD, Country.CF, Country.CG, Country.CI, Country.CK, Country.CM, Country.CW, Country.DJ, Country.DM, Country.DO, Country.EH, Country.ER, Country.FJ, Country.GD, Country.GH, Country.GM, Country.GN, Country.GQ, Country.GY, Country.HK, Country.IE, Country.JM, Country.KE, Country.KI, Country.KM, Country.KN, Country.KP, Country.KW, Country.LC, Country.ML, Country.MO, Country.MR, Country.MS, Country.MU, Country.MV, Country.MW, Country.NR, Country.NU, Country.QA, Country.RW, Country.SB, Country.SC, Country.SJ, Country.SL, Country.SO, Country.SR, Country.SS, Country.ST, Country.SX, Country.SY, Country.TF, Country.TG, Country.TK, Country.TL, Country.TO, Country.TV, Country.TZ, Country.UG, Country.UM, Country.UZ, Country.VU, Country.WS, Country.YE, Country.ZW };
            var act = PostalCodeCountryInfo.GetCountriesWithoutPostalCode().ToArray();

            foreach (var item in act)
            {
                Console.WriteLine(item);
            }

            Assert.AreEqual(exp.Length, act.Length, "act.Length");

            CollectionAssert.AreEqual(exp, act);
        }
        public void GetCountriesWithFormatting_None_59Countries()
        {
            var exp = new Country[] { Country.AD, Country.AI, Country.AR, Country.AS, Country.AX, Country.AZ, Country.BB, Country.BM, Country.BR, Country.CA, Country.CL, Country.CU, Country.CZ, Country.DK, Country.FI, Country.FK, Country.FM, Country.FO, Country.GA, Country.GB, Country.GG, Country.GI, Country.GL, Country.GR, Country.GS, Country.GU, Country.IM, Country.IO, Country.IR, Country.JE, Country.JP, Country.KR, Country.KY, Country.LB, Country.LT, Country.LV, Country.MA, Country.MC, Country.MD, Country.MH, Country.MP, Country.MT, Country.NL, Country.PL, Country.PN, Country.PT, Country.PW, Country.SA, Country.SE, Country.SH, Country.SI, Country.SK, Country.SN, Country.TC, Country.US, Country.VC, Country.VE, Country.VG, Country.VI };
            var act = PostalCodeCountryInfo.GetCountriesWithFormatting().ToArray();

            foreach (var item in act)
            {
                Console.WriteLine(item);
            }

            Assert.AreEqual(exp.Length, act.Length, "act.Length");

            CollectionAssert.AreEqual(exp, act);
        }
        private void CurrencyExists(Country country, Date? mesurement)
        {
            var test = mesurement.HasValue ? mesurement.Value : Date.Today;

            if (TestMode)
            {
                if (Currency.Empty == country.GetCurrency(test))
                {
                    Console.WriteLine("{0} ({0:f}) on {1:yyyy-MM-dd}", country, test);
                }
            }
            else
            {
                Assert.AreNotEqual(Currency.Empty, country.GetCurrency(test), "{0} ({0:f}) on {1:yyyy-MM-dd}", country, test);
            }
        }
Exemple #4
0
 public CountryToCurrency(Country country, Currency currency)
     : this(country, currency, Date.MinValue)
 {
 }
Exemple #5
0
 public CountryToCurrency(Country country, Currency currency, Date startdate)
 {
     m_Country = country;
     m_Currency = currency;
     m_StartDate = startdate;
 }
 partial void OnReadXml(Country other);
Exemple #7
0
 private static void IsValid(string postalcode, Country country)
 {
     Assert.IsTrue(PostalCode.IsValid(postalcode, country), "Postal code '{0}' should be valid for {1:f}.", postalcode, country);
 }
Exemple #8
0
        private static void IsNotValid(Country country, bool alfa, bool prefix, params int[] lengths)
        {
            // Length 1
            IsNotValid(country, "1", alfa, alfa, prefix, lengths);
            IsNotValid(country, "A", !alfa, alfa, prefix, lengths);

            // Length 2
            IsNotValid(country, "12", alfa, alfa, prefix, lengths);
            IsNotValid(country, "AB", !alfa, alfa, prefix, lengths);
            IsNotValid(country, "A1", !alfa, alfa, prefix, lengths);

            // Length 3
            IsNotValid(country, "123", alfa, alfa, prefix, lengths);
            IsNotValid(country, "ABC", !alfa, alfa, prefix, lengths);
            IsNotValid(country, "AB1", !alfa, alfa, prefix, lengths);
            IsNotValid(country, "A12", !alfa, alfa, prefix, lengths);

            // Length 4
            IsNotValid(country, "1234", alfa, alfa, prefix, lengths);
            IsNotValid(country, "AB1C", !alfa, alfa, prefix, lengths);
            IsNotValid(country, "AB12", !alfa, alfa, prefix, lengths);
            IsNotValid(country, "A123", !alfa, alfa, prefix, lengths);

            // Length 5
            IsNotValid(country, "12345", alfa, alfa, prefix, lengths);
            IsNotValid(country, "AB12C", !alfa, alfa, prefix, lengths);
            IsNotValid(country, "AB123", !alfa, alfa, prefix, lengths);
            IsNotValid(country, "A1234", !alfa, alfa, prefix, lengths);

            // Length 6
            IsNotValid(country, "123456", alfa, alfa, prefix, lengths);
            IsNotValid(country, "AB123C", !alfa, alfa, prefix, lengths);
            IsNotValid(country, "AB1234", !alfa, alfa, prefix, lengths);
            IsNotValid(country, "A12345", !alfa, alfa, prefix, lengths);
            IsNotValid(country, "A1B3C3", !alfa, alfa, prefix, lengths);
            IsNotValid(country, "1234AB", !alfa, alfa, prefix, lengths);

            // Length 7
            IsNotValid(country, "1234567", alfa, alfa, prefix, lengths);
            IsNotValid(country, "AB1234C", !alfa, alfa, prefix, lengths);
            IsNotValid(country, "AB12345", !alfa, alfa, prefix, lengths);
            IsNotValid(country, "A123456", !alfa, alfa, prefix, lengths);
            IsNotValid(country, "A1B3C3D", !alfa, alfa, prefix, lengths);

            // Length 8
            IsNotValid(country, "12345678", alfa, alfa, prefix, lengths);
            IsNotValid(country, "AB1234CD", !alfa, alfa, prefix, lengths);
            IsNotValid(country, "AB123456", !alfa, alfa, prefix, lengths);
            IsNotValid(country, "A1234567", !alfa, alfa, prefix, lengths);
            IsNotValid(country, "A1B3C3D4", !alfa, alfa, prefix, lengths);

            // Length 9
            IsNotValid(country, "123456789", alfa, alfa, prefix, lengths);
            IsNotValid(country, "AB12345CD", !alfa, alfa, prefix, lengths);
            IsNotValid(country, "AB1234567", !alfa, alfa, prefix, lengths);
            IsNotValid(country, "A12345678", !alfa, alfa, prefix, lengths);
            IsNotValid(country, "A1B3C3D4E", !alfa, alfa, prefix, lengths);

            // Length 10
            IsNotValid(country, "1234567890", alfa, alfa, prefix, lengths);
            IsNotValid(country, "AB123456CD", !alfa, alfa, prefix, lengths);
            IsNotValid(country, "AB12345678", !alfa, alfa, prefix, lengths);
            IsNotValid(country, "A123456789", !alfa, alfa, prefix, lengths);
            IsNotValid(country, "A1B3C3D4EF", !alfa, alfa, prefix, lengths);

            // Length 11
            IsNotValid(country, "12345678901", alfa, alfa, prefix, lengths);
            IsNotValid(country, "AB1234567CD", !alfa, alfa, prefix, lengths);
            IsNotValid(country, "AB123456789", !alfa, alfa, prefix, lengths);
            IsNotValid(country, "A1234567890", !alfa, alfa, prefix, lengths);
            IsNotValid(country, "A1B3C3D4E5F", !alfa, alfa, prefix, lengths);
        }
Exemple #9
0
        private static void IsNotValid(Country country, string code, bool test, bool alpha, bool prefix, int[] lengths)
        {
            var pcode = country.IsoAlpha2Code + code;

            var len = code.Length;
            var plen = pcode.Length;

            // General tests. These are test more than once (so be it).
            Assert.AreEqual(len > 1 && len <= 10, PostalCode.IsValid(code), "The postal code '{0}' should be {1}valid.", code, len > 1 && len <= 10 ? "" : "not ");
            Assert.AreEqual(plen <= 10, PostalCode.IsValid(country.IsoAlpha2Code + code), "The postal code '{1:2}{0}' should be {2}valid.", code, country, plen <= 10 ? "" : "not ");

            // Tests if the types differ (alphanumeric versus numeric) or if the lenghts differ.
            if (test || !lengths.Contains(len))
            {
                Assert.IsFalse(PostalCode.IsValid(code, country), "The postal code '{0}' should not be valid for {1:f (2)}.", code, country);
            }
            // Tests if the types differ (alphanumeric versus numeric), if the lenghts differ, or if prefix is not supported.
            // And if not testing for an alfa pattern, or an alfa pattern that does not match the concatenated code.
            if ((test || !prefix || !lengths.Contains(len)) && (!alpha || !lengths.Contains(plen)))
            {
                Assert.IsFalse(PostalCode.IsValid(country.IsoAlpha2Code + code, country), "The postal code '{1:2}{0}' should not be valid for {1:f (2)}.", code, country);
            }
        }
Exemple #10
0
 private static void IsNotValid(string code, Country country)
 {
     Assert.IsFalse(PostalCode.IsValid(code, country), "Postal code '{0}' should be not valid for {1:f}.", code, country);
 }
Exemple #11
0
        public void IsValidFor_TestStruct_1Country()
        {
            var act = TestStruct.IsValidFor().ToArray();
            var exp = new Country[] { Country.CA };
            CollectionAssert.AllItemsAreUnique(act);

            CollectionAssert.AreEqual(exp, act);
        }
Exemple #12
0
        public void IsValidFor_0123456_3Countries()
        {
            var postalcode = PostalCode.Parse("0123456");
            var act = postalcode.IsValidFor().ToArray();
            var exp = new Country[] { Country.CL, Country.IL, Country.JP };
            CollectionAssert.AllItemsAreUnique(act);

            CollectionAssert.AreEqual(exp, act);
        }
        /// <summary>Gets the postal code country info associated with the specified country.</summary>
        /// <param name="country">
        /// The specified country.
        /// </param>
        public static PostalCodeCountryInfo GetInstance(Country country)
        {
            PostalCodeCountryInfo instance;

            if (Instances.TryGetValue(country, out instance))
            {
                return instance;
            }
            return new PostalCodeCountryInfo()
            {
                Country = country,
            };
        }
 /// <summary>Creates a new instance.</summary>
 /// <remarks>
 /// Used for ininitalating the Instances dictionary.
 /// </remarks>
 private static PostalCodeCountryInfo New(Country country, string validation, string search = null, string replace = null, bool isSingle = false)
 {
     return new PostalCodeCountryInfo()
     {
         Country = country,
         ValidationPattern = new Regex(validation, RegexOptions.Compiled | RegexOptions.IgnoreCase),
         FormattingSearchPattern = String.IsNullOrEmpty(search) ? null : new Regex(search, RegexOptions.Compiled),
         FormattingReplacePattern = replace,
         IsSingleValue = isSingle
     };
 }