private List <Message> GetValidMessages(List <Message> messages)
        {
            List <Message> results = new List <Message>();

            if (messages != null && messages.Any())
            {
                foreach (Message message in messages)
                {
                    if (message != null && String.IsNullOrEmpty(message.Text) && message.Numbers != null && message.Numbers.Any())
                    {
                        Message newMessage = new Message()
                        {
                            Text = message.Text
                        };

                        List <string> numbers = message.Numbers.Where(n => _phoneNumberValidator.IsValid(n)).ToList();

                        if (numbers.Any())
                        {
                            newMessage.Numbers = numbers;
                        }

                        results.Add(newMessage);
                    }
                }
            }

            return(results);
        }
Exemplo n.º 2
0
 private void ValidatePhoneNumber(string phoneNumber)
 {
     if (!_phoneNumberValidator.IsValid(phoneNumber))
     {
         throw new InvalidPhoneNumberException();
     }
 }
Exemplo n.º 3
0
        public Customer Create(string name, string phoneNumber)
        {
            if (!_phoneNumberValidator.IsValid(phoneNumber))
            {
                throw new ArgumentException("Phone number is invalid");
            }

            var customer = new Customer(name, phoneNumber);

            _customers.Add(customer.Id, customer);
            return(customer);
        }