public void it_should_create_new_licence_and_address_entities_and_return_the_licence_id()
        {
            const int expectedId = 1;

            var licence = new Licence {
                Id = 1
            };

            repository.Create <Licence>().Returns(licence);
            repository.Create <Address>().Returns(new Address());
            repository.Upsert(Arg.Any <Licence>()).ReturnsForAnyArgs(1);
            repository.GetById <Licence>(expectedId).Returns(licence);

            var pdh = new LicenceApplicationPostDataHandler(mapper, repository, licenceRepository, statusRepository,
                                                            dateTimeProvider);
            var result = pdh.Insert(new LicenceApplicationViewModel());

            Assert.AreEqual(expectedId, result);
            repository.Received().Create <Licence>();
            repository.Received().Create <Address>();
        }
        public void it_should_update_the_licence_field_from_the_model()
        {
            const int    expectedId   = 1;
            const string expectedName = "Name";
            var          licence      = new Licence {
                Id = expectedId, BusinessName = string.Empty
            };
            var model = new BusinessNameViewModel {
                BusinessName = expectedName
            };

            licenceRepository.GetById(expectedId).Returns(licence);

            var pdh = new LicenceApplicationPostDataHandler(mapper, repository, licenceRepository, statusRepository, dateTimeProvider);

            pdh.Update(expectedId, l => l, model);

            repository.Received(1).Upsert(Arg.Is <Licence>(l => l.BusinessName == expectedName));
        }
Exemplo n.º 3
0
        public void it_updates_a_principal_authority_that_is_linked_to_a_director()
        {
            const int    licenceId    = 1;
            const int    paId         = 2;
            const int    dopId        = 3;
            const string expectedName = "Name";
            var          licence      = new Licence
            {
                Id = licenceId,
                PrincipalAuthorities = new List <PrincipalAuthority>
                {
                    new PrincipalAuthority
                    {
                        Id = paId,
                        DirectorOrPartner = new DirectorOrPartner
                        {
                            Id = dopId
                        }
                    }
                }
            };
            var model = new FullNameViewModel {
                FullName = expectedName
            };

            licenceRepository.GetById(licenceId).Returns(licence);
            repository.Upsert(Arg.Any <PrincipalAuthority>()).Returns(paId);

            var pdh    = new LicenceApplicationPostDataHandler(mapper, repository, licenceRepository, statusRepository, dateTimeProvider);
            var result = pdh.UpsertPrincipalAuthorityAndLinkToDirectorOrPartner(licenceId, dopId, paId, model);

            Assert.AreEqual(paId, result);
            repository.Received(1).Upsert(Arg.Is <PrincipalAuthority>(p => p.FullName.Equals(expectedName) && p.DirectorOrPartner.Id == dopId));
            repository.Received(0).Create <PrincipalAuthority>();
            repository.Received(0).GetById <DirectorOrPartner>(Arg.Any <int>());
        }