private async Task Valida_Tratamento_De_Professor_Ja_Incluso_No_Curso_Deve_Retornar_True()
        {
            // Arrange
            var professorCurso  = new ProfessorCursoEol(1234567, 1010, 6);
            var professorGoogle = new ProfessorGoogle(1234567, "José da Silva", "*****@*****.**", string.Empty);
            var cursoGoogle     = new CursoGoogle("Curso Google", "Seção", 1010, 6, "*****@*****.**");

            mediator.Setup(a => a.Send(It.IsAny <ObterProfessoresPorRfsQuery>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new List <ProfessorGoogle> {
                professorGoogle
            });

            mediator.Setup(a => a.Send(It.IsAny <ObterCursoPorTurmaComponenteCurricularQuery>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(cursoGoogle);

            mediator.Setup(a => a.Send(It.IsAny <ExisteProfessorCursoGoogleQuery>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(true);

            var professorCursoJson = JsonConvert.SerializeObject(professorCurso);
            var mensagem           = new MensagemRabbit(professorCursoJson);

            // Act
            var retorno = await inserirProfessorCursoGoogleUseCase.Executar(mensagem);

            // Assert
            Assert.True(retorno);
        }
Beispiel #2
0
        private async Task InserirProfessorGoogleAsync(ProfessorGoogle professorGoogle)
        {
            try
            {
                var professorSincronizado = await mediator.Send(new InserirProfessorGoogleCommand(professorGoogle));

                if (!professorSincronizado)
                {
                    await mediator.Send(new IncluirUsuarioErroCommand(professorGoogle?.Rf, professorGoogle?.Email,
                                                                      $"Não foi possível incluir o professor no Google Classroom. {professorGoogle}", UsuarioTipo.Professor, ExecucaoTipo.ProfessorAdicionar));

                    return;
                }

                await InserirProfessorAsync(professorGoogle);
            }
            catch (GoogleApiException gEx)
            {
                if (gEx.EhErroDeDuplicidade())
                {
                    await InserirProfessorAsync(professorGoogle);
                }
                else
                {
                    throw;
                }
            }
        }
        private async Task Valida_Tratamento_De_Excecoes_Ao_Comunicar_Com_Google_Deve_Devolver_A_Excecao_Disparada()
        {
            // Arrange
            var professorCurso  = new ProfessorCursoEol(1234567, 1010, 6);
            var professorGoogle = new ProfessorGoogle(1234567, "José da Silva", "*****@*****.**", string.Empty);
            var cursoGoogle     = new CursoGoogle("Curso Google", "Seção", 1010, 6, "*****@*****.**");

            mediator.Setup(a => a.Send(It.IsAny <ObterProfessoresPorRfsQuery>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new List <ProfessorGoogle> {
                professorGoogle
            });

            mediator.Setup(a => a.Send(It.IsAny <ObterCursoPorTurmaComponenteCurricularQuery>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(cursoGoogle);

            mediator.Setup(a => a.Send(It.IsAny <ExisteProfessorCursoGoogleQuery>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(false);

            var excecao = new NullReferenceException("Erro ao se comunicar Google Classroom.");

            mediator.Setup(a => a.Send(It.IsAny <InserirProfessorCursoGoogleCommand>(), It.IsAny <CancellationToken>()))
            .Throws(excecao);

            mediator.Setup(a => a.Send(It.IsAny <IncluirCursoUsuarioCommand>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(10);

            var professorCursoJson = JsonConvert.SerializeObject(professorCurso);
            var mensagem           = new MensagemRabbit(professorCursoJson);

            // Assert
            await Assert.ThrowsAsync <NullReferenceException>(() => inserirProfessorCursoGoogleUseCase.Executar(mensagem));
        }
Beispiel #4
0
        private async Task InserirProfessorCursoGoogleAsync(ProfessorGoogle professorGoogle, CursoGoogle cursoGoogle, bool existeProfessorCursoLocal)
        {
            var professorCursoGoogle = new ProfessorCursoGoogle(professorGoogle.Indice, cursoGoogle.Id);

            try
            {
                var professorCursoSincronizado = !existeProfessorCursoLocal && await mediator.Send(new InserirProfessorCursoGoogleCommand(professorCursoGoogle, professorGoogle.Email));

                if (professorCursoSincronizado && !existeProfessorCursoLocal)
                {
                    await InserirProfessorCursoAsync(professorCursoGoogle);
                }
            }
            catch (GoogleApiException gEx)
            {
                if (gEx.EhErroDeDuplicidade())
                {
                    await InserirProfessorCursoAsync(professorCursoGoogle);
                }
                else
                {
                    throw;
                }
            }
        }
        private async Task IncluirCursoDoProfessorComErroAsync(ProfessorGoogle professorEol, string mensagem)
        {
            var command = new IncluirCursoUsuarioErroCommand(
                professorEol.Rf,
                ExecucaoTipo.ProfessorCursoAdicionar,
                ErroTipo.Negocio,
                mensagem);

            await mediator.Send(command);
        }
        public void Valida_Tratamento_Da_Formatacao_De_Nomes_Passandos_Os_Resultados_Esperados(string nome, string sobrenomeEsperado, string nomeEsperado)
        {
            // Arrange
            var professor = new ProfessorGoogle(1, nome, "email", "organizationPath");

            // Assert
            Assert.NotNull(professor);
            Assert.Equal(sobrenomeEsperado, professor.Sobrenome);
            Assert.Equal(nomeEsperado, professor.Nome);
        }
Beispiel #7
0
        private async Task IniciarSyncGoogleCursosDoProfessorAsync(ProfessorGoogle professorGoogle)
        {
            //var publicarCursosDoProfessor = await mediator.Send(new PublicaFilaRabbitCommand(RotasRabbit.FilaProfessorCursoSync, RotasRabbit.FilaProfessorCursoSync, professorGoogle));
            var trataSyncGoogleCursosDoProfessorUseCase = new TrataSyncGoogleCursosDoProfessorUseCase(mediator);
            var publicarCursosDoProfessor = await trataSyncGoogleCursosDoProfessorUseCase.Executar(new MensagemRabbit(JsonConvert.SerializeObject(professorGoogle)));

            if (!publicarCursosDoProfessor)
            {
                await mediator.Send(new IncluirUsuarioErroCommand(professorGoogle?.Rf, professorGoogle?.Email,
                                                                  $"O professor RF {professorGoogle?.Rf} foi incluído com sucesso, mas não foi possível iniciar a sincronização dos cursos deste professor.", UsuarioTipo.Professor, ExecucaoTipo.ProfessorCursoAdicionar));
            }
        }
Beispiel #8
0
        public async Task <bool> Executar(MensagemRabbit mensagemRabbit)
        {
            if (mensagemRabbit.Mensagem is null)
            {
                throw new NegocioException("Não foi possível incluir o professor. A mensagem enviada é inválida.");
            }

            var professorParaIncluir = JsonConvert.DeserializeObject <ProfessorEol>(mensagemRabbit.Mensagem.ToString());

            if (professorParaIncluir is null)
            {
                return(true);
            }

            try
            {
                var professorGoogle = new ProfessorGoogle(professorParaIncluir.Rf, professorParaIncluir.Nome, professorParaIncluir.Email, professorParaIncluir.OrganizationPath);

                var professorJaIncluido = await mediator.Send(new ExisteProfessorPorRfQuery(professorGoogle.Rf));

                if (professorJaIncluido)
                {
                    var professor = await mediator.Send(new ObterProfessoresPorRfsQuery(professorGoogle.Rf));

                    professorGoogle.GoogleClassroomId = professor?.FirstOrDefault()?.GoogleClassroomId;
                    await IniciarSyncGoogleCursosDoProfessorAsync(professorGoogle);

                    return(true);
                }

                await InserirProfessorGoogleAsync(professorGoogle);

                return(true);
            }
            catch (Exception ex)
            {
                await mediator.Send(new IncluirUsuarioErroCommand(professorParaIncluir?.Rf, professorParaIncluir?.Email,
                                                                  $"ex.: {ex.Message} <-> msg rabbit: {mensagemRabbit}. StackTrace:{ex.StackTrace}.", UsuarioTipo.Professor, ExecucaoTipo.ProfessorAdicionar));

                throw;
            }
        }
Beispiel #9
0
        public async Task <bool> Executar(MensagemRabbit mensagemRabbit)
        {
            var filtro = JsonConvert.DeserializeObject <AlunoCursoEol>(mensagemRabbit.Mensagem.ToString());

            try
            {
                var alunoCursoGoogle = new AlunoCursoGoogle();

                var aluno = await mediator.Send(new ObterUsuariosPorCodigosQuery(filtro.CodigoRF, (int)UsuarioTipo.Professor));

                if (aluno is null || !aluno.Any())
                {
                    var professorEol = new ProfessorEol(filtro.CodigoRF, filtro.NomePessoa, filtro.NomeSocial ?? string.Empty, filtro.OrganizationPath);

                    var professorGoogle = new ProfessorGoogle(filtro.CodigoRF, professorEol.Nome, professorEol.Email, filtro.OrganizationPath);
                    var indiceInserido  = await InserirProfessorGoogleAsync(professorGoogle);

                    if (indiceInserido > 0)
                    {
                        var usuarioGsa         = new UsuarioGsa(filtro.CodigoRF.ToString(), professorEol.Email, filtro.NomePessoa, null, false, filtro.OrganizationPath, false, DateTime.Now);
                        var usuarioGsaInserido = await mediator.Send(new IncluirUsuarioGsaCommand(usuarioGsa));

                        alunoCursoGoogle = new AlunoCursoGoogle(indiceInserido, filtro.CursoId);
                        await InserirAlunoCursoGoogleAsync(alunoCursoGoogle, professorEol.Email);
                    }
                    else
                    {
                        filtro.MensagemErro += $" Inserido: {indiceInserido}";
                        await mediator.Send(new PublicaFilaRabbitCommand(RotasRabbit.FilaGsaFormacaoCidadeTurmasTratarAlunoErro, filtro));
                    }
                }
                else
                {
                    var alunoFirst = aluno.FirstOrDefault();
                    alunoCursoGoogle = new AlunoCursoGoogle(alunoFirst.Indice, filtro.CursoId);
                    await InserirAlunoCursoGoogleAsync(alunoCursoGoogle, alunoFirst.Email);
                }
            }
        private async Task RemoverProfessorCursoGoogleAsync(ProfessorGoogle professorGoogle, CursoUsuario cursoUsuario)
        {
            try
            {
                var professorCursoRemovido = await mediator.Send(new RemoverProfessorCursoGoogleCommand(cursoUsuario.CursoId, professorGoogle.Email));

                if (professorCursoRemovido)
                {
                    await RemoverProfessorCursoAsync(cursoUsuario);
                }
            }
            catch (GoogleApiException gEx)
            {
                if (gEx.RegistroNaoEncontrado())
                {
                    await RemoverProfessorCursoAsync(cursoUsuario);
                }
                else
                {
                    throw;
                }
            }
        }
        private async Task IncluirProfessorNoGoogle(ProfessorGoogle professorGoogle, DirectoryService diretorioClassroom)
        {
            var usuarioParaIncluirNoGoogle = new User
            {
                Name = new UserName {
                    FamilyName = professorGoogle.Sobrenome, GivenName = professorGoogle.PrimeiroNome, FullName = professorGoogle.Nome
                },
                PrimaryEmail = professorGoogle.Email,
                OrgUnitPath  = professorGoogle.OrganizationPath,
                Password     = configuration["GoogleClassroomConfig:PasswordPadraoParaUsuarioNovo"],
                ChangePasswordAtNextLogin = true
            };

            var requestCreate   = diretorioClassroom.Users.Insert(usuarioParaIncluirNoGoogle);
            var usuarioIncluido = await requestCreate.ExecuteAsync();

            if (usuarioIncluido is null)
            {
                throw new NegocioException("Não foi possível obter o professor incluído no Google Classroom.");
            }

            professorGoogle.GoogleClassroomId = usuarioIncluido.Id;
        }
Beispiel #12
0
 public InserirProfessorGoogleCommand(ProfessorGoogle professorGoogle)
 {
     ProfessorGoogle = professorGoogle;
 }
Beispiel #13
0
 private async Task InserirProfessorAsync(ProfessorGoogle professorGoogle)
 {
     professorGoogle.Indice = await mediator.Send(new IncluirUsuarioCommand(professorGoogle));
     await IniciarSyncGoogleCursosDoProfessorAsync(professorGoogle);
 }
 public IncluirUsuarioCommand(ProfessorGoogle professorGoogle)
     : this(usuarioGoogle : professorGoogle)
 {
     Id = professorGoogle.Rf;
 }