diff --git a/IdParser.Test/DriversLicenseTests.cs b/IdParser.Test/DriversLicenseTests.cs index df6e15d..b4323c1 100644 --- a/IdParser.Test/DriversLicenseTests.cs +++ b/IdParser.Test/DriversLicenseTests.cs @@ -264,7 +264,7 @@ public void TestMOLicense() Assert.IsNotNull(idCard); Assert.AreEqual("FirstNameTest", idCard.FirstName); - Assert.AreEqual(" ", idCard.MiddleName); + Assert.IsNull(idCard.MiddleName); Assert.AreEqual("LastNameTest", idCard.LastName); Assert.AreEqual("123 ABC TEST ADDRESS 2ND FL", idCard.StreetLine1); @@ -293,5 +293,45 @@ public void TestMOLicense() Assert.AreEqual("F", license.Jurisdiction.VehicleClass); } } + + [TestMethod] + public void TestFLLicense() + { + var file = File.ReadAllText("FL License.txt"); + var idCard = Barcode.Parse(file, Validation.None); + + Assert.IsNotNull(idCard); + + Assert.AreEqual("JOEY", idCard.FirstName); + Assert.AreEqual("MIDLAND", idCard.MiddleName); + Assert.AreEqual("TESTER", idCard.LastName); + + Assert.AreEqual("1234 PARK ST LOT 504", idCard.StreetLine1); + Assert.AreEqual("KEY WEST", idCard.City); + Assert.AreEqual("FL", idCard.IssuerIdentificationNumber.GetAbbreviation()); + Assert.AreEqual("FL", idCard.JurisdictionCode); + Assert.AreEqual("330400504", idCard.PostalCode); + Assert.AreEqual("33040-0504", idCard.FormattedPostalCode); + Assert.AreEqual(Country.USA, idCard.Country); + + Assert.AreEqual(new DateTime(1941, 05, 09), idCard.DateOfBirth); + Assert.AreEqual(Sex.Male, idCard.Sex); + Assert.AreEqual(73, idCard.Height.TotalInches); + Assert.AreEqual(WeightRange.None, idCard.WeightRange); + + Assert.AreEqual("H574712510891", idCard.IdNumber); + Assert.AreEqual(Version.Aamva2000, idCard.AamvaVersionNumber); + Assert.AreEqual(new DateTime(2014, 05, 01), idCard.IssueDate); + Assert.AreEqual(new DateTime(2022, 03, 09), idCard.ExpirationDate); + + Assert.AreEqual(5, idCard.AdditionalJurisdictionElements.Count); + Assert.AreEqual("FA", idCard.AdditionalJurisdictionElements.Single(e => e.Key == "ZFZ").Value); + + if (idCard is DriversLicense license) + { + Assert.AreEqual("A", license.Jurisdiction.RestrictionCodes); + Assert.AreEqual("E", license.Jurisdiction.VehicleClass); + } + } } } diff --git a/IdParser.Test/FL License.txt b/IdParser.Test/FL License.txt new file mode 100644 index 0000000..5dd2e16 --- /dev/null +++ b/IdParser.Test/FL License.txt @@ -0,0 +1,21 @@ +@ + +ANSI 6360100102DL00390187ZF02260043DLDAATESTER,JOEY, MIDLAND +DAG1234 PARK ST LOT 504 +DAIKEY WEST +DAJFL +DAK33040-0504 +DAQH574712510891 +DARE +DASA +DATNONE +DBA20220309 +DBB19410509 +DBC1 +DBD20140501 +DAU601 +ZFZFA +ZFB +ZFCN899999999077 +ZFD +ZFE09-01-12 \ No newline at end of file diff --git a/IdParser.Test/IdParser.Test.csproj b/IdParser.Test/IdParser.Test.csproj index a466bad..afcf55a 100644 --- a/IdParser.Test/IdParser.Test.csproj +++ b/IdParser.Test/IdParser.Test.csproj @@ -71,6 +71,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/IdParser/Extensions.cs b/IdParser/Extensions.cs index a2f0a51..3a0dc14 100644 --- a/IdParser/Extensions.cs +++ b/IdParser/Extensions.cs @@ -61,5 +61,10 @@ internal static DateTime ParseDate(this Country country, Version version, string throw new ArgumentException($"Failed to parse the date '{value}' for country '{country}' using version '{version}'.", nameof(value)); } + + internal static string ReplaceEmptyWithNull(this string data) + { + return string.IsNullOrEmpty(data) ? null : data; + } } } diff --git a/IdParser/IdentificationCard.cs b/IdParser/IdentificationCard.cs index b3795ab..81cf034 100644 --- a/IdParser/IdentificationCard.cs +++ b/IdParser/IdentificationCard.cs @@ -105,17 +105,17 @@ private void ParseRecord(string subfileRecord) // Required attributes case "DAA": var names = data.Split(',', '$'); - LastName = names.Length > 0 ? names[0].Trim() : null; - FirstName = names.Length > 1 ? names[1].Trim() : null; - MiddleName = names.Length > 2 ? names[2].Trim() : null; + LastName = names.Length > 0 ? names[0].Trim().ReplaceEmptyWithNull() : null; + FirstName = names.Length > 1 ? names[1].Trim().ReplaceEmptyWithNull() : null; + MiddleName = names.Length > 2 ? names[2].Trim().ReplaceEmptyWithNull() : null; break; // AAMVA 2003-2005 case "DCT": var givenNames = data.Split(',', '$', ' '); - FirstName = givenNames[0]; - MiddleName = givenNames.Length > 1 ? givenNames[1] : null; + FirstName = givenNames[0].Trim(); + MiddleName = givenNames.Length > 1 ? givenNames[1].Trim().ReplaceEmptyWithNull() : null; break;