Exemplo n.º 1
0
        public void GivenAPlayerWithJustOneAtributeWhenValidatedThenShouldThrowAnException()
        {
            var players = new List <List <string> >
            {
                new List <string> {
                    "Player1", "P"
                },
                new List <string> {
                    "Player2"
                }
            };

            Assert.Throws <InvalidEnrollmentException>(() => _validator.Validate(players));
        }
Exemplo n.º 2
0
        public void Validate()
        {
            var validator        = new EnrollmentValidator();
            var validationResult = validator.Validate(this);

            if (!validationResult.IsValid)
            {
                throw new ValidationException(validationResult.Errors.Select(i => i.ErrorMessage));
            }
        }
Exemplo n.º 3
0
            public void WhenDateOfBirthIsMinDate_ThenExceptionIsThrown()
            {
                var enrollmentRecord = new Enrollment
                {
                    FirstName     = "Jane",
                    LastName      = "Doe",
                    DateOfBirth   = DateTime.MinValue,
                    PlanType      = EnrollmentPlanType.HSA,
                    EffectiveDate = DateTime.Today.AddDays(5)
                };

                var enrollmentValidator = new EnrollmentValidator();

                var isValid = enrollmentValidator.Validate(enrollmentRecord);
            }
Exemplo n.º 4
0
            public void WhenLastNameIsEmpty_ThenExceptionIsThrown()
            {
                var enrollmentRecord = new Enrollment
                {
                    FirstName     = "Jane",
                    LastName      = String.Empty,
                    DateOfBirth   = new DateTime(1983, 9, 13),
                    PlanType      = EnrollmentPlanType.HSA,
                    EffectiveDate = DateTime.Today.AddDays(5)
                };

                var enrollmentValidator = new EnrollmentValidator();

                var isValid = enrollmentValidator.Validate(enrollmentRecord);
            }
Exemplo n.º 5
0
            public void WhenPlanTypeIsNone_ThenExceptionIsThrown()
            {
                var enrollmentRecord = new Enrollment
                {
                    FirstName     = "Jane",
                    LastName      = "Doe",
                    DateOfBirth   = new DateTime(1975, 7, 28),
                    PlanType      = EnrollmentPlanType.None,
                    EffectiveDate = DateTime.Today.AddDays(5)
                };

                var enrollmentValidator = new EnrollmentValidator();

                var isValid = enrollmentValidator.Validate(enrollmentRecord);
            }
Exemplo n.º 6
0
            public void WhenEffectiveDateMoreThan30DaysInFuture_ThenReturnsFalse()
            {
                var effectiveDate = DateTime.Today.AddDays(53);

                var enrollmentRecord = new Enrollment
                {
                    FirstName     = "Jane",
                    LastName      = "Doe",
                    DateOfBirth   = new DateTime(1973, 3, 14),
                    PlanType      = EnrollmentPlanType.HSA,
                    EffectiveDate = effectiveDate
                };

                var enrollmentValidator = new EnrollmentValidator();

                var isValid = enrollmentValidator.Validate(enrollmentRecord);

                Assert.IsFalse(isValid);
            }
Exemplo n.º 7
0
            public void WhenDateOfBirthIsLessThan18_ThenReturnsFalse()
            {
                var dateOfBirth = DateTime.Today.AddYears(-1);

                var enrollmentRecord = new Enrollment
                {
                    FirstName     = "Jane",
                    LastName      = "Doe",
                    DateOfBirth   = dateOfBirth,
                    PlanType      = EnrollmentPlanType.HSA,
                    EffectiveDate = DateTime.Today.AddDays(3)
                };

                var enrollmentValidator = new EnrollmentValidator();

                var isValid = enrollmentValidator.Validate(enrollmentRecord);

                Assert.IsFalse(isValid);
            }
        public dynamic Post(string enrollmentNumber)
        {
            Enrollment enrollment = _enrollmentService.List().Single(x => x.ExternalId == enrollmentNumber);

            if (enrollment == null)
            {
                return(new BadRequestObjectResult(new { messages = new List <string> {
                                                            onboarding.Resources.Messages.EnrollmentLinkIsNotValid
                                                        } }));
            }

            if (!enrollment.IsDeadlineValid())
            {
                return(new BadRequestObjectResult(new { messages = new List <string> {
                                                            onboarding.Resources.Messages.OnboardingExpired
                                                        } }));
            }

            if (enrollment.SentAt.HasValue)
            {
                return(new BadRequestObjectResult(new { messages = new List <string> {
                                                            onboarding.Resources.Messages.EnrollmentInReview
                                                        } }));
            }

            string personalDataStatus = (new PersonalDataStatus(new PersonalDataValidator(_context), enrollment.PersonalData)).GetStatus();
            string financeDataStatus  = (new FinanceDataStatus(new FinanceDataValidator(_context), enrollment.FinanceData, new FinanceDataMessagesValidator(_context))).GetStatus();

            EnrollmentValidator enrollmentValidator = new EnrollmentValidator(_context);

            FluentValidation.Results.ValidationResult enrollmentValidatorResult = enrollmentValidator.Validate(enrollment);
            List <string> messages = enrollmentValidatorResult.Errors.Select(x => x.ErrorMessage).Distinct().ToList();

            if (personalDataStatus == "valid" && financeDataStatus == "valid" && enrollmentValidatorResult.IsValid)
            {
                string body        = GetEmailBody("enrollment_sent.html");
                string subject     = "Sua matricula foi enviada para análise";
                string messageBody = GetEmailBody("enrollment_sent.html")
                                     .Replace("{student_name}", enrollment.PersonalData.AssumedName)
                                     .Replace("{send_at}", enrollment.SentAt.Value.ToString("dd/MM/yyyy"))
                                     .Replace("{send_at_hour}", enrollment.SentAt.Value.ToString("HH:mm"));

                BackgroundJob.Enqueue(() => (new EmailHelper()).SendEmail(messageBody, subject, _configuration["EMAIL_SENDER"], enrollment.PersonalData.Email, _configuration["SMTP_USERNAME"], _configuration["SMTP_PASSWORD"]));

                enrollment.SentAt = DateTime.Now;
                _enrollmentService.Update(enrollment);

                return(Ok());
            }
            else
            {
                if (personalDataStatus != "valid")
                {
                    messages.Add("Os dados pessoais estão inválidos");
                }
                if (financeDataStatus != "valid")
                {
                    messages.Add("Os dados financeiros estão inválidos");
                }

                return(new BadRequestObjectResult(new { messages }));
            }
        }