示例#1
0
        public void op_ToString()
        {
            const string expected = "+441111222333";
            var          actual   = Telephone.FromString(expected).ToString();

            Assert.Equal(expected, actual);
        }
示例#2
0
        public void op_FromString_stringEmpty()
        {
            var expected = string.Empty;
            var actual   = Telephone.FromString(expected).ToString();

            Assert.Equal(expected, actual);
        }
示例#3
0
        public void op_FromString_string()
        {
            const string value = "+441111222333";

            var obj = Telephone.FromString(value);

            Assert.Equal(value, obj.Number);
        }
示例#4
0
        public void opImplicit_Telephone_string()
        {
            const string value = "+441111222333";

            Telephone obj = value;

            Assert.Equal(value, obj.Number);
        }
        public static bool Validate(Telephone telephone)
        {
            if (null == telephone)
            {
                throw new ArgumentNullException("telephone");
            }

            return(Validate(telephone.Number));
        }
 public void prop_Number()
 {
     Assert.True(new PropertyExpectations <BritishTelephone>(p => p.Number)
                 .IsNotDecorated()
                 .TypeIs <Telephone>()
                 .ArgumentNullException()
                 .Set(Telephone.FromString("(01234) 567 890"))
                 .Result);
 }
        public static bool Validate(Telephone telephone)
        {
            if (null == telephone)
            {
                throw new ArgumentNullException("telephone");
            }

            return Validate(telephone.Number);
        }
        public void op_Load_BritishTelephoneNumberPlan_Telephone_whenInvalid(string number)
        {
            var       plan      = BritishTelephoneNumberPlan.Load(new FileInfo("sabc.csv"));
            Telephone telephone = number;

            var actual = BritishTelephone.Load(plan, telephone);

            Assert.Empty(actual.Area);
            Assert.Empty(actual.AreaCode);
            Assert.Empty(actual.NumberGroups);
            Assert.Empty(actual.DialingCode);
            Assert.Empty(actual.LocalNumber);
            Assert.Empty(actual.ServiceType);
            Assert.Equal(telephone, actual.Number);
            Assert.False(actual.IsValid);
        }
示例#9
0
        public static BritishTelephone Load(BritishTelephoneNumberPlan plan,
                                            Telephone telephone)
        {
            if (null == plan)
            {
                throw new ArgumentNullException("plan");
            }

            if (null == telephone)
            {
                throw new ArgumentNullException("telephone");
            }

            var result = new BritishTelephone
            {
                Number       = telephone,
                AreaCode     = string.Empty,
                Area         = string.Empty,
                NumberGroups = string.Empty,
                DialingCode  = string.Empty,
                LocalNumber  = string.Empty,
                ServiceType  = string.Empty,
            };

            var item = plan.Item(telephone);

            if (null == item)
            {
                return(result);
            }

            var valid = item.Use.IndexOf("Unassigned", StringComparison.OrdinalIgnoreCase).Is(-1);

            result.Number       = telephone;
            result.AreaCode     = item.AreaCode;
            result.Area         = item.Use;
            result.LocalNumber  = ToLocalNumber(item.DialingCode, telephone.Number);
            result.NumberGroups = ToNumberGroups(item.AreaCode, telephone.Number);
            result.DialingCode  = item.DialingCode;
            result.ServiceType  = ToServiceType(telephone.Number);
            result.IsValid      = valid;

            return(result);
        }
示例#10
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_Load_BritishTelephoneNumberPlan_Telephone(string number,
                                                                 bool valid,
                                                                 string area,
                                                                 string areaCode,
                                                                 string numberGroups,
                                                                 string dialingCode,
                                                                 string localNumber,
                                                                 string serviceType)
        {
            var       plan      = BritishTelephoneNumberPlan.Load(new FileInfo("sabc.csv"));
            Telephone telephone = number;

            var actual = BritishTelephone.Load(plan, telephone);

            Assert.Equal(area, actual.Area);
            Assert.Equal(areaCode, actual.AreaCode);
            Assert.Equal(numberGroups, actual.NumberGroups);
            Assert.Equal(dialingCode, actual.DialingCode);
            Assert.Equal(localNumber, actual.LocalNumber);
            Assert.Equal(serviceType, actual.ServiceType);
            Assert.Equal(telephone, actual.Number);
            Assert.Equal(valid, actual.IsValid);
        }
示例#12
0
        public void op_FromString_string_whenLongInternationalFormat()
        {
            var obj = Telephone.FromString("00441111222333");

            Assert.Equal("+441111222333", obj.Number);
        }
示例#13
0
 public void op_FromString_stringNull()
 {
     Assert.Throws <ArgumentNullException>(() => Telephone.FromString(null));
 }
示例#14
0
        public void opImplicit_Telephone_stringEmpty()
        {
            Telephone obj = string.Empty;

            Assert.Null(obj.Number);
        }
示例#15
0
        public static BritishTelephone Load(BritishTelephoneNumberPlan plan,
                                            Telephone telephone)
        {
            if (null == plan)
            {
                throw new ArgumentNullException("plan");
            }

            if (null == telephone)
            {
                throw new ArgumentNullException("telephone");
            }

            var result = new BritishTelephone
                             {
                                 Number = telephone,
                                 AreaCode = string.Empty,
                                 Area = string.Empty,
                                 NumberGroups = string.Empty,
                                 DialingCode = string.Empty,
                                 LocalNumber = string.Empty,
                                 ServiceType = string.Empty,
                             };

            var item = plan.Item(telephone);
            if (null == item)
            {
                return result;
            }

            var valid = item.Use.IndexOf("Unassigned", StringComparison.OrdinalIgnoreCase).Is(-1);

            result.Number = telephone;
            result.AreaCode = item.AreaCode;
            result.Area = item.Use;
            result.LocalNumber = ToLocalNumber(item.DialingCode, telephone.Number);
            result.NumberGroups = ToNumberGroups(item.AreaCode, telephone.Number);
            result.DialingCode = item.DialingCode;
            result.ServiceType = ToServiceType(telephone.Number);
            result.IsValid = valid;

            return result;
        }
        public void op_Validate_TelephoneEmpty()
        {
            Telephone telephone = string.Empty;

            Assert.Throws <ArgumentNullException>(() => BritishTelephoneNumberLength.Validate(telephone));
        }
示例#17
0
        public void op_FromString_string_whenDomesticFormatAndComment()
        {
            var obj = Telephone.FromString("(01111) 222-333 at home");

            Assert.Equal("+441111222333", obj.Number);
        }
示例#18
0
 public BritishTelephoneNumberPlanItem Item(string telephone)
 {
     return(Item(Telephone.FromString(telephone)));
 }
示例#19
0
        public void op_FromString_string_whenShortInternationalFormat()
        {
            var obj = Telephone.FromString("+1 (222) 333-4444");

            Assert.Equal("+12223334444", obj.Number);
        }
示例#20
0
        public void op_FromString_string_whenMissingLeadingZero()
        {
            var obj = Telephone.FromString("1111222333");

            Assert.Equal("+441111222333", obj.Number);
        }
示例#21
0
        public void op_FromString_string_whenNoDigits()
        {
            var obj = Telephone.FromString("not a number");

            Assert.Null(obj.Number);
        }