public void ShouldReturnErroWhenActiveSubscription()
        {
            var paypalPayment = new PaypalPayment("12345678", DateTime.Now, DateTime.Now.AddDays(5), 10, 10, "Douglas Corp", _document, _address, _email);

            _subscription.AddPayments(paypalPayment);
            _student.AddSubscription(_subscription);
            _student.AddSubscription(_subscription);
            Assert.IsTrue(_student.Invalid);
        }
        public void ShouldReturnErrorWhenHadActiveSubscription()
        {
            var payment = new PayPalPayment("2535136357357357", DateTime.Now, DateTime.Now.AddDays(5), 10, 10, _document, "Empresas Stark", _address, _email);

            _subscription.AddPayments(payment);
            _student.AddSubscription(_subscription);
            _student.AddSubscription(_subscription);

            Assert.IsTrue(_student.Invalid);
        }
示例#3
0
        public ICommandResult Handle(CreateBoletoSubscriptionCommand command)
        {
            // Fail Fast Validations
            command.Validate();
            if (command.Invalid)
            {
                AddNotifications(command);
                return(new CommandResult(false, "Não foi possível realizar sua assinatura"));
            }

            // Verificar se Documento já está cadastrado
            if (_studentRepository.DocumentExists(command.Document))
            {
                AddNotification("Document", "Este CPF já está em uso");
            }

            // Verificar se Email já está cadastrado
            if (_studentRepository.DocumentExists(command.Email))
            {
                AddNotification("Email", "Este Email já está em uso");
            }

            //Gerar os VOs
            var name     = new Name(command.FirstName, command.LastName);
            var document = new Document(command.Document, EDocumentType.CPF);
            var email    = new Email(command.Email);
            var address  = new Address(command.Street, command.Number, command.Neighborhood, command.City, command.State, command.Country, command.ZipCode);

            // gerar as Entidades
            var student      = new Student(name, document, email);
            var subscription = new Subscription(DateTime.Now.AddMonths(1));
            var payment      = new BoletoPayment(command.BarCode, command.BoletoNumber,
                                                 command.PaidDate, command.ExpireDate,
                                                 command.Total, command.TotalPaid,
                                                 command.Payer, new Document(command.PayerDocuments,
                                                                             command.PayerDocumentsType), address, email);

            // Relacionamentos
            subscription.AddPayments(payment);
            student.AddSubscription(subscription);

            //Agrupar as Validações
            AddNotifications(name, document, email, address, student, subscription, subscription, payment);

            // Checar Notificações
            if (Invalid)
            {
                return(new CommandResult(false, "Não foi possível realizar sua assinatura"));
            }

            //Salvar as informações
            _studentRepository.CreateSubscription(student);

            // Enviar E-mail de boas vindas
            _emailService.Send(student.Name.ToString(), student.Email.Address, "Bem vindo ao Curso", "Sua assinatura foi assinada");
            // Retornar informações


            return(new CommandResult(true, "Assinatura realizada com sucesso"));
        }
示例#4
0
        public void ShouldReturnSuccessWhenAddSubscription()
        {
            var subscription = new Subscription(null);
            var payment      = new PayPalPayment("12345678", DateTime.Now, DateTime.Now.AddDays(5), 10, 10, "WAYNE CORP", _document, _address, _email);

            subscription.AddPayments(payment);
            _student.AddSubscription(subscription);
            Assert.IsTrue(_student.Valid);
        }
        public ICommandResult Handle(CreatePayPalSubscriptionCommand command)
        {
            //Fail Fast Validation
            command.Validate();
            if (command.Invalid)
            {
                AddNotifications(command);
                return(new CommandResult(false, "Não foi possível realizar a assinatura."));
            }

            //Verificar se documento já está cadastrado
            if (_studentRepository.DocumentExists(command.Document))
            {
                AddNotification("Document", "Este CPF já existe.");
            }


            //Varificar se E-mail já está cadastrado
            if (_studentRepository.EmailExists(command.Email))
            {
                AddNotification("Email", "Este email já existe.");
            }

            //Gerar VOs
            var name     = new Name(command.FirstName, command.LastName);
            var document = new Document(command.Document, EDocumentType.CPF);
            var email    = new Email(command.Email);
            var address  = new Address(command.Street, command.City, command.State, command.Country, command.ZipCode);

            //Gerar Entidades
            var student      = new Student(name, document, email);
            var subscription = new Subscription(DateTime.Now.AddMonths(1));
            var payment      = new PayPalPayment(command.TransactionCode, command.PaidDate, command.ExpireDate, command.Total, command.TotalPaid, new Document(command.PayerDocument, command.PayerDocumentType), command.Payer, address, email);

            //Relacionamentos
            subscription.AddPayments(payment);
            student.AddSubscription(subscription);

            //Aplicar validações
            AddNotifications(name, document, email, address, student, subscription, payment);

            //Check notificações
            if (Invalid)
            {
                return(new CommandResult(false, "Não foi possível realizar a assinatura."));
            }

            //Salvar as informações
            _studentRepository.CreateSubscription(student);

            //Enviar email de boas vindas
            _emailService.Send(name.ToString(), student.Email.Address, "Assinatura realizada com sucesso", "");

            return(new CommandResult(true, "Assinatura realizada com sucesso."));
        }
        public ICommandResult Handle(CreatePayPalSubscriptionCommand command)
        {
            /*command.Validate();
             * if(command.Invalid)
             * {
             *  AddNotifications(command);
             *  return new CommandResult(false, "Não foi possivel realizar sua assinatura");
             * }*/

            if (_studentRepository.DocumentExists(command.Document))
            {
                AddNotification("Document", "Este CPF já está em uso");
            }

            if (_studentRepository.DocumentExists(command.EnderecoEmail))
            {
                AddNotification("Document", "Este CPF já está em uso");
            }

            var _name         = new Name(command.FirstName, command.LastName);
            var _document     = new Document(command.Document, Domain.Enum.EDocumentType.CPF);
            var _email        = new Email(command.EnderecoEmail);
            var _address      = new Address(command.Rua, command.Bairro, command.Cidade, command.Estado, command.Pais, command.Complemento, command.Numero, command.CEP);
            var _student      = new Student(_name, _document, _email);
            var _subscription = new Subscription(DateTime.Now.AddMonths(1));

            var paypalPayment = new PaypalPayment(
                command.TransactionCode,
                command.PaidDate,
                command.ExpireDate,
                command.Total,
                command.TotalPaid,
                command.Owner,
                new Document(command.PayerDocument.Number, command.PayerDocumentType),
                _address,
                _email
                );

            _subscription.AddPayments(paypalPayment);
            _student.AddSubscription(_subscription);
            AddNotifications(_name, _document, _email, _address, _student, _subscription, paypalPayment);

            if (Invalid)
            {
                return(new CommandResult(false, "Não foi possivel realizar sua assinatura"));
            }

            _studentRepository.CreateSubscription(_student);
            _emailService.Send(_student.Name.ToString(), _student.Email.EnderecoEmail, "Bem vindo", "Sua assinatura foi criada");
            AddNotifications(new Contract());
            return(new CommandResult(true, "Assinatura realizada com sucesso"));
        }
示例#7
0
 public void ErrorWhenActiveSubscriptions()
 {
     _subscription.AddPayments(_payment);
     _student.AddSubscriptions(_subscription);
     Assert.IsTrue(_student.Valid);
 }