Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions csharp/PhoneNumbers.Test/TestMedataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public void TestAlternateFormatsFailsGracefully()
/// </summary>
// IMetadataLoader/EmbeddedResourceMetadataLoader/SetMetadataLoader are Obsolete for external
// callers only; this test exercises them directly as this project's own internal API.
// The Obsolete message names no replacement — the member is slated to become internal, not
// to be superseded — so there is nothing for these calls to migrate to, and covering the
// deprecated entry point is exactly what the two tests below are for. CodeQL's
// cs/call-to-obsolete-method still reports them; dismiss those alerts rather than
// rewriting the tests away from the API under test.
#pragma warning disable CS0618
[Fact]
public void SetMetadataLoader_RoutesLookupsThroughCustomLoader()
Expand Down
17 changes: 17 additions & 0 deletions csharp/PhoneNumbers.Test/TestPhonenumber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,23 @@ public void TestNonEqualWithItalianLeadingZeroSetToTrue()
Assert.False(numberA.GetHashCode() == numberB.GetHashCode());
}

[Fact]
public void TestItalianLeadingZeroSetterWritesNumberOfLeadingZeros()
{
// Exercises the obsolete ItalianLeadingZero property setter itself, not
// SetNumberOfLeadingZeros directly, since that setter is what delegates to
// SetNumberOfLeadingZeros(value ? 1 : 0) under the hood.
#pragma warning disable CS0618 // intentionally exercising the obsolete setter
var builder = new PhoneNumber.Builder()
.SetCountryCode(1).SetNationalNumber(6502530000L);
builder.ItalianLeadingZero = true;
Assert.Equal(1, builder.NumberOfLeadingZeros);

builder.ItalianLeadingZero = false;
Assert.Equal(0, builder.NumberOfLeadingZeros);
#pragma warning restore CS0618
}

[Fact]
public void TestNonEqualWithDifferingRawInput()
{
Expand Down
5 changes: 4 additions & 1 deletion csharp/PhoneNumbers/Phonenumber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ public string Extension
public bool ItalianLeadingZero
{
get => MessageBeingBuilt.ItalianLeadingZero;
set => SetItalianLeadingZero(value);
// Goes straight to the replacement rather than through the equally-obsolete
// SetItalianLeadingZero: that method is nothing but
// SetNumberOfLeadingZeros(value ? 1 : 0), so this is the same write.
set => SetNumberOfLeadingZeros(value ? 1 : 0);
}

public bool HasNumberOfLeadingZeros => MessageBeingBuilt.HasNumberOfLeadingZeros;
Expand Down