public void ShouldCalculateAge()
        {
            var sut = new AgeCalculator();

            var today = new DateTime(2020, 2, 8);

            Assert.Equal(0, sut.Calculate(today, new DateTime(2020, 2, 8)));
            Assert.Equal(17, sut.Calculate(today, new DateTime(2002, 2, 9)));
            Assert.Equal(18, sut.Calculate(today, new DateTime(2002, 2, 8)));
            Assert.Equal(18, sut.Calculate(today, new DateTime(2001, 2, 9)));
            Assert.Equal(30, sut.Calculate(today, new DateTime(1990, 2, 8)));
        }
示例#2
0
        public void ShouldCalculateAge(string dob, string today, int age)
        {
            var birthday = DateTime.ParseExact(dob, "yyyyMMdd", CultureInfo.InvariantCulture);
            var now      = DateTime.ParseExact(today, "yyyyMMdd", CultureInfo.InvariantCulture);

            if (age == 8)
            {
            }
            var result = AgeCalculator.Calculate(birthday, now);

            Assert.AreEqual(age, result);
        }
        public void Calculate_Should_Return_8_When_BirthDate_Is_2000_02_29_And_Today_Is_2009_02_28()
        {
            // Arrange
            DateTime bDay = new DateTime(2000, 2, 29);
            DateTime now  = new DateTime(2009, 2, 28);

            // Act
            int age = AgeCalculator.Calculate(now, bDay);

            // Assert
            Assert.Equal(8, age);
        }
        public void Should_Return_32_One_Month_Past_DateOfBirth()
        {
            int age = AgeCalculator.Calculate(new DateTime(1978, 9, 27), new DateTime(2010, 10, 27));

            Assert.AreEqual(32, age);
        }
        public void Should_Return_31_One_Day_Before_DateOfBirth()
        {
            int age = AgeCalculator.Calculate(new DateTime(1978, 9, 27), new DateTime(2010, 9, 26));

            Assert.AreEqual(31, age);
        }
 public void Should_Throw_ArgumentException_When_Reference_Is_Before_DateOfBirth()
 {
     AgeCalculator.Calculate(DateTime.MaxValue, DateTime.MinValue);
 }
示例#7
0
 public int GetAge() => AgeCalculator.Calculate(DateTime.Today, BirthDate);