Skip to content

Commit

Permalink
Added IIN abbreviations
Browse files Browse the repository at this point in the history
  • Loading branch information
c0shea committed Sep 25, 2016
1 parent b67401f commit 4778b47
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 0 deletions.
6 changes: 6 additions & 0 deletions IdParser.Tests/DriversLicenseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public void TestMA2009License() {
var idCard = IdParser.Parse(file, true);

Assert.AreEqual("SMITH", idCard.LastName);
Assert.AreEqual("MA", idCard.IssuerIdentificationNumber.GetAbbreviation());
}

[TestMethod]
Expand All @@ -24,6 +25,7 @@ public void TestMA2016License() {
Assert.AreEqual("24 BEACON STREET", idCard.StreetLine1);
Assert.AreEqual("MA504", idCard.AdditionalJurisdictionElements.Single(e => e.Key == "ZMZ").Value);
Assert.AreEqual("02133-0000", idCard.FormattedPostalCode);
Assert.AreEqual("MA", idCard.IssuerIdentificationNumber.GetAbbreviation());

if (idCard is DriversLicense) {
var license = (DriversLicense)idCard;
Expand All @@ -41,6 +43,7 @@ public void TestNYLicense() {
Assert.AreEqual("Michael", license.LastName);
Assert.AreEqual(new DateTime(2013, 08, 31), license.DateOfBirth);
Assert.AreEqual("New York", license.IssuerIdentificationNumber.GetDescription());
Assert.AreEqual("NY", license.IssuerIdentificationNumber.GetAbbreviation());
}

[TestMethod]
Expand All @@ -49,6 +52,7 @@ public void TestVALicense() {
var idCard = IdParser.Parse(file);

Assert.AreEqual("STAUNTON", idCard.City);
Assert.AreEqual("VA", idCard.IssuerIdentificationNumber.GetAbbreviation());

if (idCard is DriversLicense) {
var license = (DriversLicense)idCard;
Expand All @@ -65,6 +69,7 @@ public void TestGALicense()

Assert.AreEqual("123 NORTH STATE ST.", idCard.StreetLine1);
Assert.AreEqual("Georgia", idCard.IssuerIdentificationNumber.GetDescription());
Assert.AreEqual("GA", idCard.IssuerIdentificationNumber.GetAbbreviation());

if (idCard is DriversLicense) {
var license = (DriversLicense)idCard;
Expand All @@ -82,6 +87,7 @@ public void TestCTLicense()
Assert.IsTrue(idCard.IsOrganDonor);
Assert.AreEqual("CTLIC", idCard.LastName);
Assert.AreEqual("990000001", idCard.IdNumber);
Assert.AreEqual("CT", idCard.IssuerIdentificationNumber.GetAbbreviation());
}

[TestMethod]
Expand Down
12 changes: 12 additions & 0 deletions IdParser/AbbreviationAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace IdParser {
[AttributeUsage(AttributeTargets.All)]
public class AbbreviationAttribute : Attribute {
public string Abbreviation { get; set; }

public AbbreviationAttribute(string abbreviation) {
Abbreviation = abbreviation;
}
}
}
74 changes: 74 additions & 0 deletions IdParser/IdParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ public static string GetDescription(this Enum value) {

return attribute == null ? value.ToString() : attribute.Description;
}

public static string GetAbbreviation(this Enum value) {
var field = value.GetType().GetField(value.ToString());

var attribute = Attribute.GetCustomAttribute(field, typeof(AbbreviationAttribute)) as AbbreviationAttribute;

return attribute == null ? value.ToString() : attribute.Abbreviation;
}
}

public enum Version : byte {
Expand All @@ -140,90 +148,156 @@ public enum Version : byte {
}

public enum IssuerIdentificationNumber {
[Abbreviation("AL")]
Alabama = 636033,
[Abbreviation("AK")]
Alaska = 636059,
[Abbreviation("AS")]
[Description("American Samoa")]
AmericanSamoa = 604427,
[Abbreviation("AZ")]
Arizona = 636026,
[Abbreviation("AR")]
Arkansas = 636026,
[Abbreviation("BC")]
[Description("British Columbia")]
BritishColumbia = 636028,
[Abbreviation("CA")]
California = 636014,
[Abbreviation("COA")]
Coahuila = 636056,
[Abbreviation("CO")]
Colorado = 636020,
[Abbreviation("CT")]
Connecticut = 636006,
[Abbreviation("DC")]
[Description("District of Columbia")]
DistrictOfColumbia = 636043,
[Abbreviation("DE")]
Delaware = 636011,
[Abbreviation("FL")]
Florida = 636010,
[Abbreviation("GA")]
Georgia = 636055,
[Abbreviation("GU")]
Guam = 636019,
[Abbreviation("HI")]
Hawaii = 636047,
[Abbreviation("HID")]
Hidalgo = 636057,
[Abbreviation("ID")]
Idaho = 636050,
[Abbreviation("IL")]
Illinois = 636035,
[Abbreviation("IN")]
Indiana = 636037,
[Abbreviation("IA")]
Iowa = 636018,
[Abbreviation("KS")]
Kansas = 636022,
[Abbreviation("KY")]
Kentucky = 636046,
[Abbreviation("LA")]
Louisiana = 636007,
[Abbreviation("ME")]
Maine = 636041,
[Abbreviation("MB")]
Manitoba = 636048,
[Abbreviation("MD")]
Maryland = 636003,
[Abbreviation("MA")]
Massachusetts = 636002,
[Abbreviation("MI")]
Michigan = 636032,
[Abbreviation("MN")]
Minnesota = 636038,
[Abbreviation("MS")]
Mississippi = 636051,
[Abbreviation("MO")]
Missouri = 636030,
[Abbreviation("MT")]
Montana = 636008,
[Abbreviation("NE")]
Nebraska = 636054,
[Abbreviation("NV")]
Nevada = 636049,
[Abbreviation("NB")]
[Description("New Brunswick")]
NewBrunswick = 636017,
[Abbreviation("ND")]
[Description("New Hampshire")]
NewHampshire = 636039,
[Abbreviation("NJ")]
[Description("New Jersey")]
NewJersey = 636036,
[Abbreviation("NM")]
[Description("New Mexico")]
NewMexico = 636009,
[Abbreviation("NY")]
[Description("New York")]
NewYork = 636001,
[Abbreviation("NL")]
Newfoundland = 636016,
[Abbreviation("NC")]
[Description("North Carolina")]
NorthCarolina = 636004,
[Abbreviation("ND")]
[Description("North Dakota")]
NorthDakota = 636034,
[Abbreviation("NS")]
[Description("Nova Scotia")]
NovaScotia = 636013,
[Abbreviation("OH")]
Ohio = 636023,
[Abbreviation("OK")]
Oklahoma = 636058,
[Abbreviation("ON")]
Ontario = 636012,
[Abbreviation("OR")]
Oregon = 636029,
[Abbreviation("PA")]
Pennsylvania = 636025,
[Abbreviation("PE")]
[Description("Price Edward Island")]
PrinceEdwardIsland = 604426,
[Abbreviation("QC")]
Quebec = 604428,
[Abbreviation("RI")]
[Description("Rhode Island")]
RhodeIsland = 636052,
[Abbreviation("SK")]
Saskatchewan = 636044,
[Abbreviation("SC")]
[Description("South Carolina")]
SouthCarolina = 636005,
[Abbreviation("SD")]
[Description("South Dakota")]
SouthDakota = 636042,
[Abbreviation("TN")]
Tennessee = 636053,
[Description("US State Department")]
UsStateDepartment = 636027,
[Abbreviation("TX")]
Texas = 636015,
[Abbreviation("VI")]
[Description("US Virgin Islands")]
UsVirginIslands = 636062,
[Abbreviation("UT")]
Utah = 636040,
[Abbreviation("VT")]
Vermont = 636024,
[Abbreviation("VA")]
Virginia = 636000,
[Abbreviation("WA")]
Washington = 636045,
[Abbreviation("WV")]
[Description("West Virginia")]
WestVirginia = 636061,
[Abbreviation("WI")]
Wisconsin = 636031,
[Abbreviation("WY")]
Wyoming = 636060,
[Abbreviation("YT")]
Yukon = 604429
}

Expand Down
1 change: 1 addition & 0 deletions IdParser/IdParser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AbbreviationAttribute.cs" />
<Compile Include="DriversLicense.cs" />
<Compile Include="DriversLicenseJurisdiction.cs" />
<Compile Include="Height.cs" />
Expand Down

0 comments on commit 4778b47

Please sign in to comment.