public void it_should_create_a_new_address_entity_if_one_is_not_present_and_update_the_address_from_the_address_view_model()
        {
            const int    expectedId       = 1;
            const string expectedLine1    = "Line 1";
            const int    expectedCounty   = 1;
            const int    expectedCountry  = 1;
            const string expectedPostcode = "BA2 3DQ";
            var          licence          = new Licence {
                Id = expectedId, Address = null
            };
            var model = new AddressViewModel
            {
                AddressLine1 = expectedLine1,
                CountyId     = expectedCounty,
                CountryId    = expectedCountry,
                Postcode     = expectedPostcode
            };

            licenceRepository.GetById(expectedId).Returns(licence);
            repository.Create <Address>().Returns(new Address());

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

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

            repository.Received(1).Create <Address>();
            repository.Received(1).Upsert(Arg.Is <Licence>(l =>
                                                           l.Address.AddressLine1.Equals(expectedLine1) && l.Address.CountyId == expectedCounty &&
                                                           l.Address.CountryId == expectedCountry && l.Address.Postcode.Equals(expectedPostcode)));
        }
Exemplo n.º 2
0
        public void it_creates_and_updates_a_new_principal_authority_if_one_does_not_exist()
        {
            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>()
            };
            var model = new FullNameViewModel {
                FullName = expectedName
            };

            licenceRepository.GetById(licenceId).Returns(licence);
            repository.GetById <DirectorOrPartner>(dopId).Returns(new DirectorOrPartner {
                Id = dopId
            });
            repository.Create <PrincipalAuthority>().Returns(new PrincipalAuthority {
                Id = paId
            });
            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 && p.Licence.Id == licenceId));
            repository.Received(1).Create <PrincipalAuthority>();
            repository.Received(1).GetById <DirectorOrPartner>(dopId);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Imports the specified j object.
        /// </summary>
        /// <param name="jObject">The j object.</param>
        /// <returns></returns>
        public PersonSearch Import(JObject jObject)
        {
            //todo map this
            var search = new Search();

            #region Create PersonSearchResult Entity

            var personSearch = PersonSearchResultFactory.Create(search, null, jObject);

            var log = logger.With("PersonSearchResult", personSearch);

            #endregion Create PersonSearchResult Entity

            #region Log Data Problems

            if (!string.IsNullOrWhiteSpace(personSearch.Warnings))
            {
                log.WarningEvent("Search", "FindPerson api result returned with warning messages");
            }
            if (!string.IsNullOrWhiteSpace(personSearch.Error))
            {
                log.ErrorEvent("Search", "FindPerson api result returned with error message");
            }
            if (string.IsNullOrWhiteSpace(personSearch.Data))
            {
                log.ErrorEvent("Search", "FindPerson api result returned with no person data");;
            }

            #endregion Log Data Problems

            #region Save Entity to Database

            Repository.Create(personSearch);
            Repository.Save();

            #endregion Save Entity to Database

            return(personSearch);
        }
        public async Task UpdateAddressAsync(string email, AddressViewModel model)
        {
            var user = userManager.FindCompleteUserByEmail(email);

            if (user.Address == null)
            {
                user.Address = repository.Create <Address>();
            }

            mapper.Map(model, user.Address);

            await userManager.UpdateAsync(user);
        }
        public void UpdateStatus(AdminLicenceViewModel model)
        {
            var statusChange = repository.Create <LicenceStatusChange>();

            statusChange.Licence               = repository.GetById <Licence>(model.Licence.Id);
            statusChange.DateCreated           = dateTimeProvider.Now();
            statusChange.Status                = repository.GetById <LicenceStatus>(model.NewLicenceStatus);
            statusChange.Reason                = repository.GetById <StatusReason>(model.NewStatusReason);
            statusChange.NonCompliantStandards = model.Standards.Where(x => x.Checked)
                                                 .Select(y => repository.GetById <LicenceStatusChangeLicensingStandard>(y.Id)).ToList();
            statusChange.Licence.CurrentStatusChange = statusChange;
            repository.Upsert(statusChange.Licence);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Builds this instance.
        /// </summary>
        /// <param name="repository">The repository.</param>
        public static void Build(IEntityFrameworkRepository repository)
        {
            var personSearch = MockDataFactory.GetPersonSearch();

            repository.Create(personSearch);
            repository.Save();

            var person = MockDataFactory.GetPerson(personSearch.Id);

            repository.Create(person);
            repository.Save();

            var addresses = MockDataFactory.GetAddresses(person.Id);

            foreach (var address in addresses)
            {
                repository.Create(address);
                repository.Save();
            }

            var associates = MockDataFactory.GetAssociates(person.Id);

            foreach (var associate in associates)
            {
                repository.Create(associate);
                repository.Save();
            }

            var phones = MockDataFactory.GetPhones(person.Id);

            foreach (var phone in phones)
            {
                repository.Create(phone);
                repository.Save();
            }
        }
        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 CreatePersonWithAddresses()
        {
            //Arrange
            var personSearch = MockDataFactory.GetPersonSearch();

            Repository.Create(personSearch);
            Repository.Save();

            //Act
            var person = MockDataFactory.GetPerson(personSearch.Id);

            Repository.Create(person);
            Repository.Save();

            var addresses = MockDataFactory.GetAddresses(person.Id);

            foreach (var address in addresses)
            {
                Repository.Create(address);
                Repository.Save();
            }

            var savedPerson    = Repository.GetFirst <Person>(x => x.Id == person.Id);
            var savedAddresses = Repository.Get <Address>(x => x.PersonId == person.Id);

            //Assert
            Assert.Equal(person.Id, savedPerson.Id);
            Assert.Equal(person.FirstName, savedPerson.FirstName);
            Assert.Equal(person.LastName, savedPerson.LastName);
            Assert.Equal(person.Alias, savedPerson.Alias);
            Assert.Equal(person.AgeRange, savedPerson.AgeRange);
            Assert.Equal(addresses.Count(), savedAddresses.Count());
            Assert.Equal(addresses.Count(), savedPerson.Addresses.Count());

            foreach (var savedAddress in savedAddresses)
            {
                var anyAddress = addresses.Any(x => x.Id == savedAddress.Id);
                Assert.True(anyAddress);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Searches the specified person.
        /// </summary>
        /// <param name="serach">The search criteria.</param>
        /// <param name="searchWaitMs">The search wait in ms.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">person</exception>
        public async Task <PersonSearch> SearchAsync(Search search, int searchWaitMs, CancellationToken cancellationToken)
        {
            if (search == null)
            {
                throw new ArgumentNullException(nameof(search));
            }

            var log = logger.With("search", search);

            var stopwatch = new Stopwatch();

            try
            {
                stopwatch.Start();

                var person = Mapper.Map <Models.Domain.Api.Request.Person>(search);
                log.DebugEvent("Search", "Mapped PersonSearchRequest entity to Person domain model after {ms}ms", stopwatch.ElapsedMilliseconds);

                #region Execute Find Person request

                var result = await FindPersonController.GetFindPerson(person);

                await Task.Delay(searchWaitMs);

                log.With("Person", person)
                .InformationEvent("Search", "Executed Find Person request after {ms}ms", stopwatch.ElapsedMilliseconds);

                var jObject = JObject.Parse(result.Content);

                log.ForContext("Content", jObject);

                #endregion Execute Find Person request

                #region Save Response to JSON text file

                var fullPath = Path.Combine(this.ResultOutputPath, $"SearchJob-{person.Name}");
                await this.Export.ToJsonAsync(jObject, fullPath, cancellationToken);

                #endregion Save Response to JSON text file

                #region Create PersonSearchResult Entity

                var personSearch = PersonSearchResultFactory.Create(search, result.StatusCode, jObject);

                log.With("PersonSearchResult", personSearch);

                #endregion Create PersonSearchResult Entity

                #region Log Data Problems

                if (!string.IsNullOrWhiteSpace(personSearch.Warnings))
                {
                    log.WarningEvent("Search", "FindPerson api result returned with warning messages");
                }
                if (!string.IsNullOrWhiteSpace(personSearch.Error))
                {
                    log.ErrorEvent("Search", "FindPerson api result returned with error message");
                }
                if (string.IsNullOrWhiteSpace(personSearch.Data))
                {
                    log.ErrorEvent("Search", "FindPerson api result returned with no person data");;
                }

                #endregion Log Data Problems

                //todo fix all of this
                #region Save Entity to Database

                Repository.Create(personSearch);
                Repository.Save();

                #endregion Save Entity to Database

                stopwatch.Stop();
                log.DebugEvent("Search", "Finished processing person search result after {ms}ms", stopwatch.ElapsedMilliseconds);

                return(personSearch);
            }
            catch (Exception ex)
            {
                //Log and throw
                log.ErrorEvent(ex, "Search", "Processing person failed after {ms}ms", stopwatch.ElapsedMilliseconds);
                throw;
            }
        }
        public int Insert(LicenceApplicationViewModel model)
        {
            var licence = repository.Create <Licence>();

            var address = repository.Create <Address>();

            licence.Address = address;

            repository.Upsert(licence);

            licence.ApplicationId = CreateDraftURN(licence.Id);
            UpdateStatus(licence, model);

            repository.Upsert(licence);

            return(licence.Id);
        }