public void GetCountryNameByNumber_PhoneNumberInDresdenGermanyWithoutRegistryAccess_GetsCountryNameFromXML() { MockRepository mocks = new MockRepository(); IPhoneNumberDataXml xmlDataProvider = mocks.StrictMock <IPhoneNumberDataXml>(); IPhoneNumberDataRegistry registryDataProvider = mocks.Stub <IPhoneNumberDataRegistry>(); string number = "+493511234567"; using (mocks.Record()) { xmlDataProvider.GetCountryCode("4935"); LastCall.Return("49"); xmlDataProvider.GetAreaCode("+493511234567"); LastCall.Return("+49351"); xmlDataProvider.GetCountryID("+49351"); LastCall.Return("49"); xmlDataProvider.GetCountryName(49); LastCall.Return("Germany"); } PhoneNumbers phoneNumberConverter = new PhoneNumbers(xmlDataProvider, registryDataProvider); phoneNumberConverter.GetCountryNameByNumber(number); mocks.VerifyAll(); }
public void GetCountryNameByNumber_PhoneNumberInDresdenGermany_ReturnsGermany() { MockRepository mocks = new MockRepository(); IPhoneNumberDataXml xmlDataProvider = mocks.Stub <IPhoneNumberDataXml>(); IPhoneNumberDataRegistry registryDataProvider = mocks.Stub <IPhoneNumberDataRegistry>(); string number = "+493511234567"; string expected = "Deutschland"; using (mocks.Record()) { xmlDataProvider.GetCountryCode("4935"); LastCall.Return("49"); xmlDataProvider.GetAreaCode("+493511234567"); LastCall.Return("+49351"); xmlDataProvider.GetCountryID("+49351"); LastCall.Return("49"); registryDataProvider.GetCountryName(49); LastCall.Return(expected); } PhoneNumbers phoneNumberConverter = new PhoneNumbers(xmlDataProvider, registryDataProvider); string actual = phoneNumberConverter.GetCountryNameByNumber(number); Assert.AreEqual(expected, actual); }
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); }
private string GetCountryCode(string number) { if (String.IsNullOrEmpty(number)) { return(String.Empty); } if (Regex.IsMatch(number, PhoneNumberConstants.PHONE_NUMBER_PATTERN) == false) { return(String.Empty); } string result = ""; string code = ""; if (number.StartsWith("00")) { code = number.Substring(2, PhoneNumberConstants.MAX_COUNTRYCODE_LENGTH); } else if (number.StartsWith("+")) { code = number.Substring(1, PhoneNumberConstants.MAX_COUNTRYCODE_LENGTH); } else { return(GetUserCountryID()); } result = xmlDataProvider.GetCountryCode(code); return(result); }
public void FormatPhoneNumber_PhoneNumberInGermanInternationalFormatToCanonical_ReturnsCanonicalNumber() { MockRepository mocks = new MockRepository(); IPhoneNumberDataXml xmlDataProvider = mocks.Stub <IPhoneNumberDataXml>(); IPhoneNumberDataRegistry registryDataProvider = mocks.Stub <IPhoneNumberDataRegistry>(); string number = "00493511234567"; string expected = "+49 (351) 1234567"; using (mocks.Record()) { xmlDataProvider.GetCountryCode("4935"); LastCall.Return("49"); xmlDataProvider.GetAreaCode("+493511234567"); LastCall.Return("+49351"); } PhoneNumbers phoneNumberConverter = new PhoneNumbers(xmlDataProvider, registryDataProvider); string actual = phoneNumberConverter.FormatPhoneNumber(number, DISTANCE_RULE.CANONICAL); Assert.AreEqual(expected, actual); }
public void GetCountryID_PhoneNumberOfTMobileGermany_Returns49() { MockRepository mocks = new MockRepository(); IPhoneNumberDataXml xmlDataProvider = mocks.Stub <IPhoneNumberDataXml>(); IPhoneNumberDataRegistry registryDataProvider = mocks.Stub <IPhoneNumberDataRegistry>(); string number = "+491511123456"; string expected = "49"; using (mocks.Record()) { xmlDataProvider.GetCountryCode("4915"); LastCall.Return("49"); xmlDataProvider.GetAreaCode("+491511123456"); LastCall.Return("+491511"); xmlDataProvider.GetCountryID("+491511"); LastCall.Return(expected); } PhoneNumbers phoneNumberConverter = new PhoneNumbers(xmlDataProvider, registryDataProvider); string actual = phoneNumberConverter.GetCountryID(number); Assert.AreEqual(expected, actual); }