Example #1
0
 public RegisterOutput Execute(
     FirstName firstName,
     LastName lastName,
     Personnummer personnummer,
     Email email,
     MobilePhoneNumber mobilePhoneNumber)
 {
Example #2
0
 public Customer(Personnummer ssn, Name name)
 {
     Id       = Guid.NewGuid();
     SSN      = ssn;
     Name     = name;
     Accounts = new AccountCollection();
 }
 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));
 }
        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);
        }
Example #5
0
        public static Customer LoadFromDetails(Guid id, Name name, Personnummer ssn, AccountCollection accounts)
        {
            Customer customer = new Customer();

            customer.Id       = id;
            customer.Name     = name;
            customer.SSN      = ssn;
            customer.Accounts = accounts;
            return(customer);
        }
 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));
 }
Example #7
0
        public void Valid_SSN_Should_Be_Created()
        {
            //
            // Arrange
            string valid = "08724050601";

            //
            // Act
            Personnummer SSN = new Personnummer(valid);

            // Assert
            Assert.Equal(valid, SSN);
        }
        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 +.
        }
 public void TestValid()
 {
     foreach (string key in ValidTestCases.Keys)
     {
         Personnummer personnummer = new Personnummer(key);
         TestResult   actual       = new TestResult()
         {
             Original    = personnummer.Original,
             LongForm    = personnummer.LongForm,
             ShortForm   = personnummer.ShortForm,
             IsTemporary = personnummer.IsTemporary,
             BirthDate   = personnummer.BirthDate
         };
         Assert.IsTrue(ValidTestCases[key].Equals(actual), key);
     }
 }
 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());
 }
        public async Task <RegisterOutput> Execute(Personnummer personnummer, Name name, Amount initialAmount)
        {
            Customer customer = new Customer(personnummer, name);

            Account account = new Account(customer.Id);

            account.Deposit(initialAmount);
            Credit credit = (Credit)account.GetLastTransaction();

            customer.Register(account.Id);

            await _customerWriteOnlyRepository.Add(customer);

            await _accountWriteOnlyRepository.Add(account, credit);

            RegisterOutput output = new RegisterOutput(customer, account);

            return(output);
        }
 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
     }));
 }
        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);
        }
 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
     }));
 }
Example #15
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
            }));
        }
        public void TestFutureBirthDate()
        {
            Personnummer personnummer = new Personnummer("801301015218");

            Assert.AreEqual(personnummer.BirthDate, DateTime.Parse("8013-01-1"));
        }