-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
12 changed files
with
199 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/PhoneNumbers/Formatters/NationalUnformattedPhoneNumberFormatter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
namespace PhoneNumbers.Formatters; | ||
|
||
/// <summary> | ||
/// A <see cref="PhoneNumberFormatter"/> which returns the phone number in national notation without any formatting. | ||
/// </summary> | ||
internal sealed class NationalUnformattedPhoneNumberFormatter : PhoneNumberFormatter | ||
{ | ||
/// <summary> | ||
/// Initialises a new instance of the <see cref="NationalUnformattedPhoneNumberFormatter"/> class. | ||
/// </summary> | ||
private NationalUnformattedPhoneNumberFormatter() | ||
: base("U") | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Gets the <see cref="NationalUnformattedPhoneNumberFormatter"/> instance. | ||
/// </summary> | ||
internal static PhoneNumberFormatter Instance { get; } = new NationalUnformattedPhoneNumberFormatter(); | ||
|
||
/// <inheritdoc/> | ||
internal override string Format(PhoneNumber phoneNumber) => | ||
phoneNumber.Country.HasTrunkPrefix | ||
? $"{phoneNumber.Country.TrunkPrefix}{phoneNumber.NationalSignificantNumber}" | ||
: phoneNumber.NationalSignificantNumber; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
test/PhoneNumbers.Tests/Formatters/NationalUnformattedPhoneNumberFormatterTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using PhoneNumbers.Formatters; | ||
|
||
namespace PhoneNumbers.Tests.Formatters; | ||
|
||
/// <summary> | ||
/// Contains unit tests for the <see cref="NationalUnformattedPhoneNumberFormatter"/> class. | ||
/// </summary> | ||
public class NationalUnformattedPhoneNumberFormatterTests | ||
{ | ||
[Fact] | ||
public void CanFormat_Returns_False_For_Not_U() => | ||
Assert.False(NationalUnformattedPhoneNumberFormatter.Instance.CanFormat("E.164")); | ||
|
||
[Fact] | ||
public void CanFormat_Returns_False_For_Null() => | ||
Assert.False(NationalUnformattedPhoneNumberFormatter.Instance.CanFormat(null)); | ||
|
||
[Fact] | ||
public void CanFormat_Returns_True_For_U() => | ||
Assert.True(NationalUnformattedPhoneNumberFormatter.Instance.CanFormat("U")); | ||
|
||
[Fact] | ||
public void Instance() | ||
{ | ||
Assert.NotNull(NationalUnformattedPhoneNumberFormatter.Instance); | ||
Assert.Same(NationalUnformattedPhoneNumberFormatter.Instance, NationalUnformattedPhoneNumberFormatter.Instance); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.