public async Task Handle_DataForCountry_NonUk()
        {
            // Arrange
            A.CallTo(() => unitedKingdomCompetentAuthorityRepository.IsCountryUk(countryWithDataId)).Returns(false);

            // Act
            var result = await handler.HandleAsync(new GetCompetentAuthoritiesAndEntryPointsByCountryId(countryWithDataId, UKCompetentAuthority.England));

            // Assert
            A.CallTo(() => unitedKingdomCompetentAuthorityRepository.IsCountryUk(countryWithDataId)).MustHaveHappened();
            A.CallTo(() => entryOrExitPointRepository.GetForCountry(countryWithDataId)).MustHaveHappened();
            A.CallTo(() => repository.GetCompetentAuthorities(countryWithDataId));
        }
        public async Task <CompetentAuthorityAndEntryOrExitPointData> HandleAsync(
            GetCompetentAuthoritiesAndEntryPointsByCountryId message)
        {
            IEnumerable <CompetentAuthority> competentAuthorities;
            var isUk = await this.unitedKingdomCompetentAuthorityRepository.IsCountryUk(message.CountryId);

            var entryOrExitPoints = (await entryOrExitPointRepository.GetForCountry(message.CountryId));

            if (isUk)
            {
                var ids = (await intraCountryExportAllowedRepository.GetImportCompetentAuthorities(message.NotificationUkCompetentAuthority))
                          .Select(x => x.ImportCompetentAuthorityId).ToList();
                competentAuthorities = (await competentAuthorityRepository.GetByIds(ids));
            }
            else
            {
                competentAuthorities = (await competentAuthorityRepository.GetCompetentAuthorities(message.CountryId));
            }

            return(new CompetentAuthorityAndEntryOrExitPointData
            {
                CompetentAuthorities = competentAuthorities.Select(competentAuthorityMapper.Map).ToArray(),
                EntryOrExitPoints = entryOrExitPoints.Select(entryOrExitPointMapper.Map).ToArray()
            });
        }
Beispiel #3
0
        public async Task <bool> HandleAsync(CheckEntryOrExitPointUnique message)
        {
            var entryOrExitPoints = await entryOrExitPointRepository.GetForCountry(message.CountryId);

            return
                (!entryOrExitPoints.Any(eep => eep.Name.Equals(message.Name, StringComparison.InvariantCultureIgnoreCase)));
        }
        public GetCompetentAuthoritiesAndEntryPointsByCountryIdHandlerTests()
        {
            entryOrExitPointRepository                = A.Fake <IEntryOrExitPointRepository>();
            intraCountryExportAllowedRepository       = A.Fake <IIntraCountryExportAllowedRepository>();
            unitedKingdomCompetentAuthorityRepository = A.Fake <IUnitedKingdomCompetentAuthorityRepository>();
            var iwsContext = new TestIwsContext();

            var countryWithData      = CountryFactory.Create(countryWithDataId);
            var unitedKingdomCountry = CountryFactory.Create(unitedKingdomCountryId);
            var countryWithNoData    = CountryFactory.Create(countryWithNoDataId);

            competentAuthorities = new[]
            {
                CompetentAuthorityFactory.Create(new Guid("67D2B3B5-298A-4BB5-901C-0C0C80097242"), unitedKingdomCountry),
                CompetentAuthorityFactory.Create(new Guid("5E7CA40F-D7B5-49C3-8850-694D36D52C94"), countryWithData),
                CompetentAuthorityFactory.Create(new Guid("DFD98B0D-F255-4BA0-96A5-527DE9F973E3"), countryWithData)
            };

            A.CallTo(() => unitedKingdomCompetentAuthorityRepository.GetAll()).Returns(new[]
            {
                new TestableUnitedKingdomCompetentAuthority(1, competentAuthorities[0], "something", null)
            });

            var competentAuthorityMapper = new CompetentAuthorityMap();
            var entryOrExitPointMapper   = new EntryOrExitPointMap();

            A.CallTo(() => entryOrExitPointRepository.GetForCountry(countryWithDataId)).Returns(new[]
            {
                EntryOrExitPointFactory.Create(new Guid("FC012C3E-4252-4D62-A8A2-D46DE0FA93B9"), countryWithData),
                EntryOrExitPointFactory.Create(new Guid("9699CC16-6EF1-4889-9598-F4B0511A2038"), countryWithData)
            });

            A.CallTo(() => intraCountryExportAllowedRepository.GetImportCompetentAuthorities(UKCompetentAuthority.England)).Returns(new[]
            {
                new TestableIntraCountryExportAllowed
                {
                    ExportCompetentAuthority   = UKCompetentAuthority.England,
                    ImportCompetentAuthorityId = competentAuthorities[1].Id
                }
            });

            repository = A.Fake <ICompetentAuthorityRepository>();

            A.CallTo(() => repository.GetCompetentAuthorities(countryWithDataId)).Returns(competentAuthorities);

            ids = new Guid[]
            {
                competentAuthorities[1].Id
            };

            A.CallTo(repository).Where(call => call.Method.Name == "GetByIds")
            .WithReturnType <CompetentAuthority[]>()
            .Returns(competentAuthorities);

            handler = new GetCompetentAuthoritiesAndEntryPointsByCountryIdHandler(entryOrExitPointMapper, competentAuthorityMapper, repository, entryOrExitPointRepository, intraCountryExportAllowedRepository, iwsContext, unitedKingdomCompetentAuthorityRepository);
        }
        public async Task <CompetentAuthorityAndEntryOrExitPointData> HandleAsync(
            GetTransitAuthoritiesAndEntryOrExitPointsByCountryId message)
        {
            var competentAuthorities = (await competentAuthorityRepository.GetTransitAuthorities(message.Id));

            var entryOrExitPoints = await entryOrExitPointRepository.GetForCountry(message.Id);

            return(new CompetentAuthorityAndEntryOrExitPointData
            {
                CompetentAuthorities = competentAuthorities.Select(competentAuthorityMapper.Map).ToArray(),
                EntryOrExitPoints = entryOrExitPoints.Select(entryOrExitPointMapper.Map).ToArray()
            });
        }
        public async Task <CompetentAuthorityAndEntryOrExitPointData> HandleAsync(GetUnitedKingdomCompetentAuthoritiesAndEntryOrExitPoints message)
        {
            var countryId = await countryRepository.GetUnitedKingdomId();

            var competentAuthorities = await competentAuthorityRepository.GetCompetentAuthorities(countryId);

            var entryOrExitPoints = await entryOrExitPointRepository.GetForCountry(countryId);

            return(new CompetentAuthorityAndEntryOrExitPointData
            {
                CompetentAuthorities =
                    competentAuthorities.Select(ca => mapper.Map <CompetentAuthorityData>(ca)).ToArray(),
                EntryOrExitPoints = entryOrExitPoints.Select(eep => mapper.Map <EntryOrExitPointData>(eep)).ToArray()
            });
        }
        public async Task <IList <EntryOrExitPointData> > HandleAsync(GetEntryOrExitPointsByCountry message)
        {
            var entryOrExitPoints = await entryOrExitPointRepository.GetForCountry(message.CountryId);

            return(entryOrExitPoints.Select(mapper.Map).ToArray());
        }