public void AlunoServiceSuccess() { var alunoBusinessMock = new Mock <IAlunoBusiness>(); alunoBusinessMock.Setup( a => a.Add(It.IsAny <Aluno>())).Returns(true); var alunosExpectancy = new List <Aluno> { new Aluno() { Id = 1, Key = Guid.NewGuid(), Nome = "AAA" }, new Aluno() { Id = 2, Key = Guid.NewGuid(), Nome = "BBB" } }; alunoBusinessMock.Setup(a => a.GetList()).Returns(alunosExpectancy); var alunoService = new AlunoService(alunoBusinessMock.Object); var alunos = alunoService.Insert(null); Assert.NotNull(alunos); Assert.True(alunos.Any()); for (var index = 0; index < alunos.Count; index++) { Assert.Equal(alunosExpectancy[index].Id, alunos[index].Id); Assert.Equal(alunosExpectancy[index].Key, alunos[index].Key); Assert.Equal(alunosExpectancy[index].Nome, alunos[index].Nome); } }
static void Main(string[] args) { var alunoRepository = new AlunoRepository(); var turmaRepository = new TurmaRepository(); var alunoBusiness = new AlunoBusiness(alunoRepository); var turmaBusiness = new TurmaBusiness(turmaRepository); var alunoService = new AlunoService(alunoBusiness); var turmaService = new TurmaService(turmaBusiness); var alunos = alunoService.Insert(new Aluno { Id = 1, Nome = "AAAA" }); var turmas = turmaService.Insert(new Turma { Numero = "101", Periodo = Domain.ValueObj.Periodo.noite, Alunos = new List <Aluno>() { new Aluno { Id = 1, Nome = "AAAA" }, new Aluno { Id = 1, Nome = "BBBB" }, new Aluno { Id = 1, Nome = "CCCC" } } }); Console.WriteLine($"{alunos.Any()} {alunos.Count()} {alunos[0].Nome}"); Console.WriteLine($"{turmas.Any()} {turmas.Count()} {turmas[0].Numero}"); }
public IActionResult Create(Aluno aluno) { if (!ModelState.IsValid) // verificacao, validando dados { var turmas = _turmaService.FindAll(); var viewModel = new AlunoFormViewModel { Aluno = aluno, Turmas = turmas }; return(View(viewModel)); } _alunoService.Insert(aluno); return(RedirectToAction(nameof(Index))); }
public void TestaInclusao() { AlunoService alunoService = new AlunoService(); COBOL.Entidades.Aluno aluno = new COBOL.Entidades.Aluno { CPF = 1234567, Nome = "Aluno 1", Logradouro = "Rua Aluno", Telefone = 11223344 }; var retorno = alunoService.Insert(aluno); Assert.True(retorno != null); }
public async Task <IActionResult> Criar(AlunosFormViewModel aluno) { await _AlunoService.Insert(aluno); return(RedirectToAction(nameof(Index))); }