public void Parser_ParseAddress()
        {
            var addressParser = AddressesParser.Parse("Lidstostrasse 5\r\n6006 Luzern");

            Assert.AreEqual("6006", addressParser.PostalCode);
            Assert.AreEqual("Luzern", addressParser.City);
            Assert.AreEqual("Lidstostrasse 5", addressParser.Street);
        }
        public void Parser_ParseWithLongerCityName()
        {
            var addressParser = AddressesParser.Parse("Bul Oslobodjenja 38\r\n21000 Novi Sad");

            Assert.AreEqual("21000", addressParser.PostalCode);
            Assert.AreEqual("Novi Sad", addressParser.City);
            Assert.AreEqual("Bul Oslobodjenja 38", addressParser.Street);
        }
        public void Parser_ParseWithCityNameInFirstRow()
        {
            var addressParser = AddressesParser.Parse("Bul Oslobodjenja 38\r\n21000 Novi Sad\r\nSerbia");

            Assert.AreEqual("21000", addressParser.PostalCode);
            Assert.AreEqual("Novi Sad", addressParser.City);
            Assert.AreEqual("Bul Oslobodjenja 38", addressParser.Street);
            Assert.AreEqual("Serbia", addressParser.Country);
        }
        public void Parser_ParseAddressWithPoBox()
        {
            var addressParser = AddressesParser.Parse("Lidstostrasse 5\r\nPostfach 42\r\n6006 Luzern");

            Assert.AreEqual("6006", addressParser.PostalCode);
            Assert.AreEqual("Luzern", addressParser.City);
            //Assert.AreEqual("Postfach 42", addressParser.PostalBox);
            Assert.AreEqual("Lidstostrasse 5", addressParser.Street);
        }
        public void Parser_ParseWithoutPostalCodeOrCity()
        {
            var addressParser = AddressesParser.Parse("Bul Oslobodjenja 38\r\nNovi Sad");

            Assert.IsNull(addressParser.PostalCode);
            Assert.IsNull(addressParser.City);

            addressParser = AddressesParser.Parse("Bul Oslobodjenja 38\r\n21000");

            Assert.AreEqual("21000", addressParser.PostalCode);
            Assert.IsTrue(string.IsNullOrEmpty(addressParser.City));
        }
        public void Parser_ParseWithMultilineAddress()
        {
            var addressParser = AddressesParser.Parse("IT Engine\r\nBul Oslobodjenja 38\r\n21000 Novi Sad\r\nSerbia");

            Assert.AreEqual("21000", addressParser.PostalCode);
            Assert.AreEqual("Novi Sad", addressParser.City);
            Assert.AreEqual("Bul Oslobodjenja 38", addressParser.Street);
            Assert.AreEqual("Serbia", addressParser.Country);

            var addressLines = addressParser.AddressLines;

            Assert.AreEqual("IT Engine", addressLines[0]);
            Assert.AreEqual("Bul Oslobodjenja 38", addressLines[1]);
            Assert.AreEqual("Serbia", addressLines[2]);
        }
Ejemplo n.º 7
0
        public static Municipality TryGuessMunicipality(string formattedAddress)
        {
            Address addressParser = AddressesParser.Parse(formattedAddress);

            if (!string.IsNullOrWhiteSpace(addressParser.City))
            {
                //Try to guess the canton using the postal code
                XmlNode node = _municipalities.FirstOrDefault(n => string.Equals(n.Attributes["MunicipalityName"].Value, addressParser.City, StringComparison.OrdinalIgnoreCase));

                //if an element with the given postal code is found return the corresponding canton
                if (node != null)
                {
                    return(new Municipality
                    {
                        Canton = node.Attributes["CantonNumber"].Value,
                        MunicipalityName = node.Attributes["MunicipalityName"].Value,
                        MunicipalityNumber = node.Attributes["MunicipalityNumber"].Value
                    });
                }
            }

            return(null);
        }
Ejemplo n.º 8
0
        public static string TryGuessCanton(string formattedAddress)
        {
            Address addressParser = AddressesParser.Parse(formattedAddress);

            return(TryGuessCanton(addressParser.PostalCode, addressParser.City));
        }