Beispiel #1
0
        public SendSmsValidator(CountryService countryService)
        {
            _countryService = countryService;

            RuleFor(x => x.From).NotEmpty();
            RuleFor(x => x.Text).NotEmpty();
            RuleFor(x => x.To).NotEmpty();

            RuleFor(x => x.To)
            .Must(phoneNumber => ValidatePhoneNumber(phoneNumber) == true)
            .When(x => !string.IsNullOrEmpty(x.To))
            .WithMessage("Phone number not valid")
            .WithErrorCode("Invalid number");

            RuleFor(x => x.To)
            .Must(to => _countryService.CheckCountrySupport(to) == true)
            .When(x => ValidatePhoneNumber(x.To) == true)
            .WithMessage("Mcc not currently supported")
            .WithErrorCode("Unsupported Mcc");
        }