diff --git a/csharp/PhoneNumbers.Test/TestMedataManager.cs b/csharp/PhoneNumbers.Test/TestMedataManager.cs index 50c6c4a1..18234dc1 100644 --- a/csharp/PhoneNumbers.Test/TestMedataManager.cs +++ b/csharp/PhoneNumbers.Test/TestMedataManager.cs @@ -60,6 +60,11 @@ public void TestAlternateFormatsFailsGracefully() /// // 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() diff --git a/csharp/PhoneNumbers.Test/TestPhonenumber.cs b/csharp/PhoneNumbers.Test/TestPhonenumber.cs index efd29e30..5798345f 100644 --- a/csharp/PhoneNumbers.Test/TestPhonenumber.cs +++ b/csharp/PhoneNumbers.Test/TestPhonenumber.cs @@ -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() { diff --git a/csharp/PhoneNumbers/Phonenumber.cs b/csharp/PhoneNumbers/Phonenumber.cs index df6b261b..9aee2de0 100644 --- a/csharp/PhoneNumbers/Phonenumber.cs +++ b/csharp/PhoneNumbers/Phonenumber.cs @@ -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;