//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); }
public static void ShouldNotBeMobileNumber(string phoneNumber) { var isMobileNumber = PhoneValidator.IsMobileNumber(phoneNumber); Assert.False(isMobileNumber); }