public void op_Load_FileInfoNotFound()
        {
            using (var temp = new TempDirectory())
            {
                var file = temp.Info.ToFile("sabc.csv");

                Assert.Throws <FileNotFoundException>(() => BritishTelephoneNumberPlan.Load(file));
            }
        }
        public void ctor()
        {
            var plan = new BritishTelephoneNumberPlan
            {
                { "example", new BritishTelephoneNumberPlanItem() }
            };

            Assert.True(plan.ContainsKey("example"));
            Assert.False(plan.ContainsKey("Example"));
        }
Ejemplo n.º 3
0
        public static BritishTelephoneNumberPlan Load(FileInfo file)
        {
            var result = new BritishTelephoneNumberPlan();

            foreach (var item in new CsvDataSheet(file).Where(entry => entry["Status"].Is("Designated"))
                     .Select(Load))
            {
                result.TryAdd(item.DialingCode, item);
            }

            return(result);
        }
        public void op_Load_KeyStringDictionary_whenNottingham()
        {
            var entry = new KeyStringDictionary
            {
                { "Code", "1152" },
                { "D/DE", "0" },
                { "Notes", "3 Digit Area Code" },
                { "Use", "Nottingham" },
            };
            var actual = BritishTelephoneNumberPlan.Load(entry);

            Assert.Equal("115", actual.AreaCode);
            Assert.Equal("11520", actual.DialingCode);
            Assert.Equal("Nottingham", actual.Use);
        }
        public void op_Load_KeyStringDictionary_whenLondon()
        {
            var entry = new KeyStringDictionary
            {
                { "Code", "2071" },
                { "D/DE", string.Empty },
                { "Notes", string.Empty },
                { "Use", "London" },
            };
            var actual = BritishTelephoneNumberPlan.Load(entry);

            Assert.Equal("20", actual.AreaCode);
            Assert.Equal("2071", actual.DialingCode);
            Assert.Equal("London", actual.Use);
        }
        public void op_Load_KeyStringDictionary_whenLancaster()
        {
            var entry = new KeyStringDictionary
            {
                { "Code", "1524" },
                { "D/DE", "5" },
                { "Notes", "4 Digit Code Area" },
                { "Use", "Lancaster" },
            };
            var actual = BritishTelephoneNumberPlan.Load(entry);

            Assert.Equal("1524", actual.AreaCode);
            Assert.Equal("15245", actual.DialingCode);
            Assert.Equal("Lancaster", actual.Use);
        }
        public void op_Load_KeyStringDictionary_whenHarrogate()
        {
            var entry = new KeyStringDictionary
            {
                { "Code", "1423" },
                { "D/DE", "6" },
                { "Notes", "ELNS" },
                { "Use", "Harrogate" },
            };
            var actual = BritishTelephoneNumberPlan.Load(entry);

            Assert.Equal("14236", actual.AreaCode);
            Assert.Equal("14236", actual.DialingCode);
            Assert.Equal("Harrogate", actual.Use);
        }
        public void op_Load_KeyStringDictionary_whenGlasgow()
        {
            var entry = new KeyStringDictionary
            {
                { "Code", "1412" },
                { "D/DE", string.Empty },
                { "Notes", "3 Digit Code Area" },
                { "Use", "Glasgow" },
            };
            var actual = BritishTelephoneNumberPlan.Load(entry);

            Assert.Equal("141", actual.AreaCode);
            Assert.Equal("1412", actual.DialingCode);
            Assert.Equal("Glasgow", actual.Use);
        }
        public void op_Load_KeyStringDictionary_whenColchester()
        {
            var entry = new KeyStringDictionary
            {
                { "Code", "1206" },
                { "D/DE", string.Empty },
                { "Notes", string.Empty },
                { "Use", "Colchester" },
            };
            var actual = BritishTelephoneNumberPlan.Load(entry);

            Assert.Equal("1206", actual.AreaCode);
            Assert.Equal("1206", actual.DialingCode);
            Assert.Equal("Colchester", actual.Use);
        }
        public void op_Load_KeyStringDictionary_whenSedbergh()
        {
            var entry = new KeyStringDictionary
            {
                { "Code", "1539" },
                { "D/DE", "6" },
                { "Notes", "5 Digit Code Area" },
                { "Use", "Sedbergh" },
            };
            var actual = BritishTelephoneNumberPlan.Load(entry);

            Assert.Equal("15396", actual.AreaCode);
            Assert.Equal("15396", actual.DialingCode);
            Assert.Equal("Sedbergh", actual.Use);
        }
        public void op_Load_KeyStringDictionary_when3DigitAreaCode()
        {
            var entry = new KeyStringDictionary
            {
                { "Code", "1999" },
                { "D/DE", string.Empty },
                { "Notes", "3 Digit Area Code" },
                { "Use", "Example" },
            };
            var actual = BritishTelephoneNumberPlan.Load(entry);

            Assert.Equal("199", actual.AreaCode);
            Assert.Equal("1999", actual.DialingCode);
            Assert.Equal("Example", actual.Use);
        }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
0
        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);
        }
 public void op_Load_KeyStringDictionaryNull()
 {
     Assert.Throws <ArgumentNullException>(() => BritishTelephoneNumberPlan.Load(null as KeyStringDictionary));
 }
 public void op_Load_FileInfoNull()
 {
     Assert.Throws <ArgumentNullException>(() => BritishTelephoneNumberPlan.Load(null as FileInfo));
 }
        public void op_Load_FileInfo()
        {
            var plan = BritishTelephoneNumberPlan.Load(new FileInfo("sabc.csv"));

            Assert.NotEmpty(plan);
        }
        public void op_Item_string_whenNullResult(string telephone)
        {
            var plan = new BritishTelephoneNumberPlan();

            Assert.Null(plan.Item(telephone));
        }
        public void op_Item_stringNull()
        {
            var plan = new BritishTelephoneNumberPlan();

            Assert.Throws <ArgumentNullException>(() => plan.Item(null));
        }