Esempio n. 1
0
        public void CalculateAge_Equal3Years_Return2()
        {
            DateTime birth = DateTime.Now.AddYears(-3);

            var target = new DateTimeService();

            int result = target.CalculateAge(birth);

            Assert.AreEqual(2, result);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public void CalculateAge_BirthNull_Return0()
        {
            DateTime?birth = null;

            var target = new DateTimeService();

            int result = target.CalculateAge(birth);

            Assert.AreEqual(0, result);
        }
Esempio n. 4
0
        public AutoMapperProfile()
        {
            IDateTimeService dateTimeService = new DateTimeService();

            this.CreateMap <Person, PersonForListDto>()
            .ForMember(member => member.Age, memberOpt =>
            {
                memberOpt.MapFrom(value => dateTimeService.CalculateAge(value.BirthDate));
            })
            .ReverseMap();
        }