public void When_Not_Yet_Born_Throws_Exception(int year, int month, int day, int birthNumber, int checksum) { var personalIdentityNumber = new PersonalIdentityNumber(year, month, day, birthNumber, checksum); var ex = Assert.Throws <ArgumentException>(() => personalIdentityNumber.GetAgeHint(_date_2000_04_14)); Assert.Contains("The person is not yet born.", ex.Message); }
private void AddPersonalIdentityNumberProperties(Dictionary <string, string> properties, Dictionary <string, double> metrics, PersonalIdentityNumber personalIdentityNumber) { if (_options.LogUserPersonalIdentityNumber) { properties.Add(PropertyName_UserSwedishPersonalIdentityNumber, personalIdentityNumber?.To12DigitString() ?? string.Empty); } if (_options.LogUserPersonalIdentityNumberHints) { properties.Add(PropertyName_UserDateOfBirthHint, personalIdentityNumber?.GetDateOfBirthHint().ToString("yyyy-MM-dd") ?? string.Empty); properties.Add(PropertyName_UserGenderHint, personalIdentityNumber?.GetGenderHint().ToString() ?? string.Empty); var ageHint = personalIdentityNumber?.GetAgeHint(); if (ageHint != null) { metrics.Add(PropertyName_UserAgeHint, ageHint.Value); } } }
public void Without_Date_Uses_UtcNow() { var personalIdentityNumber = new PersonalIdentityNumber(1899, 09, 13, 980, 1); Assert.Equal(personalIdentityNumber.GetAgeHint(DateTime.UtcNow), personalIdentityNumber.GetAgeHint()); }
public void When_Younger_Than_100_Years_Calculates_Age(int year, int month, int day, int birthNumber, int checksum, int expectedAge) { var personalIdentityNumber = new PersonalIdentityNumber(year, month, day, birthNumber, checksum); Assert.Equal(expectedAge, personalIdentityNumber.GetAgeHint(_date_2018_07_15)); }