public void AddressConverter_ConvertingAddress_ProducesExpectedFormat(string zipCode, string city)
        {
            IAddress address = addressBuilderFactory.Create()
                               .WithZipCode(zipCode)
                               .WithCity(city)
                               .Build();

            string converted = addressConverter.Convert(address);

            Assert.IsTrue(Regex.IsMatch(converted, @"\w+\s\w[\w\s]+"));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Convert a <see cref="string"/> to an <see cref="IAddress"/>.
        /// </summary>
        /// <param name="toConvert">The <see cref="string"/> to convert</param>
        /// <returns>The converted <see cref="string"/></returns>
        /// <exception cref="ArgumentNullException">If <see cref="null"/> is passed</exception>
        /// <exception cref="InvalidFormattedAddressException">If the value given by <paramref name="toConvert"/> isn't formatted correctly</exception>
        public override IAddress Convert(string toConvert)
        {
            if (toConvert is null)
            {
                throw new ArgumentNullException(nameof(toConvert));
            }

            string[] parts = toConvert.Split(new[] { Separator }, NumberOfParts);
            if (parts.Length != NumberOfParts)
            {
                throw new InvalidFormattedAddressException(toConvert, NumberOfParts, Separator);
            }

            return(addressBuilderFactory.Create()
                   .WithZipCode(parts[0])
                   .WithCity(parts[1])
                   .Build());
        }