public void CalculateAge_Equal3Years_Return2() { DateTime birth = DateTime.Now.AddYears(-3); var target = new DateTimeService(); int result = target.CalculateAge(birth); Assert.AreEqual(2, result); }
public void CalculateAge_MoreThan3_YearsReturn3() { DateTime birth = DateTime.Now.AddYears(-3).AddDays(-1); var target = new DateTimeService(); int result = target.CalculateAge(birth); Assert.AreEqual(3, result); }
public void CalculateAge_BirthNull_Return0() { DateTime?birth = null; var target = new DateTimeService(); int result = target.CalculateAge(birth); Assert.AreEqual(0, result); }
public AutoMapperProfile() { IDateTimeService dateTimeService = new DateTimeService(); this.CreateMap <Person, PersonForListDto>() .ForMember(member => member.Age, memberOpt => { memberOpt.MapFrom(value => dateTimeService.CalculateAge(value.BirthDate)); }) .ReverseMap(); }