コード例 #1
0
 //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);
 }
コード例 #2
0
        public static void ShouldGetPublicServicePhoneFormatted()
        {
            string result = PublicServicePhoneFormatter.GetFormattedPhone("190");

            Assert.Equal("SUP: 190", result);
        }