Exemplo n.º 1
0
        public NotificationTransportRouteTests()
        {
            this.transportRoute = new TransportRoute(Guid.Empty);

            guids = new List <Guid>
            {
                new Guid("D8DB53F9-D3CB-498D-B044-7A67B94EE4E4"),
                new Guid("1D3A7A18-F345-4201-81AA-8FC8A4029F4E"),
                new Guid("596E6BE3-D0C1-4C17-AF75-BFCDBD972627"),
                new Guid("208EA94D-638B-4724-9272-DF1383FF9452"),
                new Guid("DEDAA6F6-CA6D-486E-B0B8-254A477E697F"),
                new Guid("4C7EEA30-510E-45BD-8DBB-3EC1AF5E563A"),
                new Guid("8B87B87D-43D0-4BBE-8E2C-8EC84C983A42"),
                new Guid("40E44905-4CDE-4470-8E8B-527EE65C65DC"),
                new Guid("58E18F1C-5A4A-4E2E-869F-72D9C1512FE8")
            };

            countries = guids.Select(g => CountryFactory.Create(g)).ToList();

            transitStates = new List <TransitState>();
            for (int i = 0; i < countries.Count - 1; i++)
            {
                var c = countries[i];
                transitStates.Add(new TransitState(c,
                                                   CompetentAuthorityFactory.Create(guids[i], c),
                                                   EntryOrExitPointFactory.Create(guids[i], c),
                                                   EntryOrExitPointFactory.Create(guids[i + 1], c), i + 1));
                ObjectInstantiator <TransitState> .SetProperty(x => x.Id, guids[i], transitStates[i]);
            }

            this.validator = A.Fake <ITransportRouteValidator>();
        }
Exemplo n.º 2
0
        public void SetStateOfImport_SameCountryToStateOfExportIfNoSameCountryExportsAllowed_Throws()
        {
            // Arrange
            var exportCountry = countries[0];

            var exportCompetentAuthority = CompetentAuthorityFactory.Create(guids[0], exportCountry);
            var exportExitPoint          = EntryOrExitPointFactory.Create(guids[0], exportCountry);

            var importCompetentAuthority = CompetentAuthorityFactory.Create(guids[1], exportCountry);
            var importExitPoint          = EntryOrExitPointFactory.Create(guids[1], exportCountry);

            var stateOfExport = new StateOfExport(exportCountry,
                                                  exportCompetentAuthority,
                                                  exportExitPoint);

            var stateOfImport = new StateOfImport(exportCountry,
                                                  importCompetentAuthority,
                                                  importExitPoint);

            A.CallTo(() => this.validator.IsImportAndExportStatesCombinationValid(null, stateOfExport)).Returns(true);
            A.CallTo(() => this.validator.IsImportAndExportStatesCombinationValid(stateOfImport, stateOfExport)).Returns(false);

            // Act
            var intraCountryExportAlloweds = new TestableIntraCountryExportAllowed[0];

            transportRoute.SetStateOfExportForNotification(stateOfExport, this.validator);

            // Assert
            Assert.Throws <InvalidOperationException>(() => transportRoute.SetStateOfImportForNotification(stateOfImport, this.validator));
        }
        public GetCompetentAuthoritiesAndEntryOrExitPointsByCountryIdHandlerTests()
        {
            var entryOrExitPointRepository = A.Fake <IEntryOrExitPointRepository>();

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

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

            var competentAuthorities = new[]
            {
                CompetentAuthorityFactory.Create(new Guid("C74A75B9-C338-4330-A43A-3AAF3B8FA5E7"), countryWithData),
                CompetentAuthorityFactory.Create(new Guid("B076AF57-83EB-4F99-BDE6-859CC2B35FBE"), countryWithData)
            };

            A.CallTo(() => entryOrExitPointRepository.GetForCountry(countryWithDataId)).Returns(new[]
            {
                EntryOrExitPointFactory.Create(new Guid("B054CA23-18D3-4E4E-A2B1-F92B7503919A"), countryWithData),
                EntryOrExitPointFactory.Create(new Guid("9F0DC969-8224-4FEC-BD0D-B90B70378323"), countryWithData)
            });

            var repository = A.Fake <ICompetentAuthorityRepository>();

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

            handler = new GetCompetentAuthoritiesAndEntryOrExitPointsByCountryIdHandler(entryOrExitPointMapper, competentAuthorityMapper, repository, entryOrExitPointRepository);
        }
Exemplo n.º 4
0
        private static TransitState TransitState(Country country, string name)
        {
            var ca    = CompetentAuthorityFactory.Create(Guid.Empty, country);
            var state = new TransitState(country, ca, EntryOrExitPointFactory.Create(Guid.Empty, country, name), EntryOrExitPointFactory.Create(Guid.NewGuid(), country, name), 1);

            return(state);
        }
Exemplo n.º 5
0
        public StateOfImportValidatorTests()
        {
            var countryRepo   = A.Fake <ICountryRepository>();
            var caRepo        = A.Fake <ICompetentAuthorityRepository>();
            var exitPointRepo = A.Fake <IEntryOrExitPointRepository>();

            var uk   = CountryFactory.Create(ukId, "United Kingdom");
            var ukCa = CompetentAuthorityFactory.Create(ukCaId, uk);

            var france   = CountryFactory.Create(Guid.NewGuid(), "France");
            var franceCa = CompetentAuthorityFactory.Create(nonUkCaId, france);

            A.CallTo(() => countryRepo.GetUnitedKingdomId()).Returns(ukId);

            A.CallTo(() => caRepo.GetById(ukCaId)).Returns(ukCa);
            A.CallTo(() => caRepo.GetById(nonUkCaId)).Returns(franceCa);

            var dover  = EntryOrExitPointFactory.Create(ukEntryPointId, uk);
            var calais = EntryOrExitPointFactory.Create(nonUkEntryPointId, france);

            A.CallTo(() => exitPointRepo.GetById(ukEntryPointId)).Returns(dover);
            A.CallTo(() => exitPointRepo.GetById(nonUkEntryPointId)).Returns(calais);

            validator = new StateOfImportValidator(countryRepo, caRepo, exitPointRepo);
        }
        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);
        }
Exemplo n.º 7
0
        public void UpdateTransitState_ValidUpdate_SetsCorrectValue()
        {
            transportRoute.AddTransitStateToNotification(transitStates[0]);

            transportRoute.AddTransitStateToNotification(transitStates[1]);

            transportRoute.UpdateTransitStateForNotification(transitStates[1].Id, countries[1],
                                                             CompetentAuthorityFactory.Create(guids[0], countries[1]),
                                                             EntryOrExitPointFactory.Create(guids[0], countries[1]),
                                                             EntryOrExitPointFactory.Create(guids[2], countries[1]), null);

            Assert.Equal(guids[2], transportRoute.TransitStates.Single(ts => ts.Id == transitStates[1].Id).ExitPoint.Id);
        }
Exemplo n.º 8
0
        public void UpdateTransitState_SetToSameCountryAsExisting_AddsToNotification()
        {
            transportRoute.AddTransitStateToNotification(transitStates[0]);

            transportRoute.AddTransitStateToNotification(transitStates[1]);

            transportRoute.UpdateTransitStateForNotification(transitStates[1].Id, countries[0],
                                                             CompetentAuthorityFactory.Create(guids[0], countries[0]),
                                                             EntryOrExitPointFactory.Create(guids[0], countries[0]),
                                                             EntryOrExitPointFactory.Create(guids[1], countries[0]), null);

            Assert.Equal(2, transportRoute.TransitStates.Count());
        }
        public SetExitCustomsOfficeForNotificationByIdHandlerTests()
        {
            this.context = new TestIwsContext();
            var repository = A.Fake <ITransportRouteRepository>();

            anyNotification = NotificationApplicationFactory.Create(TestIwsContext.UserId, NotificationType.Recovery, UKCompetentAuthority.England, 0);
            EntityHelper.SetEntityId(anyNotification, notificationId);

            transport = new TransportRoute(notificationId);

            context.NotificationApplications.Add(anyNotification);
            context.TransportRoutes.Add(transport);

            country      = CountryFactory.Create(AnyGuid);
            nonEuCountry = CountryFactory.Create(new Guid("606ECF5A-6571-4803-9CCA-7E1AF82D147A"), "test", false);

            context.Countries.AddRange(new[]
            {
                country,
                nonEuCountry
            });

            stateOfExport = new StateOfExport(country,
                                              CompetentAuthorityFactory.Create(AnyGuid, country),
                                              EntryOrExitPointFactory.Create(AnyGuid, country));

            stateOfImportNonEu = new StateOfImport(nonEuCountry,
                                                   CompetentAuthorityFactory.Create(new Guid("5E4F1F22-5054-449B-9EC7-933A43BB5D6D"), nonEuCountry),
                                                   EntryOrExitPointFactory.Create(new Guid("9781324F-17B8-4009-89B2-C18963E3E6E1"), nonEuCountry));

            A.CallTo(() => repository.GetByNotificationId(notificationId)).Returns(transport);

            this.handler   = new SetExitCustomsOfficeForNotificationByIdHandler(context, repository);
            this.validator = A.Fake <ITransportRouteValidator>();
            A.CallTo(() => this.validator.IsImportAndExportStatesCombinationValid(null, stateOfExport)).Returns(true);
            A.CallTo(() => this.validator.IsImportAndExportStatesCombinationValid(stateOfImportNonEu, stateOfExport)).Returns(true);
        }
Exemplo n.º 10
0
 private CompetentAuthority CreateCompetentAuthority(Guid id, Country country)
 {
     return(CompetentAuthorityFactory.Create(id, country));
 }
Exemplo n.º 11
0
        public void UpdateTransitState_SetToSameOrdinalPositionAsExisting_Throws()
        {
            transportRoute.AddTransitStateToNotification(transitStates[0]);

            transportRoute.AddTransitStateToNotification(transitStates[1]);

            Assert.Throws <InvalidOperationException>(() => transportRoute.UpdateTransitStateForNotification(transitStates[1].Id, countries[1],
                                                                                                             CompetentAuthorityFactory.Create(guids[0], countries[1]),
                                                                                                             EntryOrExitPointFactory.Create(guids[0], countries[1]),
                                                                                                             EntryOrExitPointFactory.Create(guids[1], countries[1]), 1));
        }