public void ShouldValidateCorrectApplication()
        {
            var sut = new ApplicationDetailsValidator(new AirlineMembershipNumberValidator());

            var a = new CreditCardApplication {
                AirlineFrequentFlyerNumber = "A1234567",
                ApplicantAgeInYears        = 44,
                ApplicantName = "Lisa"
            };

            var errors = sut.Validate(a);

            Assert.That(errors, Is.Empty);
        }
        public void ShouldValidateApplicationDetails()
        {
            var applicant = new CreditCardApplication
            {
                ApplicantName              = "John",
                ApplicantAgeInYears        = 25,
                AirlineFrequentFlyerNumber = "C1234567"
            };
            var sut = new ApplicationDetailsValidator(new AirlineMembershipNumberValidator());

            var results = sut.Validate(applicant);

            Assert.That(results, Is.Empty);
        }
        public void ShouldDetectInvalidAirlineNumber()
        {
            var fakeValidator = new Mock <IAirlineMembershipNumberValidator>();

            fakeValidator.Setup(x => x.IsValid(It.IsAny <string>())).Returns(false);


            var a = new CreditCardApplication();

            var sut = new ApplicationDetailsValidator(fakeValidator.Object);

            var errors = sut.Validate(a);

            Assert.That(errors, Has.Exactly(1).EqualTo("Airline membership number is invalid"));
        }
        public void ShouldDetectUseAirlineValidatorToCheckNumber()
        {
            var fakeValidator = new Mock <IAirlineMembershipNumberValidator>();

            var a = new CreditCardApplication
            {
                AirlineFrequentFlyerNumber = "x123"
            };

            var sut = new ApplicationDetailsValidator(fakeValidator.Object);

            sut.Validate(a);

            fakeValidator.Verify(x => x.IsValid("x123"), Times.Once());
        }
        public void ShouldDetectBlankName()
        {
            var fakeValidator = new Mock <IAirlineMembershipNumberValidator>();

            var a = new CreditCardApplication
            {
                ApplicantName = ""
            };

            var sut = new ApplicationDetailsValidator(fakeValidator.Object);

            var errors = sut.Validate(a);

            Assert.That(errors, Has.Exactly(1).EqualTo("Name cannot be blank."));
        }
示例#6
0
        public void ShouldValidateInCorrectApplication()
        {
            // Example of internal classes being integration tested together

            var sut = new ApplicationDetailsValidator(new AirlineMembershipNumberValidator());

            var a = new CreditCardApplication
            {
                ApplicantName              = "Lisa",
                ApplicantAgeInYears        = 44,
                AirlineFrequentFlyerNumber = "badnumber"
            };
            var errors = sut.Validate(a);

            Assert.That(errors, Is.Not.Empty);
        }
        public ApplicationDetails UpdateApplicationDetails(ApplicationDetails model)
        {
            ApplicationDetailsValidator applicationDetailsValidator = new ApplicationDetailsValidator(_bankAgencyRepository);

            //validate the form data
            ValidationResult validationResult = applicationDetailsValidator.Validate(model);

            model.UpdateSuccess = true;
            //if it's invalid prepare the error list to be handled on frontend side
            if(!validationResult.IsValid)
            {
                if(validationResult.Errors != null && validationResult.Errors.Count > 0)
                {
                    model.NumberOfErrors = validationResult.Errors.Count;
                    model.UpdateSuccess = false;
                    model.Errors = new List<ValidationFailure>();
                    List<string> sections = new List<string>();

                    for (int index = 0; index < validationResult.Errors.Count; index++)
                    {
                        ValidationFailure failure = validationResult.Errors[index];
                        //we need to know which sections have any errors so on the frontend we can mark them as red
                        GetSectionName(failure.PropertyName, sections);

                        model.Errors.Add(failure);
                    }
                    model.SectionsWithErrors = sections;
                }

                return model;

            }

            //Updates section

            //Update Applicant
            _applicantRepository.UpdateApplicant(model.Applicant);

            //Update Application

            _applicationRepository.UpdateApplication(model.Application);

            //Update Employment

            _employmentRepository.UpdateEmployment(model.Employment);

            //Update Address

            _addressRepository.UpdateAddress(model.Address);

            //Update Contacts

            List<Contact> contacts = new List<Contact>();

            contacts.Add(model.HomePhone);
            contacts.Add(model.EmailAddress);
            contacts.Add(model.MobilePhone);

            _contactRepository.UpdateContacts(contacts, model.Applicant.ApplicantId, model.Application.ApplicationId);

            //Update Bank Account

            _bankAccountRepository.UpdateBankAccount(model.BankAccount);

            //Update Bank Card

            _bankCardRepository.UpdateBankCard(model.BankCard);

            return model;
        }