using System; using System.Collections.Generic; using AddressSolution.AddressRules; using AddressSolution.Dao; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace AddressSolution.Test { [TestClass] public class UnitTest1 { [TestMethod] public void CanReadExcelFile() { List addressList = new ExcelDao().GetExcel(); Assert.IsNotNull(addressList); } [TestMethod] public void CanParsedAddress() { List addressList = new ExcelDao().GetExcel(); List parsedAddress = new ParseAddress().Parse(addressList); Assert.AreEqual(addressList.Count, parsedAddress.Count); } [TestMethod] public void CanVerifyAddressWithOneComma() { string addressLine = "4059 FARNSWORTH CRES MISSISSAUGA ON, L5L3Z4"; Assert.AreEqual("4059 FARNSWORTH CRES MISSISSAUGA ON, L5L3Z4", addressLine); Assert.AreEqual("4059", RuleStreetNumber.GetStreetNumber(addressLine)); Assert.AreEqual("FARNSWORTH", RuleStreetName.GetStreetName(addressLine)); Assert.AreEqual("CRES", RuleStreetType.GetStreetType(addressLine)); Assert.AreEqual("", RuleStreetDirection.GetStreetDirection(addressLine)); Assert.AreEqual("", RuleSuite.GetSuite(addressLine)); Assert.AreEqual("MISSISSAUGA", RuleMunicipality.GetMunicipality(addressLine)); Assert.AreEqual("ON", RuleProvince.GetProvince(addressLine)); Assert.AreEqual("L5L3Z4", RulePostalCode.GetPostalCode(addressLine)); } [TestMethod] public void CanVerifyAddressWithCommas() { string addressLine = "4059 FARNSWORTH CRES, MISSISSAUGA ON, L5L3Z4"; Assert.AreEqual("4059 FARNSWORTH CRES, MISSISSAUGA ON, L5L3Z4", addressLine); Assert.AreEqual("4059", RuleStreetNumber.GetStreetNumber(addressLine)); Assert.AreEqual("FARNSWORTH", RuleStreetName.GetStreetName(addressLine)); Assert.AreEqual("CRES", RuleStreetType.GetStreetType(addressLine)); Assert.AreEqual("", RuleStreetDirection.GetStreetDirection(addressLine)); Assert.AreEqual("", RuleSuite.GetSuite(addressLine)); Assert.AreEqual("MISSISSAUGA", RuleMunicipality.GetMunicipality(addressLine)); Assert.AreEqual("ON", RuleProvince.GetProvince(addressLine)); Assert.AreEqual("L5L3Z4", RulePostalCode.GetPostalCode(addressLine)); } [TestMethod] public void CanVerifyAddressWithTightCommas() { string addressLine = "4059 FARNSWORTH CRES,MISSISSAUGA ON,L5L3Z4"; Assert.AreEqual("4059 FARNSWORTH CRES,MISSISSAUGA ON,L5L3Z4", addressLine); Assert.AreEqual("4059", RuleStreetNumber.GetStreetNumber(addressLine)); Assert.AreEqual("FARNSWORTH", RuleStreetName.GetStreetName(addressLine)); Assert.AreEqual("CRES", RuleStreetType.GetStreetType(addressLine)); Assert.AreEqual("", RuleStreetDirection.GetStreetDirection(addressLine)); Assert.AreEqual("", RuleSuite.GetSuite(addressLine)); Assert.AreEqual("MISSISSAUGA", RuleMunicipality.GetMunicipality(addressLine)); Assert.AreEqual("ON", RuleProvince.GetProvince(addressLine)); Assert.AreEqual("L5L3Z4", RulePostalCode.GetPostalCode(addressLine)); } [TestMethod] public void CanVerifyAddressWithNoCommas() { string addressLine = "621 BRITANNIA DR SW CALGARY AB T2S1S2"; Assert.AreEqual("621 BRITANNIA DR SW CALGARY AB T2S1S2", addressLine); Assert.AreEqual("621", RuleStreetNumber.GetStreetNumber(addressLine)); Assert.AreEqual("BRITANNIA", RuleStreetName.GetStreetName(addressLine)); Assert.AreEqual("DR", RuleStreetType.GetStreetType(addressLine)); Assert.AreEqual("SW", RuleStreetDirection.GetStreetDirection(addressLine)); Assert.AreEqual("", RuleSuite.GetSuite(addressLine)); Assert.AreEqual("CALGARY", RuleMunicipality.GetMunicipality(addressLine)); Assert.AreEqual("AB", RuleProvince.GetProvince(addressLine)); Assert.AreEqual("T2S1S2", RulePostalCode.GetPostalCode(addressLine)); } [TestMethod] public void CanVerifyAddressWithExtraSpaces() { string addressLine = "4059 FARNSWORTH CRES MISSISSAUGA ON L5L3Z4"; Assert.AreEqual("4059 FARNSWORTH CRES MISSISSAUGA ON L5L3Z4", addressLine); Assert.AreEqual("4059", RuleStreetNumber.GetStreetNumber(addressLine)); Assert.AreEqual("FARNSWORTH", RuleStreetName.GetStreetName(addressLine)); Assert.AreEqual("CRES", RuleStreetType.GetStreetType(addressLine)); Assert.AreEqual("", RuleStreetDirection.GetStreetDirection(addressLine)); Assert.AreEqual("", RuleSuite.GetSuite(addressLine)); Assert.AreEqual("MISSISSAUGA", RuleMunicipality.GetMunicipality(addressLine)); Assert.AreEqual("ON", RuleProvince.GetProvince(addressLine)); Assert.AreEqual("L5L3Z4", RulePostalCode.GetPostalCode(addressLine)); } } }