//Não vi outro modo de resolver sem ser com ifs.
 // State pattern, polimorfismo ou matching pattern do c# 9 não fazem sentido aqui
 public static string GetFormattedPhone(string phoneNumber)
 {
     if (PhoneValidator.IsPublicService(phoneNumber))
     {
         return(PublicServicePhoneFormatter.GetFormattedPhone(phoneNumber));
     }
     if (PhoneValidator.IsServiceProvider(phoneNumber))
     {
         return(PhoneFormatter.GetFormattedServiceProviderNumber(phoneNumber));
     }
     if (PhoneValidator.IsNotGeophicNumber(phoneNumber))
     {
         return(GetNotGeographicFormattedNumber(phoneNumber));
     }
     if (PhoneValidator.IsResidentialNumber(phoneNumber))
     {
         return(GetResidentialFormattedNumber(phoneNumber));
     }
     if (PhoneValidator.IsMobileNumber(phoneNumber))
     {
         return(GetMobileFormattedNumber(phoneNumber));
     }
     return("Número de telefone não identificado: " + phoneNumber);
 }
Ejemplo n.º 2
0
        public static void ShouldNotBeServiceProviderNumber(string phoneNumber)
        {
            var isServiceProvider = PhoneValidator.IsServiceProvider(phoneNumber);

            Assert.False(isServiceProvider);
        }