private static MailViewModel MapViewModel(EmailCobrancaAvaliacao email)
        {
            var viewModel = new MailViewModel();

            //viewModel.Email = email.Email;
            //viewModel.Ano = email.Avaliacao.Solicitacao.Ano;
            //viewModel.Seq = email.Avaliacao.Solicitacao.Seq;
            //viewModel.DataLimite = email.Avaliacao.DataLimite;
            //viewModel.FullName = email.Avaliacao.Solicitacao.User.FullName;
            //viewModel.IdAvaliacao = email.Avaliacao.Id;
            //viewModel.IdSolicitacao = email.Avaliacao.Solicitacao.Id;
            viewModel.InjectFrom <FlatLoopValueInjection>(email);
            return(viewModel);
        }
        public void MapViewModelTest()
        {
            EmailCobrancaAvaliacao email = GetEmailCompleto();
            MailViewModel          actual;

            actual = Program_Accessor.MapViewModel(email);
            Assert.AreEqual(actual.AvaliacaoSolicitacaoAno, email.Avaliacao.Solicitacao.Ano);
            Assert.AreEqual(actual.AvaliacaoSolicitacaoSeq, email.Avaliacao.Solicitacao.Seq);
            Assert.AreEqual(actual.AvaliacaoDataLimite, email.Avaliacao.DataLimite);
            Assert.AreEqual(actual.AvaliacaoSolicitacaoUserFullName, email.Avaliacao.Solicitacao.User.FullName);
            Assert.AreEqual(actual.AvaliacaoId, email.Avaliacao.Id);
            Assert.AreEqual(actual.AvaliacaoSolicitacaoUserEmail, email.Avaliacao.Solicitacao.User.Email);
            Assert.AreEqual(actual.AvaliacaoSolicitacaoId, email.Avaliacao.Solicitacao.Id);
        }
        public void EnviarEmailsTest()
        {
            EmailCobrancaAvaliacao emailCompleto        = GetEmailCompleto();
            IEnumerable <EmailCobrancaAvaliacao> emails = new EmailCobrancaAvaliacao[] {
                emailCompleto
            };

            Program_Accessor.EnviarEmails(emails);
            foreach (var email in emails)
            {
                Assert.IsTrue(email.Enviado, "Email deve ser marcado como enviado");
                Assert.IsTrue(DateTime.Now.Subtract(email.EnviadoEm) < new TimeSpan(0, 2, 0),
                              "Tempo desde o envio deve ser menor que 2 min");
            }
        }
        static private IEnumerable <EmailCobrancaAvaliacao> PreencherFila()
        {
            List <EmailCobrancaAvaliacao> result = new List <EmailCobrancaAvaliacao>();

            using (var db = new ReprografiaContext())
            {
                //Colocar na fila de emails avaliacoes com menos de 2 dias ate o prazo final
                //DateTime dateFilter = DateTime.Now.AddDays(100);
                DateTime dateFilter = DateTime.Now.AddDays(2);
                var      avaliacoesPrestesAExpirar = db.Avaliacoes
                                                     .Where(a => a.DataLimite <= dateFilter);

                foreach (var avaliacao in avaliacoesPrestesAExpirar)
                {
                    EmailCobrancaAvaliacao email = new EmailCobrancaAvaliacao(avaliacao);
                    result.Add(email);
                    db.Emails.Add(email);
                }
                db.SaveChanges();
            }
            return(result);
        }
        private static EmailCobrancaAvaliacao GetEmailCompleto()
        {
            EmailCobrancaAvaliacao emailCompleto = new EmailCobrancaAvaliacao()
            {
                Avaliacao = new Avaliacao()
                {
                    Id          = 1,
                    Solicitacao = new Solicitacao()
                    {
                        Id   = 1,
                        Seq  = 1,
                        Ano  = 2012,
                        User = new User()
                        {
                            Email = "*****@*****.**", FullName = "Paolo Haji de Carvalho Bueno"
                        }
                    },
                    DataLimite = DateTime.Now
                                 //, SolicitacaoId = 1
                },
            };

            return(emailCompleto);
        }