Esempio n. 1
0
 public void TestValid(PersonnummerData ssn)
 {
     Assert.True(Personnummer.Valid(ssn.LongFormat));
     Assert.True(Personnummer.Valid(ssn.SeparatedLong));
     Assert.True(Personnummer.Valid(ssn.SeparatedFormat));
     Assert.True(Personnummer.Valid(ssn.ShortFormat));
 }
Esempio n. 2
0
        public void TestMaleFemale(PersonnummerData ssn)
        {
            Assert.Equal(ssn.IsMale, Personnummer.Parse(ssn.LongFormat, new Personnummer.Options {
                AllowCoordinationNumber = true
            }).IsMale);
            Assert.Equal(ssn.IsMale, Personnummer.Parse(ssn.SeparatedLong, new Personnummer.Options {
                AllowCoordinationNumber = true
            }).IsMale);
            Assert.Equal(ssn.IsMale, Personnummer.Parse(ssn.SeparatedFormat, new Personnummer.Options {
                AllowCoordinationNumber = true
            }).IsMale);
            Assert.Equal(ssn.IsMale, Personnummer.Parse(ssn.ShortFormat, new Personnummer.Options {
                AllowCoordinationNumber = true
            }).IsMale);

            Assert.Equal(ssn.IsFemale, Personnummer.Parse(ssn.LongFormat, new Personnummer.Options {
                AllowCoordinationNumber = true
            }).IsFemale);
            Assert.Equal(ssn.IsFemale, Personnummer.Parse(ssn.SeparatedLong, new Personnummer.Options {
                AllowCoordinationNumber = true
            }).IsFemale);
            Assert.Equal(ssn.IsFemale, Personnummer.Parse(ssn.SeparatedFormat, new Personnummer.Options {
                AllowCoordinationNumber = true
            }).IsFemale);
            Assert.Equal(ssn.IsFemale, Personnummer.Parse(ssn.ShortFormat, new Personnummer.Options {
                AllowCoordinationNumber = true
            }).IsFemale);
        }
Esempio n. 3
0
 public void TestFormatLong(PersonnummerData ssn)
 {
     Assert.Equal(ssn.SeparatedLong, Personnummer.Parse(ssn.SeparatedLong, new Personnummer.Options {
         AllowCoordinationNumber = true
     }).Format(true));
     Assert.Equal(ssn.SeparatedLong, Personnummer.Parse(ssn.SeparatedFormat, new Personnummer.Options {
         AllowCoordinationNumber = true
     }).Format(true));
     Assert.Equal(ssn.SeparatedLong, Personnummer.Parse(ssn.LongFormat, new Personnummer.Options {
         AllowCoordinationNumber = true
     }).Format(true));
 }
Esempio n. 4
0
        public void TestSeparator(PersonnummerData ssn)
        {
            string sep = ssn.SeparatedFormat.Contains('+') ? "+" : "-";

            Assert.Equal(sep, Personnummer.Parse(ssn.LongFormat, new Personnummer.Options {
                AllowCoordinationNumber = true
            }).Separator);
            Assert.Equal(sep, Personnummer.Parse(ssn.SeparatedLong, new Personnummer.Options {
                AllowCoordinationNumber = true
            }).Separator);
            Assert.Equal(sep, Personnummer.Parse(ssn.SeparatedFormat, new Personnummer.Options {
                AllowCoordinationNumber = true
            }).Separator);
            // Getting the separator from a short formatted none-separated person number is not actually possible if it is intended to be a +.
        }
Esempio n. 5
0
 public void TestFormat(PersonnummerData ssn)
 {
     Assert.Equal(ssn.SeparatedFormat, Personnummer.Parse(ssn.SeparatedLong, new Personnummer.Options {
         AllowCoordinationNumber = true
     }).Format());
     Assert.Equal(ssn.SeparatedFormat, Personnummer.Parse(ssn.SeparatedFormat, new Personnummer.Options {
         AllowCoordinationNumber = true
     }).Format());
     Assert.Equal(ssn.SeparatedFormat, Personnummer.Parse(ssn.LongFormat, new Personnummer.Options {
         AllowCoordinationNumber = true
     }).Format());
     // Short format will always guess that it's latest century.
     Assert.Equal(ssn.SeparatedFormat.Replace("+", "-"), Personnummer.Parse(ssn.ShortFormat, new Personnummer.Options {
         AllowCoordinationNumber = true
     }).Format());
 }
Esempio n. 6
0
 public void TestParse(PersonnummerData ssn)
 {
     Assert.IsType <Personnummer>(Personnummer.Parse(ssn.LongFormat, new Personnummer.Options
     {
         AllowCoordinationNumber = false
     }));
     Assert.IsType <Personnummer>(Personnummer.Parse(ssn.ShortFormat, new Personnummer.Options
     {
         AllowCoordinationNumber = false
     }));
     Assert.IsType <Personnummer>(Personnummer.Parse(ssn.SeparatedFormat, new Personnummer.Options
     {
         AllowCoordinationNumber = false
     }));
     Assert.IsType <Personnummer>(Personnummer.Parse(ssn.SeparatedLong, new Personnummer.Options
     {
         AllowCoordinationNumber = false
     }));
 }
Esempio n. 7
0
 public void TestCtrInvalid(PersonnummerData ssn)
 {
     Assert.Throws <PersonnummerException>(() => new Personnummer(ssn.LongFormat, new Personnummer.Options
     {
         AllowCoordinationNumber = false
     }));
     Assert.Throws <PersonnummerException>(() => new Personnummer(ssn.ShortFormat, new Personnummer.Options
     {
         AllowCoordinationNumber = false
     }));
     Assert.Throws <PersonnummerException>(() => new Personnummer(ssn.SeparatedFormat, new Personnummer.Options
     {
         AllowCoordinationNumber = false
     }));
     Assert.Throws <PersonnummerException>(() => new Personnummer(ssn.SeparatedLong, new Personnummer.Options
     {
         AllowCoordinationNumber = false
     }));
 }
Esempio n. 8
0
 public void TestCtrCn(PersonnummerData ssn)
 {
     Assert.IsType <Personnummer>(new Personnummer(ssn.LongFormat, new Personnummer.Options
     {
         AllowCoordinationNumber = true
     }));
     Assert.IsType <Personnummer>(new Personnummer(ssn.ShortFormat, new Personnummer.Options
     {
         AllowCoordinationNumber = true
     }));
     Assert.IsType <Personnummer>(new Personnummer(ssn.SeparatedFormat, new Personnummer.Options
     {
         AllowCoordinationNumber = true
     }));
     Assert.IsType <Personnummer>(new Personnummer(ssn.SeparatedLong, new Personnummer.Options
     {
         AllowCoordinationNumber = true
     }));
 }
Esempio n. 9
0
        public void TestAge(PersonnummerData ssn)
        {
            DateTime dt    = DateTime.ParseExact(ssn.LongFormat.Substring(0, ssn.LongFormat.Length - 4), "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None);
            int      years = DateTime.Now.Year - dt.Year;

            Assert.Equal(years, Personnummer.Parse(ssn.SeparatedLong, new Personnummer.Options {
                AllowCoordinationNumber = false
            }).Age);
            Assert.Equal(years, Personnummer.Parse(ssn.SeparatedFormat, new Personnummer.Options {
                AllowCoordinationNumber = false
            }).Age);
            Assert.Equal(years, Personnummer.Parse(ssn.LongFormat, new Personnummer.Options {
                AllowCoordinationNumber = false
            }).Age);
            // Du to age not being possible to fetch from >100 year short format without separator, we aught to check this here.
            Assert.Equal(years > 99 ? years - 100 : years, Personnummer.Parse(ssn.ShortFormat, new Personnummer.Options {
                AllowCoordinationNumber = false
            }).Age);
        }
Esempio n. 10
0
 public void TestParseInvalidCn(PersonnummerData ssn)
 {
     Assert.Throws <PersonnummerException>(() => Personnummer.Parse(ssn.LongFormat, new Personnummer.Options
     {
         AllowCoordinationNumber = true
     }));
     Assert.Throws <PersonnummerException>(() => Personnummer.Parse(ssn.ShortFormat, new Personnummer.Options
     {
         AllowCoordinationNumber = true
     }));
     Assert.Throws <PersonnummerException>(() => Personnummer.Parse(ssn.SeparatedFormat, new Personnummer.Options
     {
         AllowCoordinationNumber = true
     }));
     Assert.Throws <PersonnummerException>(() => Personnummer.Parse(ssn.SeparatedLong, new Personnummer.Options
     {
         AllowCoordinationNumber = true
     }));
 }
Esempio n. 11
0
        public void TestOrgNumber(PersonnummerData orgnr)
        {
            Assert.Throws <PersonnummerException>(() => Personnummer.Parse(orgnr.SeparatedFormat, new Personnummer.Options
            {
                AllowCoordinationNumber = true
            }));

            Assert.Throws <PersonnummerException>(() => Personnummer.Parse(orgnr.SeparatedFormat, new Personnummer.Options
            {
                AllowCoordinationNumber = false
            }));

            Assert.Throws <PersonnummerException>(() => Personnummer.Parse(orgnr.ShortFormat, new Personnummer.Options
            {
                AllowCoordinationNumber = true
            }));

            Assert.Throws <PersonnummerException>(() => Personnummer.Parse(orgnr.ShortFormat, new Personnummer.Options
            {
                AllowCoordinationNumber = false
            }));
        }