Пример #1
0
        public Rematricular_aluno()
        {
            _pessoaFisica = PessoaFisicaStub.PessoaMenorDeIdade;
            _responsavel  = PessoaFisicaStub.PessoaMaiorDeIdade;

            _aluno = new Aluno(_alunoId, _pessoaFisica, _responsavel, _matricula);
            _aluno.Transferir();

            _escola = new Escola(_escolaId, _escolaNome);
            _escola.AdicionarSala(_salaId, _salaFaseAno, Turno.Matutino);

            var mockAlunoRepository        = new Mock <IAlunoRepository>();
            var mockPessoaFisicaRepository = new Mock <IPessoaFisicaRepository>();
            var mockEscolaRepository       = new Mock <IEscolaRepository>();
            var mockMatriculaService       = new Mock <IMatriculaService>();

            mockAlunoRepository.Setup(x => x.GetByEntityIdAsync(It.IsAny <Guid>()))
            .Returns(Task.FromResult(_aluno));

            mockAlunoRepository.Setup(x => x.AddAsync(It.IsAny <Aluno>()))
            .Callback((Aluno a) => { _aluno = a; });

            mockPessoaFisicaRepository.Setup(x => x.GetByEntityIdAsync(It.IsAny <Guid>()))
            .Returns((Guid entityId) =>
            {
                if (entityId == _pessoaFisica.EntityId)
                {
                    return(Task.FromResult(_pessoaFisica));
                }
                if (entityId == _responsavel.EntityId)
                {
                    return(Task.FromResult(_responsavel));
                }

                return(Task.FromResult <PessoaFisica>(null));
            });

            mockEscolaRepository.Setup(x => x.GetByEntityIdAsync(It.IsAny <Guid>()))
            .Returns(Task.FromResult(_escola));

            mockMatriculaService.Setup(x => x.GerarMatriculaAsync())
            .Returns(Task.FromResult(_matricula));

            _service = new AlunoService(mockAlunoRepository.Object,
                                        mockPessoaFisicaRepository.Object,
                                        mockEscolaRepository.Object,
                                        mockMatriculaService.Object);

            TestAsyncHelper.CallSync(() => _service.RematricularAsync(_alunoId, _responsavel.EntityId, _escolaId, _salaId).Wait());
        }
Пример #2
0
        public Matricular_aluno()
        {
            _matricula   = _fixture.Create <int>();
            _alunoId     = _fixture.Create <Guid>();
            _salaId      = _fixture.Create <Guid>();
            _salaFaseAno = _fixture.Create <string>();
            _escola      = EscolaStub.EscolaValida;

            _pessoaFisica = PessoaFisicaStub.PessoaMenorDeIdade;
            _responsavel  = PessoaFisicaStub.PessoaMaiorDeIdade;


            _escola.AdicionarSala(_salaId, _salaFaseAno, Turno.Matutino);

            _mockAlunoRepository.Setup(x => x.AddAsync(It.IsAny <Aluno>()))
            .Callback((Aluno a) => { _aluno = a; });

            _mockPessoaFisicaRepository.Setup(x => x.GetByEntityIdAsync(It.IsAny <Guid>()))
            .Returns((Guid entityId) =>
            {
                if (entityId == _pessoaFisica.EntityId)
                {
                    return(Task.FromResult(_pessoaFisica));
                }
                if (entityId == _responsavel.EntityId)
                {
                    return(Task.FromResult(_responsavel));
                }

                return(Task.FromResult <PessoaFisica>(null));
            });

            _mockEscolaRepository.Setup(x => x.GetByEntityIdAsync(It.IsAny <Guid>()))
            .Returns(Task.FromResult(_escola));

            _mockMatriculaService.Setup(x => x.GerarMatriculaAsync())
            .Returns(Task.FromResult(_matricula));

            _service = new AlunoService(_mockAlunoRepository.Object,
                                        _mockPessoaFisicaRepository.Object,
                                        _mockEscolaRepository.Object,
                                        _mockMatriculaService.Object);

            TestAsyncHelper.CallSync(() => _service.MatricularAsync(_alunoId, _pessoaFisica.EntityId, _responsavel.EntityId, _escola.EntityId, _salaId).Wait());
        }
Пример #3
0
        public Transferir_aluno()
        {
            _pessoaFisica = PessoaFisicaStub.PessoaMenorDeIdade;
            _responsavel  = PessoaFisicaStub.PessoaMaiorDeIdade;

            _escola = new Escola(_escolaId, _escolaNome);
            _escola.AdicionarSala(_salaId, _salaFaseAno, Turno.Matutino);

            _aluno = new Aluno(_alunoId, _pessoaFisica, _responsavel, 1334);

            var mockAlunoRepository        = new Mock <IAlunoRepository>();
            var mockPessoaFisicaRepository = new Mock <IPessoaFisicaRepository>();
            var mockEscolaRepository       = new Mock <IEscolaRepository>();
            var mockMatriculaService       = new Mock <IMatriculaService>();

            mockAlunoRepository.Setup(x => x.GetByEntityIdAsync(It.IsAny <Guid>()))
            .Returns(Task.FromResult(_aluno));

            mockPessoaFisicaRepository.Setup(x => x.GetByEntityIdAsync(It.IsAny <Guid>()))
            .Returns((Guid entityId) =>
            {
                if (entityId == _pessoaFisica.EntityId)
                {
                    return(Task.FromResult(_pessoaFisica));
                }
                if (entityId == _responsavel.EntityId)
                {
                    return(Task.FromResult(_responsavel));
                }

                return(Task.FromResult <PessoaFisica>(null));
            });

            mockEscolaRepository.Setup(x => x.GetByEntityIdAsync(It.IsAny <Guid>()))
            .Returns(Task.FromResult(_escola));

            mockEscolaRepository.Setup(x => x.ObterPorAlunoIdAsync(It.IsAny <Guid>()))
            .Returns((Guid entityId) =>
            {
                if (entityId == _alunoId)
                {
                    return(Task.FromResult(_escola));
                }

                return(Task.FromResult <Escola>(null));
            });

            mockEscolaRepository.Setup(x => x.RemoverAlunoPorAsync(It.IsAny <Guid>(), It.IsAny <Guid>())).Returns((Guid escola, Guid alunoId) =>
            {
                var sala = _escola.Salas.SingleOrDefault(x => x.Alunos.Any(y => y.Aluno.EntityId == alunoId));

                _escola.RemoverAluno(sala.EntityId, _aluno);

                return(Task.CompletedTask);
            });

            mockMatriculaService.Setup(x => x.GerarMatriculaAsync())
            .Returns(Task.FromResult(_matricula));

            _service = new AlunoService(mockAlunoRepository.Object,
                                        mockPessoaFisicaRepository.Object,
                                        mockEscolaRepository.Object,
                                        mockMatriculaService.Object);

            TestAsyncHelper.CallSync(() => _service.MatricularAsync(_alunoId, _pessoaFisica.EntityId, _responsavel.EntityId, _escolaId, _salaId).Wait());
            TestAsyncHelper.CallSync(() => _service.TransferirAsync(_alunoId).Wait());
        }