Exemplo n.º 1
0
        public void FormatPhoneNumber_PhoneNumberInDresdenGermany_ReturnsFormattedNumber(
            [Values(DISTANCE_RULE.CANONICAL, DISTANCE_RULE.InternationalRule, DISTANCE_RULE.LongDistanceRule,
                    DISTANCE_RULE.SameAreaRule)] DISTANCE_RULE distanceRule,
            [Values("+49 (351) 1234567", "00493511234567", "03511234567", "1234567")] string expected)
        {
            MockRepository           mocks                = new MockRepository();
            IPhoneNumberDataXml      xmlDataProvider      = mocks.Stub <IPhoneNumberDataXml>();
            IPhoneNumberDataRegistry registryDataProvider = mocks.Stub <IPhoneNumberDataRegistry>();

            string number = "+493511234567";

            using (mocks.Record())
            {
                registryDataProvider.GetUserCountryID();
                LastCall.Return("49");
                registryDataProvider.GetUserAreaCode();
                LastCall.Return("351");
                registryDataProvider.GetPhoneFormat(49, DISTANCE_RULE.InternationalRule);
                LastCall.Return("00EFG");
                registryDataProvider.GetPhoneFormat(49, DISTANCE_RULE.LongDistanceRule);
                LastCall.Return("0FG");
                registryDataProvider.GetPhoneFormat(49, DISTANCE_RULE.SameAreaRule);
                LastCall.Return("G");

                xmlDataProvider.GetCountryCode("4935");
                LastCall.Return("49");
                xmlDataProvider.GetAreaCode("+493511234567");
                LastCall.Return("+49351");
            }

            PhoneNumbers phoneNumberConverter = new PhoneNumbers(xmlDataProvider, registryDataProvider);
            string       actual = phoneNumberConverter.FormatPhoneNumber(number, distanceRule);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 2
0
        private string GetUserPhoneFormat(DISTANCE_RULE distanceRule)
        {
            if (distanceRule == DISTANCE_RULE.CANONICAL)
            {
                return(PhoneNumberConstants.CANONICAL_FORMAT);
            }

            string result = "";
            string id     = GetUserCountryID();

            if (String.IsNullOrEmpty(id))
            {
                return(String.Empty);
            }

            int userCountryID = int.Parse(id);

            result = registryDataProvider.GetPhoneFormat(userCountryID, distanceRule);
            if (String.IsNullOrEmpty(result))
            {
                result = xmlDataProvider.GetPhoneFormat(userCountryID, distanceRule);
            }

            return(result);
        }