Example #1
0
        [TestMethod] public void testShortNumbersValidAndCorrectCost()
        {
            List <String> invalidStringCases = new List <String>();

            foreach (String regionCode in shortNumberInfo.getSupportedRegions())
            {
                String exampleShortNumber = shortNumberInfo.getExampleShortNumber(regionCode);
                if (!shortNumberInfo.isValidShortNumberForRegion(exampleShortNumber, regionCode))
                {
                    String invalidStringCase = "region_code: " + regionCode + ", national_number: " +
                                               exampleShortNumber;
                    invalidStringCases.Add(invalidStringCase);
                    LOGGER.log(Level.SEVERE, "Failed validation for string " + invalidStringCase);
                }
                PhoneNumber phoneNumber = phoneNumberUtil.parse(exampleShortNumber, regionCode);
                if (!shortNumberInfo.isValidShortNumber(phoneNumber))
                {
                    invalidCases.Add(phoneNumber);
                    LOGGER.log(Level.SEVERE, "Failed validation for " + phoneNumber.ToString());
                }

                foreach (
                    ShortNumberInfo.ShortNumberCost cost in Enum.GetValues(typeof(ShortNumberInfo.ShortNumberCost)))
                {
                    exampleShortNumber = shortNumberInfo.getExampleShortNumberForCost(regionCode, cost);
                    if (!exampleShortNumber.Equals(""))
                    {
                        if (cost != shortNumberInfo.getExpectedCostForRegion(exampleShortNumber, regionCode))
                        {
                            wrongTypeCases.Add(phoneNumber);
                            LOGGER.log(Level.SEVERE, "Wrong cost for " + phoneNumber.ToString());
                        }
                    }
                }
            }
            Assert.AreEqual(0, invalidStringCases.Count);
            Assert.AreEqual(0, invalidCases.Count);
            Assert.AreEqual(0, wrongTypeCases.Count);
        }
Example #2
0
        [TestMethod] public void testGetExpectedCost()
        {
            String premiumRateExample = shortInfo.getExampleShortNumberForCost(
                RegionCode.FR, ShortNumberInfo.ShortNumberCost.PREMIUM_RATE);

            Assert.AreEqual(ShortNumberInfo.ShortNumberCost.PREMIUM_RATE,
                            shortInfo.getExpectedCostForRegion(premiumRateExample, RegionCode.FR));
            PhoneNumber premiumRateNumber = new PhoneNumber();

            premiumRateNumber.setCountryCode(33).setNationalNumber(int.Parse(premiumRateExample));
            Assert.AreEqual(ShortNumberInfo.ShortNumberCost.PREMIUM_RATE,
                            shortInfo.getExpectedCost(premiumRateNumber));

            String standardRateExample = shortInfo.getExampleShortNumberForCost(
                RegionCode.FR, ShortNumberInfo.ShortNumberCost.STANDARD_RATE);

            Assert.AreEqual(ShortNumberInfo.ShortNumberCost.STANDARD_RATE,
                            shortInfo.getExpectedCostForRegion(standardRateExample, RegionCode.FR));
            PhoneNumber standardRateNumber = new PhoneNumber();

            standardRateNumber.setCountryCode(33).setNationalNumber(int.Parse(standardRateExample));
            Assert.AreEqual(ShortNumberInfo.ShortNumberCost.STANDARD_RATE,
                            shortInfo.getExpectedCost(standardRateNumber));

            String tollFreeExample = shortInfo.getExampleShortNumberForCost(
                RegionCode.FR, ShortNumberInfo.ShortNumberCost.TOLL_FREE);

            Assert.AreEqual(ShortNumberInfo.ShortNumberCost.TOLL_FREE,
                            shortInfo.getExpectedCostForRegion(tollFreeExample, RegionCode.FR));
            PhoneNumber tollFreeNumber = new PhoneNumber();

            tollFreeNumber.setCountryCode(33).setNationalNumber(int.Parse(tollFreeExample));
            Assert.AreEqual(ShortNumberInfo.ShortNumberCost.TOLL_FREE,
                            shortInfo.getExpectedCost(tollFreeNumber));

            Assert.AreEqual(ShortNumberInfo.ShortNumberCost.UNKNOWN_COST,
                            shortInfo.getExpectedCostForRegion("12345", RegionCode.FR));
            PhoneNumber unknownCostNumber = new PhoneNumber();

            unknownCostNumber.setCountryCode(33).setNationalNumber(12345L);
            Assert.AreEqual(ShortNumberInfo.ShortNumberCost.UNKNOWN_COST,
                            shortInfo.getExpectedCost(unknownCostNumber));

            // Test that an invalid number may nevertheless have a cost other than UNKNOWN_COST.
            Assert.IsFalse(shortInfo.isValidShortNumberForRegion("116123", RegionCode.FR));
            Assert.AreEqual(ShortNumberInfo.ShortNumberCost.TOLL_FREE,
                            shortInfo.getExpectedCostForRegion("116123", RegionCode.FR));
            PhoneNumber invalidNumber = new PhoneNumber();

            invalidNumber.setCountryCode(33).setNationalNumber(116123L);
            Assert.IsFalse(shortInfo.isValidShortNumber(invalidNumber));
            Assert.AreEqual(ShortNumberInfo.ShortNumberCost.TOLL_FREE,
                            shortInfo.getExpectedCost(invalidNumber));

            // Test a nonexistent country code.
            Assert.AreEqual(ShortNumberInfo.ShortNumberCost.UNKNOWN_COST,
                            shortInfo.getExpectedCostForRegion("911", RegionCode.ZZ));
            unknownCostNumber.clear();
            unknownCostNumber.setCountryCode(123).setNationalNumber(911L);
            Assert.AreEqual(ShortNumberInfo.ShortNumberCost.UNKNOWN_COST,
                            shortInfo.getExpectedCost(unknownCostNumber));
        }