public void op_Validate_Telephone(string telephone,
                                          bool expected)
        {
            var actual = BritishTelephoneNumberLength.Validate(telephone);

            Assert.Equal(expected, actual);
        }
Пример #2
0
        private BritishTelephoneNumberPlanItem Item(Telephone telephone)
        {
            if (null == telephone)
            {
                throw new ArgumentNullException("telephone");
            }

            if (null == telephone.Number)
            {
                return(null);
            }

            if (telephone.Number.StartsWithAny(StringComparison.Ordinal, "+441", "+442"))
            {
                if (BritishTelephoneNumberLength.Validate(telephone))
                {
                    return(new[] { 5, 4, 3 }.Select(length => telephone.Number.Substring(3, length))
                           .Where(ContainsKey).Select(prefix => this[prefix])
                           .FirstOrDefault());
                }
            }

            if (telephone.Number.Length.IsNot(13))
            {
                return(null);
            }

            if (telephone.Number.StartsWith("+447", StringComparison.Ordinal))
            {
                var code = telephone.Number.Substring(3, 4);
                return(new BritishTelephoneNumberPlanItem
                {
                    AreaCode = code,
                    DialingCode = code,
                    Use = string.Empty
                });
            }

            return(null);
        }
 public void op_Validate_TelephoneNull()
 {
     Assert.Throws <ArgumentNullException>(() => BritishTelephoneNumberLength.Validate(null));
 }
        public void op_Validate_TelephoneEmpty()
        {
            Telephone telephone = string.Empty;

            Assert.Throws <ArgumentNullException>(() => BritishTelephoneNumberLength.Validate(telephone));
        }