Esempio n. 1
0
        public static Address Parse(string address)
        {
            if (string.IsNullOrEmpty(address))
                return new Address();

            Address result;
            var input = address.ToUpper();

            var re = new Regex(BuildPattern());
            if (re.IsMatch(input))
            {
                var m = re.Match(input);
                result = new Address
                {
                    HouseNumber = m.Groups["HouseNumber"].Value,
                    StreetPrefix = m.Groups["StreetPrefix"].Value,
                    StreetName = m.Groups["StreetName"].Value,
                    StreetType = m.Groups["StreetType"].Value,
                    StreetSuffix = m.Groups["StreetSuffix"].Value,
                    Apt = m.Groups["Apt"].Value,
                };
            }
            else
            {
                result = new Address
                {
                    StreetName = input,
                };
            }
            return result;
        }
Esempio n. 2
0
        public void ParseAssignsInputToStreetNameWhenInputCannotBeParsed()
        {
            // Arrange
            const string input = "127.0.0.1 IS NOT A VALID FORMAT";
            var expected = new Address
            {
                StreetName = input
            };

            // Act
            var actual = Parser.Parse(input);

            // Assert
            CompareAddresses(expected, actual);
        }
Esempio n. 3
0
        public void ParseParsesHouseNumberAndStreetName()
        {
            // Arrange
            const string input = "100 MAIN";
            var expected = new Address
            {
                HouseNumber = "100",
                StreetName = "MAIN"
            };

            // Act
            var actual = Parser.Parse(input);

            // Assert
            CompareAddresses(expected, actual);
        }
Esempio n. 4
0
        public void ParseParsesHouseNumberStreetPrefixStreetNameAndStreetType()
        {
            // Arrange
            const string input = "100 S MAIN ST";
            var expected = new Address
            {
                HouseNumber = "100",
                StreetName = "MAIN",
                StreetPrefix = "S",
                StreetType = "ST"
            };

            // Act
            var actual = Parser.Parse(input);

            // Assert
            CompareAddresses(expected, actual);
        }
Esempio n. 5
0
 private void CompareAddresses(Address expected, Address actual)
 {
     Assert.IsNotNull(actual);
     CompareStrings(expected.HouseNumber, actual.HouseNumber, "HouseNumber");
     CompareStrings(expected.StreetName, actual.StreetName, "StreetName");
     CompareStrings(expected.StreetPrefix, actual.StreetPrefix, "StreetPrefix");
     CompareStrings(expected.StreetSuffix, actual.StreetSuffix, "StreetSuffix");
     CompareStrings(expected.StreetType, actual.StreetType, "StreetType");
     CompareStrings(expected.Apt, actual.Apt, "Apt");
 }
Esempio n. 6
0
        public void ParseReturnsEmptyAddressForNullInput()
        {
            // Arrange
            var expected = new Address();

            // Act
            var actual = Parser.Parse(null);

            // Assert
            CompareAddresses(expected, actual);
        }
Esempio n. 7
0
        public void ParseResultsAreAllUppercase()
        {
            // Arrange
            const string input = "100 s main st w apt 1a";
            var expected = new Address
            {
                HouseNumber = "100",
                StreetName = "MAIN",
                StreetPrefix = "S",
                StreetSuffix = "W",
                StreetType = "ST",
                Apt = "APT 1A"
            };

            // Act
            var actual = Parser.Parse(input);

            // Assert
            CompareAddresses(expected, actual);
        }
Esempio n. 8
0
        public void ParseParsesHouseNumberStreetPrefixStreetNameStreetTypeStreetSuffixAndApartment()
        {
            // Arrange
            const string input = "100 S MAIN ST W APT 1A";
            var expected = new Address
            {
                HouseNumber = "100",
                StreetName = "MAIN",
                StreetPrefix = "S",
                StreetSuffix = "W",
                StreetType = "ST",
                Apt = "APT 1A"
            };

            // Act
            var actual = Parser.Parse(input);

            // Assert
            CompareAddresses(expected, actual);
        }