Exemple #1
0
        public void TestaObterIdade()
        {
            // Arranjo
            var aluno = new Aluno();
            aluno.Nome = "Renato";
            aluno.Nascimento = DateTime.Parse("27/10/1972");

            // Ação
            var resultado = aluno.ObterIdade(aluno);

            // Assert
            Assert.AreEqual(42, resultado);
        }
Exemple #2
0
        public int ObterIdade(Aluno aluno)
        {
            var idade = DateTime.Now.Year - aluno.Nascimento.Year;
            if (DateTime.Now.Month < aluno.Nascimento.Month || (DateTime.Now.Month == aluno.
                Nascimento.Month && DateTime.Now.Day < aluno.Nascimento.Day))
            {
                idade--;
            }

            return idade;
        }
 static void Main(string[] args)
 {
     var aluno = new Aluno();
 }