Example #1
0
 public void Apply()
 {
     if (_team.Name.Value == "Tinder" &&
         DateTimeHelpers.CalculateAge(_contact.DateOfBirth.Value) < 18)
     {
         throw new ContactException("To join to tinder team, the age cannnot be less than 18 years.");
     }
 }
Example #2
0
        public void NormalUse()
        {
            var today = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day);

            //leave the clock work (avoid .NET runtime optimizations)
            System.Threading.Thread.Sleep(100);

            var minusTenYearsOld = today.AddYears(10);
            var tenYearsOld      = today.AddYears(-10);

            Assert.AreEqual(-10, DateTimeHelpers.CalculateAge(minusTenYearsOld));
            Assert.AreEqual(10, DateTimeHelpers.CalculateAge(tenYearsOld));
            Assert.AreEqual(0, DateTimeHelpers.CalculateAge(today));
        }
Example #3
0
        public DateOfBirth(DateTime value)
        {
            if (value == DateTime.MinValue)
            {
                throw new ContactException("Invalid value.");
            }

            if (value == DateTime.MaxValue)
            {
                throw new ContactException("Invalid value.");
            }

            if (DateTimeHelpers.CalculateAge(value) < 16)
            {
                throw new ContactException("The age cannnot be less than 16 years.");
            }

            Value = value.Date;
        }