From 43e3b60d7b9ccd887efa4fa38693ed9398506bf4 Mon Sep 17 00:00:00 2001 From: Trevor Pilley Date: Mon, 9 Dec 2024 15:33:22 +0000 Subject: [PATCH] Code Butler clean up --- codebutler.sh | 13 ++ src/PhoneNumbers/CountryInfo.cs | 54 +++---- test/PhoneNumbers.Tests/CountryInfoTests.cs | 48 +++--- .../SimplePhoneNumberFormatProviderTests.cs | 112 ++++++------- ...ryNumbers_With_NationalDestinationCodes.cs | 2 +- ...NumberParserTests_GeographicPhoneNumber.cs | 152 +++++++++--------- .../PhoneNumberExtensionsTests.cs | 14 +- 7 files changed, 204 insertions(+), 191 deletions(-) create mode 100644 codebutler.sh diff --git a/codebutler.sh b/codebutler.sh new file mode 100644 index 000000000..4f06ca6b4 --- /dev/null +++ b/codebutler.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +dotnet tool update --global code-butler + +find ./src/PhoneNumbers/ -type f -name '*.cs' | while read fname; +do + dotnet-code-butler "$fname" +done + +find ./test/PhoneNumbers.Tests/ -type f -name '*.cs' | while read fname; +do + dotnet-code-butler "$fname" +done diff --git a/src/PhoneNumbers/CountryInfo.cs b/src/PhoneNumbers/CountryInfo.cs index 2b07e4b45..5dc4c17c2 100644 --- a/src/PhoneNumbers/CountryInfo.cs +++ b/src/PhoneNumbers/CountryInfo.cs @@ -84,15 +84,15 @@ internal CountryInfo() public bool IsNatoMember { get; init; } /// - /// Gets the ISO 3166 Alpha-2 code for the country. + /// Gets a value indicating whether the country is a member of the Organisation for Economic Co-operation and Development. /// - /// See https://www.iso.org/iso-3166-country-codes.html - public required string Iso3166Code { get; init; } = null!; + public bool IsOecdMember { get; init; } /// - /// Gets a value indicating whether the country is a member of the Organisation for Economic Co-operation and Development. + /// Gets the ISO 3166 Alpha-2 code for the country. /// - public bool IsOecdMember { get; init; } + /// See https://www.iso.org/iso-3166-country-codes.html + public required string Iso3166Code { get; init; } = null!; /// /// Gets the name of the country in English. @@ -159,25 +159,6 @@ internal CountryInfo() return countryInfo1.Equals(countryInfo2); } - internal static IEnumerable GetCountries() => - typeof(CountryInfo) - .GetProperties(BindingFlags.Public | BindingFlags.Static) - .Where(x => x.PropertyType == typeof(CountryInfo)) - .Select(x => x.GetValue(null)) - .Cast(); - - internal static IEnumerable GetCountries(Func predicate) => - GetCountries() - .Where(predicate); - - /// - /// Gets the for the specified format. - /// - /// Thrown if the format string is not valid. - /// The . - internal static PhoneNumberFormatter GetFormatter(string format) => - s_formatters.SingleOrDefault(x => x.CanFormat(format)) ?? throw new FormatException($"{format} is not a supported format"); - /// public override bool Equals(object? obj) => Equals(obj as CountryInfo); @@ -203,6 +184,25 @@ public bool Equals(CountryInfo? other) public override int GetHashCode() => HashCode.Combine(Iso3166Code); + internal static IEnumerable GetCountries() => + typeof(CountryInfo) + .GetProperties(BindingFlags.Public | BindingFlags.Static) + .Where(x => x.PropertyType == typeof(CountryInfo)) + .Select(x => x.GetValue(null)) + .Cast(); + + internal static IEnumerable GetCountries(Func predicate) => + GetCountries() + .Where(predicate); + + /// + /// Gets the for the specified format. + /// + /// Thrown if the format string is not valid. + /// The . + internal static PhoneNumberFormatter GetFormatter(string format) => + s_formatters.SingleOrDefault(x => x.CanFormat(format)) ?? throw new FormatException($"{format} is not a supported format"); + /// /// Gets a value indicating whether the specified value has the calling code for this country. /// @@ -262,13 +262,13 @@ internal string ReadNationalSignificantNumber(string value) internal bool SharesCallingCodeWith(CountryInfo countryInfo) => CallingCode.Equals(countryInfo.CallingCode, StringComparison.Ordinal); + private static bool IsDelimiter(char charVal) => + charVal == Chars.Comma || charVal == Chars.Semicolon; + /// Char.IsDigit returns true for more than 0-9 so use a more restricted version. private static bool IsDigit(char charVal) => charVal is >= '0' and <= '9'; - private static bool IsDelimiter(char charVal) => - charVal == Chars.Comma || charVal == Chars.Semicolon; - private static bool IsSeparator(char charVal) => charVal == Chars.Hyphen || charVal == Chars.ForwardSlash; diff --git a/test/PhoneNumbers.Tests/CountryInfoTests.cs b/test/PhoneNumbers.Tests/CountryInfoTests.cs index e810688a6..42c2ff018 100644 --- a/test/PhoneNumbers.Tests/CountryInfoTests.cs +++ b/test/PhoneNumbers.Tests/CountryInfoTests.cs @@ -4,29 +4,6 @@ namespace PhoneNumbers.Tests; public class CountryInfoTests { - [Fact] - public void GetFormatter_E123_Returns_E123PhoneNumberFormatter() => - Assert.IsType(CountryInfo.GetFormatter("E.123")); - - [Fact] - public void GetFormatter_E164_Returns_E164PhoneNumberFormatter() => - Assert.IsType(CountryInfo.GetFormatter("E.164")); - - [Fact] - public void GetFormatter_N_Returns_NationalPhoneNumberFormatter() => - Assert.IsType(CountryInfo.GetFormatter("N")); - - [Fact] - public void GetFormatter_RFC3966_Returns_Rfc3966PhoneNumberFormatter() => - Assert.IsType(CountryInfo.GetFormatter("RFC3966")); - - [Fact] - public void GetFormatter_U_Returns_NationalUnformattedPhoneNumberFormatter() => - Assert.IsType(CountryInfo.GetFormatter("U")); - - [Fact] - public void GetFormatter_Throws_For_Invalid_Format() => - Assert.Throws(() => CountryInfo.GetFormatter("X")); [Fact] public void Equality_Both_Null() @@ -81,6 +58,29 @@ public void Equality_Same_Iso3166Code() Assert.True(countryInfo1 == countryInfo2); Assert.False(countryInfo1 != countryInfo2); } + [Fact] + public void GetFormatter_E123_Returns_E123PhoneNumberFormatter() => + Assert.IsType(CountryInfo.GetFormatter("E.123")); + + [Fact] + public void GetFormatter_E164_Returns_E164PhoneNumberFormatter() => + Assert.IsType(CountryInfo.GetFormatter("E.164")); + + [Fact] + public void GetFormatter_N_Returns_NationalPhoneNumberFormatter() => + Assert.IsType(CountryInfo.GetFormatter("N")); + + [Fact] + public void GetFormatter_RFC3966_Returns_Rfc3966PhoneNumberFormatter() => + Assert.IsType(CountryInfo.GetFormatter("RFC3966")); + + [Fact] + public void GetFormatter_Throws_For_Invalid_Format() => + Assert.Throws(() => CountryInfo.GetFormatter("X")); + + [Fact] + public void GetFormatter_U_Returns_NationalUnformattedPhoneNumberFormatter() => + Assert.IsType(CountryInfo.GetFormatter("U")); [Theory] [InlineData(default(string))] @@ -270,7 +270,7 @@ public void ShareCallingCodeWith() Assert.True(CountryInfo.UnitedKingdom.SharesCallingCodeWith(CountryInfo.IsleOfMan)); Assert.True(CountryInfo.UnitedKingdom.SharesCallingCodeWith(CountryInfo.Jersey)); } - + [Fact] public void When_Constructed() { diff --git a/test/PhoneNumbers.Tests/Formatters/FormatProviders/SimplePhoneNumberFormatProviderTests.cs b/test/PhoneNumbers.Tests/Formatters/FormatProviders/SimplePhoneNumberFormatProviderTests.cs index 520c57fc9..7bf1b619a 100644 --- a/test/PhoneNumbers.Tests/Formatters/FormatProviders/SimplePhoneNumberFormatProviderTests.cs +++ b/test/PhoneNumbers.Tests/Formatters/FormatProviders/SimplePhoneNumberFormatProviderTests.cs @@ -114,62 +114,6 @@ public void GetFormat_National_No_TrunkPrefix_With_Ndc(string ndc, string sn, st SimplePhoneNumberFormatProvider.Default.GetFormat( TestHelper.CreateNonGeographicPhoneNumber(null, ndc, sn), false)); - [Theory] - [InlineData("0", "1234", "0####")] - [InlineData("0", "12345", "0#####")] - [InlineData("0", "123456", "0######")] - [InlineData("0", "1234567", "0#######")] - [InlineData("0", "12345678", "0########")] - [InlineData("0", "123456789", "0#########")] - [InlineData("0", "1234567890", "0##########")] - public void GetFormat_National_With_TrunkPrefix_No_Ndc(string trunkPrefix, string sn, string expectedMask) => - Assert.Equal( - expectedMask, - SimplePhoneNumberFormatProvider.Default.GetFormat( - TestHelper.CreateNonGeographicPhoneNumber(trunkPrefix, null, sn), false)); - - [Theory] - [InlineData("0", "1", "1234", "0# ####")] - [InlineData("0", "1", "12345", "0# #####")] - [InlineData("0", "1", "123456", "0# ######")] - [InlineData("0", "1", "1234567", "0# #######")] - [InlineData("0", "1", "12345678", "0# ########")] - [InlineData("0", "1", "123456789", "0# #########")] - [InlineData("0", "1", "1234567890", "0# ##########")] - [InlineData("0", "12", "1234", "0## ####")] - [InlineData("0", "12", "12345", "0## #####")] - [InlineData("0", "12", "123456", "0## ######")] - [InlineData("0", "12", "1234567", "0## #######")] - [InlineData("0", "12", "12345678", "0## ########")] - [InlineData("0", "12", "123456789", "0## #########")] - [InlineData("0", "12", "1234567890", "0## ##########")] - [InlineData("0", "123", "1234", "0### ####")] - [InlineData("0", "123", "12345", "0### #####")] - [InlineData("0", "123", "123456", "0### ######")] - [InlineData("0", "123", "1234567", "0### #######")] - [InlineData("0", "123", "12345678", "0### ########")] - [InlineData("0", "123", "123456789", "0### #########")] - [InlineData("0", "123", "1234567890", "0### ##########")] - [InlineData("0", "1234", "1234", "0#### ####")] - [InlineData("0", "1234", "12345", "0#### #####")] - [InlineData("0", "1234", "123456", "0#### ######")] - [InlineData("0", "1234", "1234567", "0#### #######")] - [InlineData("0", "1234", "12345678", "0#### ########")] - [InlineData("0", "1234", "123456789", "0#### #########")] - [InlineData("0", "1234", "1234567890", "0#### ##########")] - [InlineData("0", "12345", "1234", "0##### ####")] - [InlineData("0", "12345", "12345", "0##### #####")] - [InlineData("0", "12345", "123456", "0##### ######")] - [InlineData("0", "12345", "1234567", "0##### #######")] - [InlineData("0", "12345", "12345678", "0##### ########")] - [InlineData("0", "12345", "123456789", "0##### #########")] - [InlineData("0", "12345", "1234567890", "0##### ##########")] - public void GetFormat_National_With_TrunkPrefix_With_Ndc(string trunkPrefix, string ndc, string sn, string expectedMask) => - Assert.Equal( - expectedMask, - SimplePhoneNumberFormatProvider.Default.GetFormat( - TestHelper.CreateNonGeographicPhoneNumber(trunkPrefix, ndc, sn), false)); - [Theory] [InlineData("1", "1234", "(#) ####")] [InlineData("1", "12345", "(#) #####")] @@ -254,6 +198,62 @@ public void GetFormat_National_No_TrunkPrefix_With_Ndc_Required(string ndc, stri SimplePhoneNumberFormatProvider.Default.GetFormat( TestHelper.CreateNonGeographicPhoneNumber(null, ndc, sn, true), false)); + [Theory] + [InlineData("0", "1234", "0####")] + [InlineData("0", "12345", "0#####")] + [InlineData("0", "123456", "0######")] + [InlineData("0", "1234567", "0#######")] + [InlineData("0", "12345678", "0########")] + [InlineData("0", "123456789", "0#########")] + [InlineData("0", "1234567890", "0##########")] + public void GetFormat_National_With_TrunkPrefix_No_Ndc(string trunkPrefix, string sn, string expectedMask) => + Assert.Equal( + expectedMask, + SimplePhoneNumberFormatProvider.Default.GetFormat( + TestHelper.CreateNonGeographicPhoneNumber(trunkPrefix, null, sn), false)); + + [Theory] + [InlineData("0", "1", "1234", "0# ####")] + [InlineData("0", "1", "12345", "0# #####")] + [InlineData("0", "1", "123456", "0# ######")] + [InlineData("0", "1", "1234567", "0# #######")] + [InlineData("0", "1", "12345678", "0# ########")] + [InlineData("0", "1", "123456789", "0# #########")] + [InlineData("0", "1", "1234567890", "0# ##########")] + [InlineData("0", "12", "1234", "0## ####")] + [InlineData("0", "12", "12345", "0## #####")] + [InlineData("0", "12", "123456", "0## ######")] + [InlineData("0", "12", "1234567", "0## #######")] + [InlineData("0", "12", "12345678", "0## ########")] + [InlineData("0", "12", "123456789", "0## #########")] + [InlineData("0", "12", "1234567890", "0## ##########")] + [InlineData("0", "123", "1234", "0### ####")] + [InlineData("0", "123", "12345", "0### #####")] + [InlineData("0", "123", "123456", "0### ######")] + [InlineData("0", "123", "1234567", "0### #######")] + [InlineData("0", "123", "12345678", "0### ########")] + [InlineData("0", "123", "123456789", "0### #########")] + [InlineData("0", "123", "1234567890", "0### ##########")] + [InlineData("0", "1234", "1234", "0#### ####")] + [InlineData("0", "1234", "12345", "0#### #####")] + [InlineData("0", "1234", "123456", "0#### ######")] + [InlineData("0", "1234", "1234567", "0#### #######")] + [InlineData("0", "1234", "12345678", "0#### ########")] + [InlineData("0", "1234", "123456789", "0#### #########")] + [InlineData("0", "1234", "1234567890", "0#### ##########")] + [InlineData("0", "12345", "1234", "0##### ####")] + [InlineData("0", "12345", "12345", "0##### #####")] + [InlineData("0", "12345", "123456", "0##### ######")] + [InlineData("0", "12345", "1234567", "0##### #######")] + [InlineData("0", "12345", "12345678", "0##### ########")] + [InlineData("0", "12345", "123456789", "0##### #########")] + [InlineData("0", "12345", "1234567890", "0##### ##########")] + public void GetFormat_National_With_TrunkPrefix_With_Ndc(string trunkPrefix, string ndc, string sn, string expectedMask) => + Assert.Equal( + expectedMask, + SimplePhoneNumberFormatProvider.Default.GetFormat( + TestHelper.CreateNonGeographicPhoneNumber(trunkPrefix, ndc, sn), false)); + [Theory] [InlineData("0", "1", "1234", "(0#) ####")] [InlineData("0", "1", "12345", "(0#) #####")] diff --git a/test/PhoneNumbers.Tests/Parsers/DefaultPhoneNumberParserTests_CountryNumbers_With_NationalDestinationCodes.cs b/test/PhoneNumbers.Tests/Parsers/DefaultPhoneNumberParserTests_CountryNumbers_With_NationalDestinationCodes.cs index 11c84e02c..088b48105 100644 --- a/test/PhoneNumbers.Tests/Parsers/DefaultPhoneNumberParserTests_CountryNumbers_With_NationalDestinationCodes.cs +++ b/test/PhoneNumbers.Tests/Parsers/DefaultPhoneNumberParserTests_CountryNumbers_With_NationalDestinationCodes.cs @@ -261,7 +261,7 @@ public void Parse_NonGeographicPhoneNumber_SharedCost() Assert.Equal("28000", nonGeographicPhoneNumber.SubscriberNumber); Assert.Equal(PhoneNumberKind.NonGeographicPhoneNumber, nonGeographicPhoneNumber.Kind); } - + [Fact] // This scenario exists within Germany public void Parse_When_Nsn_Shorter_Than_Some_Ndc_Lengths() { diff --git a/test/PhoneNumbers.Tests/Parsers/GBPhoneNumberParserTests_GeographicPhoneNumber.cs b/test/PhoneNumbers.Tests/Parsers/GBPhoneNumberParserTests_GeographicPhoneNumber.cs index 901e5b746..e900e8203 100644 --- a/test/PhoneNumbers.Tests/Parsers/GBPhoneNumberParserTests_GeographicPhoneNumber.cs +++ b/test/PhoneNumbers.Tests/Parsers/GBPhoneNumberParserTests_GeographicPhoneNumber.cs @@ -8,55 +8,33 @@ public class GBPhoneNumberParserTests_GeographicPhoneNumber private static readonly PhoneNumberParser s_parser = GBPhoneNumberParser.Create(); [Theory] - [InlineData("01132000000", "113", "2000000", "Leeds")] - [InlineData("01135999999", "113", "5999999", "Leeds")] - [InlineData("01137000000", "113", "7000000", "Leeds")] - [InlineData("01138999999", "113", "8999999", "Leeds")] - [InlineData("01142000000", "114", "2000000", "Sheffield")] - [InlineData("01147999999", "114", "7999999", "Sheffield")] - [InlineData("01152000000", "115", "2000000", "Nottingham")] - [InlineData("01152999999", "115", "2999999", "Nottingham")] - [InlineData("01156000000", "115", "6000000", "Nottingham")] - [InlineData("01159989999", "115", "9989999", "Nottingham")] - [InlineData("01162000000", "116", "2000000", "Leicester")] - [InlineData("01164999999", "116", "4999999", "Leicester")] - [InlineData("01172000000", "117", "2000000", "Bristol")] - [InlineData("01174999999", "117", "4999999", "Bristol")] - [InlineData("01179000000", "117", "9000000", "Bristol")] - [InlineData("01179989999", "117", "9989999", "Bristol")] - [InlineData("01182000000", "118", "2000000", "Reading")] - [InlineData("01184999999", "118", "4999999", "Reading")] - [InlineData("01189000000", "118", "9000000", "Reading")] - [InlineData("01189989999", "118", "9989999", "Reading")] - [InlineData("01212000000", "121", "2000000", "Birmingham")] - [InlineData("01217999999", "121", "7999999", "Birmingham")] - [InlineData("01312000000", "131", "2000000", "Edinburgh")] - [InlineData("01317999999", "131", "7999999", "Edinburgh")] - [InlineData("01412000000", "141", "2000000", "Glasgow")] - [InlineData("01419989999", "141", "9989999", "Glasgow")] - [InlineData("01512000000", "151", "2000000", "Liverpool")] - [InlineData("01519989999", "151", "9989999", "Liverpool")] - [InlineData("01612000000", "161", "2000000", "Manchester")] - [InlineData("01614999999", "161", "4999999", "Manchester")] - [InlineData("01616000000", "161", "6000000", "Manchester")] - [InlineData("01619989999", "161", "9989999", "Manchester")] - [InlineData("01912000000", "191", "2000000", "Tyneside")] - [InlineData("01912999999", "191", "2999999", "Tyneside")] - [InlineData("01913000000", "191", "3000000", "Durham")] - [InlineData("01913999999", "191", "3999999", "Durham")] - [InlineData("01914000000", "191", "4000000", "Tyneside")] - [InlineData("01914999999", "191", "4999999", "Tyneside")] - [InlineData("01915000000", "191", "5000000", "Sunderland")] - [InlineData("01915999999", "191", "5999999", "Sunderland")] - [InlineData("01916000000", "191", "6000000", "Tyneside")] - [InlineData("01916999999", "191", "6999999", "Tyneside")] - [InlineData("01917000000", "191", "7000000", "Sunderland")] - [InlineData("01917999999", "191", "7999999", "Sunderland")] - [InlineData("01918000000", "191", "8000000", "Tyneside")] - [InlineData("01918999999", "191", "8999999", "Tyneside")] - [InlineData("01919000000", "191", "9000000", "Durham")] - [InlineData("01919989999", "191", "9989999", "Durham")] - public void Parse_Known_GeographicPhoneNumber_1XX_NationalDestinationCode(string value, string NationalDestinationCode, string subscriberNumber, string geographicArea) + [InlineData("01387320000", "13873", "20000", "Langholm")] + [InlineData("01387399899", "13873", "99899", "Langholm")] + [InlineData("01524220000", "15242", "20000", "Hornby")] + [InlineData("01524299899", "15242", "99899", "Hornby")] + [InlineData("01539420000", "15394", "20000", "Hawkshead")] + [InlineData("01539499899", "15394", "99899", "Hawkshead")] + [InlineData("01539520000", "15395", "20000", "Grange-Over-Sands")] + [InlineData("01539599899", "15395", "99899", "Grange-Over-Sands")] + [InlineData("01539620000", "15396", "20000", "Sedbergh")] + [InlineData("01539699899", "15396", "99899", "Sedbergh")] + [InlineData("01697320000", "16973", "20000", "Wigton")] + [InlineData("01697399899", "16973", "99899", "Wigton")] + [InlineData("01697420000", "16974", "20000", "Raughton Head")] + [InlineData("01697499899", "16974", "99899", "Raughton Head")] + [InlineData("0169772000", "16977", "2000", "Brampton")] + [InlineData("0169773999", "16977", "3999", "Brampton")] + [InlineData("01697740000", "16977", "40000", "Brampton")] + [InlineData("01697798999", "16977", "98999", "Brampton")] + [InlineData("01768320000", "17683", "20000", "Appleby")] + [InlineData("01768399899", "17683", "99899", "Appleby")] + [InlineData("01768420000", "17684", "20000", "Pooley Bridge")] + [InlineData("01768499899", "17684", "99899", "Pooley Bridge")] + [InlineData("01768720000", "17687", "20000", "Keswick")] + [InlineData("01768799899", "17687", "99899", "Keswick")] + [InlineData("01946720000", "19467", "20000", "Gosforth")] + [InlineData("01946799899", "19467", "99899", "Gosforth")] + public void Parse_Known_GeographicPhoneNumber_1XXXX_NationalDestinationCode(string value, string NationalDestinationCode, string subscriberNumber, string geographicArea) { var parseResult = s_parser.Parse(value); parseResult.ThrowIfFailure(); @@ -1524,33 +1502,55 @@ public void Parse_Known_GeographicPhoneNumber_1XXX_NationalDestinationCode(strin } [Theory] - [InlineData("01387320000", "13873", "20000", "Langholm")] - [InlineData("01387399899", "13873", "99899", "Langholm")] - [InlineData("01524220000", "15242", "20000", "Hornby")] - [InlineData("01524299899", "15242", "99899", "Hornby")] - [InlineData("01539420000", "15394", "20000", "Hawkshead")] - [InlineData("01539499899", "15394", "99899", "Hawkshead")] - [InlineData("01539520000", "15395", "20000", "Grange-Over-Sands")] - [InlineData("01539599899", "15395", "99899", "Grange-Over-Sands")] - [InlineData("01539620000", "15396", "20000", "Sedbergh")] - [InlineData("01539699899", "15396", "99899", "Sedbergh")] - [InlineData("01697320000", "16973", "20000", "Wigton")] - [InlineData("01697399899", "16973", "99899", "Wigton")] - [InlineData("01697420000", "16974", "20000", "Raughton Head")] - [InlineData("01697499899", "16974", "99899", "Raughton Head")] - [InlineData("0169772000", "16977", "2000", "Brampton")] - [InlineData("0169773999", "16977", "3999", "Brampton")] - [InlineData("01697740000", "16977", "40000", "Brampton")] - [InlineData("01697798999", "16977", "98999", "Brampton")] - [InlineData("01768320000", "17683", "20000", "Appleby")] - [InlineData("01768399899", "17683", "99899", "Appleby")] - [InlineData("01768420000", "17684", "20000", "Pooley Bridge")] - [InlineData("01768499899", "17684", "99899", "Pooley Bridge")] - [InlineData("01768720000", "17687", "20000", "Keswick")] - [InlineData("01768799899", "17687", "99899", "Keswick")] - [InlineData("01946720000", "19467", "20000", "Gosforth")] - [InlineData("01946799899", "19467", "99899", "Gosforth")] - public void Parse_Known_GeographicPhoneNumber_1XXXX_NationalDestinationCode(string value, string NationalDestinationCode, string subscriberNumber, string geographicArea) + [InlineData("01132000000", "113", "2000000", "Leeds")] + [InlineData("01135999999", "113", "5999999", "Leeds")] + [InlineData("01137000000", "113", "7000000", "Leeds")] + [InlineData("01138999999", "113", "8999999", "Leeds")] + [InlineData("01142000000", "114", "2000000", "Sheffield")] + [InlineData("01147999999", "114", "7999999", "Sheffield")] + [InlineData("01152000000", "115", "2000000", "Nottingham")] + [InlineData("01152999999", "115", "2999999", "Nottingham")] + [InlineData("01156000000", "115", "6000000", "Nottingham")] + [InlineData("01159989999", "115", "9989999", "Nottingham")] + [InlineData("01162000000", "116", "2000000", "Leicester")] + [InlineData("01164999999", "116", "4999999", "Leicester")] + [InlineData("01172000000", "117", "2000000", "Bristol")] + [InlineData("01174999999", "117", "4999999", "Bristol")] + [InlineData("01179000000", "117", "9000000", "Bristol")] + [InlineData("01179989999", "117", "9989999", "Bristol")] + [InlineData("01182000000", "118", "2000000", "Reading")] + [InlineData("01184999999", "118", "4999999", "Reading")] + [InlineData("01189000000", "118", "9000000", "Reading")] + [InlineData("01189989999", "118", "9989999", "Reading")] + [InlineData("01212000000", "121", "2000000", "Birmingham")] + [InlineData("01217999999", "121", "7999999", "Birmingham")] + [InlineData("01312000000", "131", "2000000", "Edinburgh")] + [InlineData("01317999999", "131", "7999999", "Edinburgh")] + [InlineData("01412000000", "141", "2000000", "Glasgow")] + [InlineData("01419989999", "141", "9989999", "Glasgow")] + [InlineData("01512000000", "151", "2000000", "Liverpool")] + [InlineData("01519989999", "151", "9989999", "Liverpool")] + [InlineData("01612000000", "161", "2000000", "Manchester")] + [InlineData("01614999999", "161", "4999999", "Manchester")] + [InlineData("01616000000", "161", "6000000", "Manchester")] + [InlineData("01619989999", "161", "9989999", "Manchester")] + [InlineData("01912000000", "191", "2000000", "Tyneside")] + [InlineData("01912999999", "191", "2999999", "Tyneside")] + [InlineData("01913000000", "191", "3000000", "Durham")] + [InlineData("01913999999", "191", "3999999", "Durham")] + [InlineData("01914000000", "191", "4000000", "Tyneside")] + [InlineData("01914999999", "191", "4999999", "Tyneside")] + [InlineData("01915000000", "191", "5000000", "Sunderland")] + [InlineData("01915999999", "191", "5999999", "Sunderland")] + [InlineData("01916000000", "191", "6000000", "Tyneside")] + [InlineData("01916999999", "191", "6999999", "Tyneside")] + [InlineData("01917000000", "191", "7000000", "Sunderland")] + [InlineData("01917999999", "191", "7999999", "Sunderland")] + [InlineData("01918000000", "191", "8000000", "Tyneside")] + [InlineData("01918999999", "191", "8999999", "Tyneside")] + [InlineData("01919000000", "191", "9000000", "Durham")] + [InlineData("01919989999", "191", "9989999", "Durham")] + public void Parse_Known_GeographicPhoneNumber_1XX_NationalDestinationCode(string value, string NationalDestinationCode, string subscriberNumber, string geographicArea) { var parseResult = s_parser.Parse(value); parseResult.ThrowIfFailure(); diff --git a/test/PhoneNumbers.Tests/PhoneNumberExtensionsTests.cs b/test/PhoneNumbers.Tests/PhoneNumberExtensionsTests.cs index 28a6baf99..ed56b2932 100644 --- a/test/PhoneNumbers.Tests/PhoneNumberExtensionsTests.cs +++ b/test/PhoneNumbers.Tests/PhoneNumberExtensionsTests.cs @@ -48,13 +48,6 @@ public void NumberToDialFrom_CountryInfo_Throws_If_CountryInfo_Null() public void NumberToDialFrom_CountryInfo_Throws_If_PhoneNumber_Null() => Assert.Throws(() => default(PhoneNumber).NumberToDialFrom(CountryInfo.UnitedKingdom)); - [Fact] - public void NumberToDialFrom_PhoneNumber_Throws_If_CountryInfo_Null() - { - Assert.Throws(() => default(PhoneNumber).NumberToDialFrom(TestHelper.CreateMobilePhoneNumber(null, "1", "123"))); - Assert.Throws(() => TestHelper.CreateMobilePhoneNumber(null, "1", "123").NumberToDialFrom(default(PhoneNumber))); - } - [Theory] [InlineData("+441142726444", "+441146548866", "6548866")] // UK Geo to Geo within NDC, local dialling permitted, NDC not required [InlineData("+441202454877", "+441202653887", "01202653887")] // UK Geo to Geo within NDC, local dialling permitted, NDC required for local dialling due to number shortages @@ -88,4 +81,11 @@ public void NumberToDialFrom_PhoneNumber(string source, string destination, stri Assert.Equal( expected, PhoneNumber.Parse(destination).NumberToDialFrom(PhoneNumber.Parse(source))); + + [Fact] + public void NumberToDialFrom_PhoneNumber_Throws_If_CountryInfo_Null() + { + Assert.Throws(() => default(PhoneNumber).NumberToDialFrom(TestHelper.CreateMobilePhoneNumber(null, "1", "123"))); + Assert.Throws(() => TestHelper.CreateMobilePhoneNumber(null, "1", "123").NumberToDialFrom(default(PhoneNumber))); + } }