public void a_blank_model_is_invalid()
        {
            var vm = new DirectorOrPartnerCollectionViewModel();

            vm.Validate();

            Assert.IsFalse(vm.IsValid);
        }
 public AdminLicenceViewModel()
 {
     Licence             = new LicenceApplicationViewModel();
     OrganisationDetails = new OrganisationDetailsViewModel();
     PrincipalAuthority  = new PrincipalAuthorityViewModel();
     AlternativeBusinessRepresentatives = new AlternativeBusinessRepresentativeCollectionViewModel();
     DirectorsOrPartners = new DirectorOrPartnerCollectionViewModel();
     NamedIndividuals    = new NamedIndividualCollectionViewModel();
     Organisation        = new OrganisationViewModel();
 }
        public void a_model_with_no_count_is_invalid()
        {
            var vm = new DirectorOrPartnerCollectionViewModel
            {
                NumberOfDirectorsOrPartners = null,
                DirectorsOrPartners         = new[] { validModel }
            };

            vm.Validate();

            Assert.IsFalse(vm.IsValid);
        }
        public void a_model_with_required_directors_and_with_a_matching_count_is_valid()
        {
            var vm = new DirectorOrPartnerCollectionViewModel
            {
                DirectorsRequired           = true,
                NumberOfDirectorsOrPartners = 1,
                DirectorsOrPartners         = new[] { validModel }
            };

            vm.Validate();

            Assert.IsTrue(vm.IsValid);
        }
        public void a_model_without_required_directors_and_with_a_count_is_valid()
        {
            var vm = new DirectorOrPartnerCollectionViewModel
            {
                DirectorsRequired           = false,
                NumberOfDirectorsOrPartners = 0,
                DirectorsOrPartners         = new DirectorOrPartnerViewModel[0]
            };

            vm.Validate();

            Assert.IsTrue(vm.IsValid);
        }
        public void a_model_with_a_mismatched_number_of_directors_is_invalid()
        {
            var vm = new DirectorOrPartnerCollectionViewModel
            {
                DirectorsRequired           = false,
                NumberOfDirectorsOrPartners = 0,
                DirectorsOrPartners         = new[] { validModel }
            };

            vm.Validate();

            Assert.IsFalse(vm.IsValid);
        }
        public void a_model_without_required_directors_and_no_count_is_invalid()
        {
            var vm = new DirectorOrPartnerCollectionViewModel
            {
                DirectorsRequired           = false,
                NumberOfDirectorsOrPartners = null,
                DirectorsOrPartners         = new[] { validModel }
            };

            vm.Validate();

            Assert.IsFalse(vm.IsValid);
        }
        public void a_model_with_required_directors_and_no_directors_is_invalid()
        {
            var vm = new DirectorOrPartnerCollectionViewModel
            {
                DirectorsRequired           = true,
                NumberOfDirectorsOrPartners = 1,
                DirectorsOrPartners         = new DirectorOrPartnerViewModel[0]
            };

            vm.Validate();

            Assert.IsFalse(vm.IsValid);
        }
        public void a_model_without_required_directors_and_with_a_matching_count_and_incomplete_directors_is_invalid()
        {
            validModel.FullName.FullName = null;
            var vm = new DirectorOrPartnerCollectionViewModel
            {
                DirectorsRequired           = false,
                NumberOfDirectorsOrPartners = 1,
                DirectorsOrPartners         = new[] { validModel }
            };

            vm.Validate();

            Assert.IsFalse(vm.IsValid);
        }
        public void a_model_with_more_than_one_principal_authority_is_invalid()
        {
            validModel.IsPreviousPrincipalAuthority.IsPreviousPrincipalAuthority = true;
            var vm = new DirectorOrPartnerCollectionViewModel
            {
                DirectorsRequired           = false,
                NumberOfDirectorsOrPartners = 2,
                DirectorsOrPartners         = new[] { validModel, validModel }
            };

            vm.Validate();

            Assert.IsFalse(vm.IsValid);
        }
        public IActionResult SaveDirectorsOrPartners(DirectorOrPartnerCollectionViewModel model)
        {
            Session.SetSubmittedPage(FormSection.DirectorsOrPartners, 2);

            model = RepopulateDropdowns(model);

            if (!ModelState.IsValid)
            {
                return(View(GetViewPath(FormSection.DirectorsOrPartners, 2), model));
            }

            LicenceApplicationPostDataHandler.Update(Session.GetCurrentLicenceId(), x => x, model);

            return(RedirectToAction(FormSection.DirectorsOrPartners, 3));
        }
        public void it_should_not_map_the_principal_authority_entity_to_the_director_or_partner_view_model_if_they_are_not_a_director()
        {
            var pa = new PrincipalAuthority();

            AddPersonData(pa);
            pa.IsDirector = false;

            var input = new Licence
            {
                PrincipalAuthorities = new List <PrincipalAuthority>
                {
                    pa
                },
                NumberOfDirectorsOrPartners = 0
            };

            var output = new DirectorOrPartnerCollectionViewModel();
            var result = this.mapper.Map(input, output);

            Assert.AreEqual(0, result.NumberOfDirectorsOrPartners);
            Assert.IsFalse(result.DirectorsOrPartners.Any());
        }
        public void it_should_map_director_or_partner_entities_and_principal_authority_entities_to_the_director_or_partner_collection_view_model()
        {
            var dop = new DirectorOrPartner();

            AddPersonData(dop);

            var pa = new PrincipalAuthority();

            AddPersonData(pa);
            pa.IsDirector = true;

            var input = new Licence
            {
                DirectorOrPartners = new List <DirectorOrPartner>
                {
                    dop
                },
                PrincipalAuthorities = new List <PrincipalAuthority>
                {
                    pa
                },
                NumberOfDirectorsOrPartners = 1
            };

            var output = new DirectorOrPartnerCollectionViewModel();
            var result = this.mapper.Map(input, output);

            Assert.AreEqual(1, result.NumberOfDirectorsOrPartners);

            foreach (var dopVm in result.DirectorsOrPartners)
            {
                AssertPerson(dop, dopVm);
                Assert.AreEqual(dop.RequiresVisa, dopVm.RightToWorkViewModel.RequiresVisa);
                Assert.AreEqual(dop.VisaDescription, dopVm.RightToWorkViewModel.VisaDescription);
            }
        }