Exemplo n.º 1
0
        public SharedUserRepositoryTests()
        {
            ownerUser = UserFactory.Create(Guid.NewGuid(), "Owner", "User", "12345",
                                           "*****@*****.**");
            sharedUser = UserFactory.Create(Guid.NewGuid(), "Shared", "User", "12345",
                                            "*****@*****.**");

            var userContext = A.Fake <IUserContext>();

            A.CallTo(() => userContext.UserId).Returns(Guid.Parse(ownerUser.Id));

            context       = new IwsContext(userContext, A.Fake <IEventDispatcher>());
            authorization = A.Fake <INotificationApplicationAuthorization>();
            repository    = new SharedUserRepository(context, authorization);

            preRunNotifications = context.NotificationApplications.Select(na => na.Id).ToArray();

            notification = NotificationApplicationFactory.Create(Guid.Parse(ownerUser.Id), NotificationType.Recovery,
                                                                 UKCompetentAuthority.England, 20191);

            context.Users.Add(ownerUser);
            context.Users.Add(sharedUser);
            context.NotificationApplications.Add(notification);
            context.SaveChanges();
        }
Exemplo n.º 2
0
        public async Task CanUpdateOperationCodes()
        {
            var notification = NotificationApplicationFactory.Create(Guid.NewGuid(), NotificationType.Recovery,
                                                                     UKCompetentAuthority.England, 0);

            var codes = new List <OperationCode>
            {
                OperationCode.R1,
                OperationCode.R2
            };

            var newCodes = new List <OperationCode>
            {
                OperationCode.R3,
                OperationCode.R4
            };

            context.NotificationApplications.Add(notification);
            await context.SaveChangesAsync();

            notification.SetOperationCodes(codes);

            await context.SaveChangesAsync();

            notification.SetOperationCodes(newCodes);

            await context.SaveChangesAsync();

            Assert.Collection(notification.OperationInfos,
                              item => Assert.Equal(notification.OperationInfos.ElementAt(0).OperationCode, OperationCode.R3),
                              item => Assert.Equal(notification.OperationInfos.ElementAt(1).OperationCode, OperationCode.R4));
        }
Exemplo n.º 3
0
        public async Task CanRemoveCarrier()
        {
            var notification = NotificationApplicationFactory.Create(Guid.NewGuid(), NotificationType.Recovery, UKCompetentAuthority.England, 0);

            var address  = ObjectFactory.CreateDefaultAddress();
            var business = ObjectFactory.CreateEmptyProducerBusiness();
            var contact  = ObjectFactory.CreateEmptyContact();

            context.NotificationApplications.Add(notification);
            await context.SaveChangesAsync();

            var carrierCollection = new CarrierCollection(notification.Id);

            context.Carriers.Add(carrierCollection);
            await context.SaveChangesAsync();

            var carrier = carrierCollection.AddCarrier(business, address, contact);

            context.NotificationApplications.Add(notification);
            await context.SaveChangesAsync();

            Assert.True(carrierCollection.Carriers.Any());

            carrierCollection.RemoveCarrier(carrier.Id);
            await context.SaveChangesAsync();

            Assert.False(carrierCollection.Carriers.Any());
        }
Exemplo n.º 4
0
        public async Task GetNotificationProducerByIdChecksAuthorization()
        {
            var notification = NotificationApplicationFactory.Create(userId, NotificationType.Recovery,
                                                                     UKCompetentAuthority.England, 20181);

            context.NotificationApplications.Add(notification);
            context.SaveChanges();

            var notificationId = notification.Id;

            var producerCollection = new ProducerCollection(notificationId);

            producerCollection.AddProducer(ObjectFactory.CreateEmptyProducerBusiness(),
                                           ObjectFactory.CreateDefaultAddress(), ObjectFactory.CreateEmptyContact());

            context.Producers.Add(producerCollection);
            context.SaveChanges();

            var repository = new ProducerRepository(context,
                                                    notificationApplicationAuthorization);

            await repository.GetByNotificationId(notificationId);

            A.CallTo(() => notificationApplicationAuthorization.EnsureAccessAsync(notificationId)).MustHaveHappened();

            context.DeleteOnCommit(producerCollection);
            await context.SaveChangesAsync();

            context.DeleteOnCommit(notification);
            await context.SaveChangesAsync();
        }
Exemplo n.º 5
0
        public async Task CanAddMultipleProducers()
        {
            var notification = NotificationApplicationFactory.Create(Guid.NewGuid(), NotificationType.Recovery,
                                                                     UKCompetentAuthority.England, 0);

            var address  = ObjectFactory.CreateDefaultAddress();
            var business = ObjectFactory.CreateEmptyProducerBusiness();
            var contact  = ObjectFactory.CreateEmptyContact();

            context.NotificationApplications.Add(notification);
            await context.SaveChangesAsync();

            var producerCollection = new ProducerCollection(notification.Id);

            for (int i = 0; i < 5; i++)
            {
                producerCollection.AddProducer(business, address, contact);
            }

            context.Producers.Add(producerCollection);
            await context.SaveChangesAsync();

            var dbProducerCollection = context.Producers.Single(p => p.NotificationId == notification.Id);

            Assert.True(producerCollection.Producers.Count() == dbProducerCollection.Producers.Count());
        }
Exemplo n.º 6
0
        public async Task CanAddMultipleCarriers()
        {
            var notification = NotificationApplicationFactory.Create(Guid.NewGuid(), NotificationType.Recovery, UKCompetentAuthority.England, 0);

            var address  = ObjectFactory.CreateDefaultAddress();
            var business = ObjectFactory.CreateEmptyProducerBusiness();
            var contact  = ObjectFactory.CreateEmptyContact();

            context.NotificationApplications.Add(notification);
            await context.SaveChangesAsync();

            var carrierCollection = new CarrierCollection(notification.Id);

            context.Carriers.Add(carrierCollection);
            await context.SaveChangesAsync();

            for (int i = 0; i < 5; i++)
            {
                carrierCollection.AddCarrier(business, address, contact);
            }

            await context.SaveChangesAsync();

            Assert.Equal(carrierCollection.Carriers.Count(), 5);
        }
Exemplo n.º 7
0
        public async Task CanAddMultipleFacilities()
        {
            var notification = NotificationApplicationFactory.Create(Guid.NewGuid(), NotificationType.Recovery,
                                                                     UKCompetentAuthority.England, 0);

            var address  = ObjectFactory.CreateDefaultAddress();
            var business = ObjectFactory.CreateEmptyBusiness();
            var contact  = ObjectFactory.CreateEmptyContact();

            context.NotificationApplications.Add(notification);
            await context.SaveChangesAsync();

            var facilityCollection = new FacilityCollection(notification.Id);

            context.Facilities.Add(facilityCollection);
            await context.SaveChangesAsync();

            for (int i = 0; i < 5; i++)
            {
                facilityCollection.AddFacility(business, address, contact);
            }

            await context.SaveChangesAsync();

            Assert.True(facilityCollection.Facilities.Count() == 5);
        }
Exemplo n.º 8
0
        public async Task CanRemoveFacilityOtherThanActualSiteOfTreatment()
        {
            var notification = NotificationApplicationFactory.Create(Guid.NewGuid(), NotificationType.Recovery, UKCompetentAuthority.England, 0);

            var address  = ObjectFactory.CreateDefaultAddress();
            var business = ObjectFactory.CreateEmptyBusiness();
            var contact  = ObjectFactory.CreateEmptyContact();

            context.NotificationApplications.Add(notification);
            await context.SaveChangesAsync();

            var facilityCollection = new FacilityCollection(notification.Id);

            context.Facilities.Add(facilityCollection);
            await context.SaveChangesAsync();

            var facility        = facilityCollection.AddFacility(business, address, contact);
            var anotherFacility = facilityCollection.AddFacility(business, address, contact);

            await context.SaveChangesAsync();

            Assert.True(facilityCollection.Facilities.Count() == 2);

            facilityCollection.SetFacilityAsSiteOfTreatment(facility.Id);
            await context.SaveChangesAsync();

            facilityCollection.RemoveFacility(anotherFacility.Id);
            await context.SaveChangesAsync();

            Assert.True(facilityCollection.Facilities.Count() == 1);
        }
Exemplo n.º 9
0
        public async Task CanRemoveProducerOtherThanSiteOfExporter()
        {
            var notification = NotificationApplicationFactory.Create(Guid.NewGuid(), NotificationType.Recovery,
                                                                     UKCompetentAuthority.England, 0);

            var address  = ObjectFactory.CreateDefaultAddress();
            var business = ObjectFactory.CreateEmptyProducerBusiness();
            var contact  = ObjectFactory.CreateEmptyContact();

            context.NotificationApplications.Add(notification);
            await context.SaveChangesAsync();

            var producerCollection = new ProducerCollection(notification.Id);

            var producer        = producerCollection.AddProducer(business, address, contact);
            var anotherProducer = producerCollection.AddProducer(business, address, contact);

            context.NotificationApplications.Add(notification);
            context.Producers.Add(producerCollection);
            await context.SaveChangesAsync();

            Assert.True(producerCollection.Producers.Count() == 2);

            producerCollection.SetProducerAsSiteOfExport(producer.Id);
            await context.SaveChangesAsync();

            producerCollection.RemoveProducer(anotherProducer.Id);
            await context.SaveChangesAsync();

            Assert.True(producerCollection.Producers.Count() == 1);
        }
Exemplo n.º 10
0
        public async Task GetNotificationAssessmentByIdChecksAuthorization()
        {
            var notification = NotificationApplicationFactory.Create(userId, NotificationType.Recovery,
                                                                     UKCompetentAuthority.England, 20181);

            context.NotificationApplications.Add(notification);
            context.SaveChanges();

            var notificationId = notification.Id;

            var assessment = new NotificationAssessment(notificationId);

            ObjectInstantiator <NotificationAssessment> .SetProperty(x => x.Status, NotificationStatus.NotificationReceived, assessment);

            context.NotificationAssessments.Add(assessment);
            context.SaveChanges();

            var repository = new NotificationAssessmentRepository(context,
                                                                  notificationApplicationAuthorization);

            await repository.GetByNotificationId(notificationId);

            A.CallTo(() => notificationApplicationAuthorization.EnsureAccessAsync(notificationId)).MustHaveHappened();

            context.DeleteOnCommit(assessment);
            await context.SaveChangesAsync();

            context.DeleteOnCommit(notification);
            await context.SaveChangesAsync();
        }
Exemplo n.º 11
0
        public async Task GetNotificationConsentByIdChecksAuthorization()
        {
            var notification = NotificationApplicationFactory.Create(userId, NotificationType.Recovery,
                                                                     UKCompetentAuthority.England, 20181);

            context.NotificationApplications.Add(notification);
            context.SaveChanges();

            var notificationId = notification.Id;

            var consent = new Consent(notificationId, new DateRange(DateTime.Now, DateTime.Now.AddDays(10)), "test", userId);

            context.Consents.Add(consent);
            context.SaveChanges();

            var repository = new NotificationConsentRepository(context,
                                                               notificationApplicationAuthorization);

            await repository.GetByNotificationId(notificationId);

            A.CallTo(() => notificationApplicationAuthorization.EnsureAccessAsync(notificationId)).MustHaveHappened();

            context.DeleteOnCommit(consent);
            await context.SaveChangesAsync();

            context.DeleteOnCommit(notification);
            await context.SaveChangesAsync();
        }
        public GetExitCustomsOfficeAddDataByNotificationIdTests()
        {
            context = new TestIwsContext();
            var repository = A.Fake <ITransportRouteRepository>();

            country           = CountryFactory.Create(new Guid("05C21C57-2F39-4A15-A09A-5F38CF139C05"));
            exitCustomsOffice = new ExitCustomsOffice("any name", "any address", country);

            notification = NotificationApplicationFactory.Create(TestIwsContext.UserId, NotificationType.Recovery,
                                                                 UKCompetentAuthority.England, 500);

            transport = new TransportRoute(NotificationId);

            EntityHelper.SetEntityId(notification, NotificationId);

            context.Countries.Add(country);
            context.NotificationApplications.Add(notification);
            context.TransportRoutes.Add(transport);

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

            handler = new GetExitCustomsOfficeAddDataByNotificationIdHandler(repository,
                                                                             new CustomsOfficeExitMap(context,
                                                                                                      new CountryMap(),
                                                                                                      new CustomsOfficeMap(new CountryMap())));
        }
Exemplo n.º 13
0
        public async Task CanModifyProducer()
        {
            var notification = NotificationApplicationFactory.Create(Guid.NewGuid(), NotificationType.Recovery,
                                                                     UKCompetentAuthority.England, 0);

            var address  = new Address("address1", string.Empty, "town", string.Empty, string.Empty, "country");
            var business = ObjectFactory.CreateEmptyProducerBusiness();
            var contact  = new Contact(string.Empty, String.Empty, String.Empty, String.Empty);

            context.NotificationApplications.Add(notification);
            await context.SaveChangesAsync();

            var producerCollection = new ProducerCollection(notification.Id);

            var producer = producerCollection.AddProducer(business, address, contact);

            context.Producers.Add(producerCollection);
            await context.SaveChangesAsync();

            var updateProducer = producerCollection.GetProducer(producer.Id);
            var newAddress     = new Address("address1", string.Empty, "town", string.Empty, string.Empty, "country");

            updateProducer.Address = newAddress;

            await context.SaveChangesAsync();

            var newAddress1 =
                await context.Database.SqlQuery <string>("SELECT [Address1] FROM [Notification].[Producer] WHERE Id = @id",
                                                         new SqlParameter("id", producer.Id)).SingleAsync();

            Assert.Equal("address1", newAddress1);
        }
Exemplo n.º 14
0
 public RelationshipDeletionIntegration()
 {
     userId      = new Guid("5BA5B2CE-A29C-4B94-A528-567F636CA456");
     userContext = A.Fake <IUserContext>();
     A.CallTo(() => userContext.UserId).Returns(userId);
     context      = new IwsContext(userContext, A.Fake <IEventDispatcher>());
     notification = NotificationApplicationFactory.Create(userId, NotificationType.Recovery,
                                                          UKCompetentAuthority.England, 0);
 }
        private NotificationApplication CreateNotificationApplication(Guid id, UKCompetentAuthority competentAuthority, WasteType wasteType)
        {
            var notificationApplication = NotificationApplicationFactory.Create(Guid.NewGuid(), NotificationType.Recovery, competentAuthority, 0);

            EntityHelper.SetEntityId(notificationApplication, id);

            notificationApplication.SetWasteType(wasteType);

            return(notificationApplication);
        }
        public NotificationCreatedEventHandlerTests()
        {
            context = new TestIwsContext();

            var notification = NotificationApplicationFactory.Create(Guid.Empty, NotificationType.Recovery,
                                                                     UKCompetentAuthority.England, 0);

            EntityHelper.SetEntityId(notification, notificationId);

            message = new NotificationCreatedEvent(notification);
            handler = new NotificationCreatedEventHandler(context);
        }
Exemplo n.º 17
0
        public async Task CanAddPackagingInfo()
        {
            var notification = NotificationApplicationFactory.Create(Guid.NewGuid(), NotificationType.Recovery,
                                                                     UKCompetentAuthority.England, 0);

            context.NotificationApplications.Add(notification);

            notification.SetPackagingInfo(new[] { PackagingInfo.CreatePackagingInfo(PackagingType.Bag) });

            await context.SaveChangesAsync();

            Assert.Equal(1, notification.PackagingInfos.Count());
        }
Exemplo n.º 18
0
        public async Task GetNotificationDatesSummaryByIdChecksAuthorization()
        {
            var notification = NotificationApplicationFactory.Create(userId, NotificationType.Recovery,
                                                                     UKCompetentAuthority.England, 20181);

            context.NotificationApplications.Add(notification);
            context.SaveChanges();

            var notificationId = notification.Id;

            var decisionRequiredBy = new DecisionRequiredBy(A.Fake <IDecisionRequiredByCalculator>(),
                                                            A.Fake <IFacilityRepository>());
            var assessmentRepository  = A.Fake <INotificationAssessmentRepository>();
            var applicationRepository = A.Fake <INotificationApplicationRepository>();
            var transactionCalculator = A.Fake <INotificationTransactionCalculator>();
            var assessment            = new NotificationAssessment(notificationId);

            ObjectInstantiator <NotificationAssessment> .SetProperty(x => x.Status, NotificationStatus.NotificationReceived, assessment);

            A.CallTo(() => assessmentRepository.GetByNotificationId(notificationId))
            .Returns(assessment);
            A.CallTo(() => applicationRepository.GetById(notificationId)).Returns(notification);

            var transaction = new NotificationTransaction(
                new NotificationTransactionData
            {
                Credit         = 1,
                Date           = new DateTime(2017, 1, 1),
                NotificationId = notificationId,
                PaymentMethod  = PaymentMethod.Card
            });

            A.CallTo(() => transactionCalculator.PaymentReceivedDate(notificationId))
            .Returns(transaction);
            A.CallTo(() => transactionCalculator.LatestPayment(notificationId))
            .Returns(transaction);
            A.CallTo(() => transactionCalculator.IsPaymentComplete(notificationId)).Returns(true);

            var repository = new NotificationAssessmentDatesSummaryRepository(decisionRequiredBy,
                                                                              assessmentRepository,
                                                                              applicationRepository,
                                                                              transactionCalculator,
                                                                              notificationApplicationAuthorization);

            await repository.GetById(notificationId);

            A.CallTo(() => notificationApplicationAuthorization.EnsureAccessAsync(notificationId)).MustHaveHappened();

            context.DeleteOnCommit(notification);
            await context.SaveChangesAsync();
        }
Exemplo n.º 19
0
        public async Task CanAddSpecialHandlingDetails()
        {
            var notification = NotificationApplicationFactory.Create(Guid.NewGuid(), NotificationType.Recovery,
                                                                     UKCompetentAuthority.England, 0);

            notification.SetSpecialHandlingRequirements("keep upright");

            context.NotificationApplications.Add(notification);
            await context.SaveChangesAsync();

            Assert.True(notification.HasSpecialHandlingRequirements);
            Assert.Equal("keep upright", notification.SpecialHandlingDetails);

            context.DeleteOnCommit(notification);
            await context.SaveChangesAsync();
        }
        public async Task SharedUserNotificationAccess()
        {
            // Setup.
            var notification = NotificationApplicationFactory.Create(Guid.NewGuid(), NotificationType.Recovery,
                                                                     UKCompetentAuthority.England, 20181);
            var aspnetInternalUser = UserFactory.Create(Guid.NewGuid(), "Internal", "Internal Last", "12345",
                                                        "*****@*****.**");
            var aspnetSharedUser = UserFactory.Create(Guid.NewGuid(), "External", "Shared", "12345",
                                                      "*****@*****.**");
            var localArea = new LocalArea(Guid.NewGuid(), "Test Area", (int)UKCompetentAuthority.England);

            context.NotificationApplications.Add(notification);
            context.Users.Add(aspnetInternalUser);
            context.Users.Add(aspnetSharedUser);
            context.LocalAreas.Add(localArea);
            await context.SaveChangesAsync();

            var internalUser = new InternalUser(aspnetInternalUser.Id, "test", UKCompetentAuthority.England,
                                                localArea.Id);
            var sharedUser = new SharedUser(notification.Id, aspnetSharedUser.Id, DateTimeOffset.Now);

            context.InternalUsers.Add(internalUser);
            context.SharedUser.Add(sharedUser);
            await context.SaveChangesAsync();

            // Set the shared user to be the user context.
            A.CallTo(() => userContext.UserId).Returns(Guid.Parse(sharedUser.UserId));

            var authorization = new NotificationApplicationAuthorization(context, userContext);

            // Assert.
            // There's no assertion for 'does not throw exception' so just executing it as normal.
            await authorization.EnsureAccessAsync(notification.Id);

            // Clear data.
            context.DeleteOnCommit(internalUser);
            context.DeleteOnCommit(sharedUser);
            await context.SaveChangesAsync();

            context.Entry(aspnetInternalUser).State = EntityState.Deleted;
            context.Entry(aspnetSharedUser).State   = EntityState.Deleted;
            context.Entry(localArea).State          = EntityState.Deleted;
            await context.SaveChangesAsync();

            context.DeleteOnCommit(notification);
            await context.SaveChangesAsync();
        }
        public async Task RandomExternalUserAccessThrowsException()
        {
            // Setup.
            var notification = NotificationApplicationFactory.Create(Guid.NewGuid(), NotificationType.Recovery,
                                                                     UKCompetentAuthority.England, 20181);
            var aspnetInternalUser = UserFactory.Create(Guid.NewGuid(), "Internal", "Internal Last", "12345",
                                                        "*****@*****.**");
            var aspnetSharedUser = UserFactory.Create(Guid.NewGuid(), "External", "Shared", "12345",
                                                      "*****@*****.**");
            var localArea = new LocalArea(Guid.NewGuid(), "Test Area", (int)UKCompetentAuthority.England);

            context.NotificationApplications.Add(notification);
            context.Users.Add(aspnetInternalUser);
            context.Users.Add(aspnetSharedUser);
            context.LocalAreas.Add(localArea);
            await context.SaveChangesAsync();

            var internalUser = new InternalUser(aspnetInternalUser.Id, "test", UKCompetentAuthority.England,
                                                localArea.Id);
            //Shared user is different to the user context.
            var sharedUser = new SharedUser(notification.Id, aspnetSharedUser.Id, DateTimeOffset.Now);

            context.SharedUser.Add(sharedUser);
            await context.SaveChangesAsync();

            context.InternalUsers.Add(internalUser);
            await context.SaveChangesAsync();

            var authorization = new NotificationApplicationAuthorization(context, userContext);

            // Assert.
            await Assert.ThrowsAsync <SecurityException>(() => authorization.EnsureAccessAsync(notification.Id));

            // Clear data.
            context.DeleteOnCommit(internalUser);
            context.DeleteOnCommit(sharedUser);
            await context.SaveChangesAsync();

            context.Entry(aspnetInternalUser).State = EntityState.Deleted;
            context.Entry(aspnetSharedUser).State   = EntityState.Deleted;
            context.Entry(localArea).State          = EntityState.Deleted;
            await context.SaveChangesAsync();

            context.DeleteOnCommit(notification);
            await context.SaveChangesAsync();
        }
        public CopyToNotificationHandlerTests()
        {
            var applicationRepository = A.Fake <INotificationApplicationRepository>();

            SystemTime.Freeze(new DateTime(2015, 1, 1));
            context = new IwsContext(GetUserContext(), A.Fake <IEventDispatcher>());
            handler = new CopyToNotificationHandler(context,
                                                    new NotificationToNotificationCopy(new WasteCodeCopy()),
                                                    new ExporterToExporterCopy(),
                                                    new TransportRouteToTransportRouteCopy(),
                                                    new WasteRecoveryToWasteRecoveryCopy(),
                                                    new ImporterToImporterCopy(),
                                                    new NotificationApplicationRepository(context, new NotificationApplicationAuthorization(context, GetUserContext())),
                                                    new IntraCountryExportAllowedRepository(context),
                                                    new FacilityCollectionCopy(),
                                                    new CarrierCollectionCopy(),
                                                    new ProducerCollectionCopy(),
                                                    new MeansOfTransportToMeansOfTransportCopy());

            preRunNotifications = context.NotificationApplications.Select(na => na.Id).ToArray();

            source = NotificationApplicationFactory.CreateCompleted(new Guid("0ED9A007-3C35-48A3-B008-9D5623FA5AD9"),
                                                                    UserId,
                                                                    context.Countries.ToArray(),
                                                                    context.WasteCodes.ToArray(),
                                                                    SourceNumber);

            destination = NotificationApplicationFactory.Create(UserId, DestinationNotificationType, DestinationCompetentAuthority, DestinationNumber);
            EntityHelper.SetEntityId(destination, new Guid("63581B29-EFB9-47F0-BCC3-E67382F4EAFA"));

            context.NotificationApplications.Add(source);
            context.NotificationApplications.Add(destination);

            // Calling source id and destination id is only safe after this call to save changes
            context.SaveChanges();

            AddNotificationLinkedEntities(source.Id, destination.Id);
            context.AnnexCollections.Add(new AnnexCollection(destination.Id));

            context.SaveChanges();

            A.CallTo(() => applicationRepository.GetById(A <Guid> .Ignored)).Returns(source);
        }
Exemplo n.º 23
0
        public async Task GetNotificationShipmentInfoByIdChecksAuthorization()
        {
            var notification = NotificationApplicationFactory.Create(userId, NotificationType.Recovery,
                                                                     UKCompetentAuthority.England, 20181);

            context.NotificationApplications.Add(notification);
            context.SaveChanges();

            var notificationId = notification.Id;

            var shipmentsInfo = new ShipmentInfo(notificationId, new ShipmentPeriod(DateTime.Now, DateTime.Now.AddDays(10), true), 10, new ShipmentQuantity(1.0m, ShipmentQuantityUnits.Tonnes));
            var assessment    = new NotificationAssessment(notificationId);

            ObjectInstantiator <NotificationAssessment> .SetProperty(x => x.Status, NotificationStatus.NotificationReceived, assessment);

            var facilityCollection = new FacilityCollection(notificationId);

            facilityCollection.AddFacility(ObjectFactory.CreateEmptyProducerBusiness(),
                                           ObjectFactory.CreateDefaultAddress(), ObjectFactory.CreateEmptyContact());

            context.ShipmentInfos.Add(shipmentsInfo);
            context.NotificationAssessments.Add(assessment);
            context.Facilities.Add(facilityCollection);
            context.SaveChanges();

            var repository = new ShipmentInfoRepository(context,
                                                        notificationApplicationAuthorization);

            await repository.GetByNotificationId(notificationId);

            await repository.GetIntendedShipmentDataByNotificationId(notificationId);

            A.CallTo(() => notificationApplicationAuthorization.EnsureAccessAsync(notificationId)).MustHaveHappened(Repeated.Exactly.Times(2));

            context.DeleteOnCommit(shipmentsInfo);
            context.DeleteOnCommit(assessment);
            context.DeleteOnCommit(facilityCollection);
            await context.SaveChangesAsync();

            context.DeleteOnCommit(notification);
            await context.SaveChangesAsync();
        }
Exemplo n.º 24
0
        public async Task CanAddWasteType()
        {
            var notification = NotificationApplicationFactory.Create(Guid.NewGuid(), NotificationType.Recovery,
                                                                     UKCompetentAuthority.England, 0);

            context.NotificationApplications.Add(notification);
            await context.SaveChangesAsync();

            List <WasteAdditionalInformation> wasteCompositions = new List <WasteAdditionalInformation>
            {
                WasteAdditionalInformation.CreateWasteAdditionalInformation("boulder", 5, 10, WasteInformationType.Energy),
                WasteAdditionalInformation.CreateWasteAdditionalInformation("notes", 6, 9, WasteInformationType.AshContent)
            };

            notification.SetWasteType(WasteType.CreateWoodWasteType("This waste type is of wood type. I am writing some description here.", wasteCompositions));

            await context.SaveChangesAsync();

            Assert.True(notification.HasWasteType);
        }
Exemplo n.º 25
0
        public GetCustomsOfficeRequiredStatusByNotificationIdHandlerTests()
        {
            notification1  = NotificationApplicationFactory.Create(TestIwsContext.UserId, NotificationType.Recovery, UKCompetentAuthority.England, 500);
            notificationId = new Guid("295B0511-D0EB-43B4-9D17-938E1A34F0D3");

            EntityHelper.SetEntityId(notification1, notificationId);

            var transport = new TransportRoute(notificationId);

            context = new TestIwsContext();

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

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

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

            handler = new GetCustomsCompletionStatusByNotificationIdHandler(repository);
        }
Exemplo n.º 26
0
        public async Task GetNotificationWasteRecoveryByIdChecksAuthorization()
        {
            var notification = NotificationApplicationFactory.Create(userId, NotificationType.Recovery,
                                                                     UKCompetentAuthority.England, 20181);

            context.NotificationApplications.Add(notification);
            context.SaveChanges();

            var notificationId = notification.Id;

            var repository = new WasteRecoveryRepository(context,
                                                         notificationApplicationAuthorization);

            await repository.GetByNotificationId(notificationId);

            A.CallTo(() => notificationApplicationAuthorization.EnsureAccessAsync(notificationId)).MustHaveHappened();

            context.DeleteOnCommit(notification);
            await context.SaveChangesAsync();
        }
        public async Task InternalUserDifferentCompetentAuthorityAccessThrowsException()
        {
            // Setup.
            var notification = NotificationApplicationFactory.Create(Guid.NewGuid(), NotificationType.Recovery,
                                                                     UKCompetentAuthority.England, 20181);
            var aspnetInternalUser = UserFactory.Create(Guid.NewGuid(), "Internal", "Internal Last", "12345",
                                                        "*****@*****.**");
            var localArea = new LocalArea(Guid.NewGuid(), "Test Area", (int)UKCompetentAuthority.England);

            context.NotificationApplications.Add(notification);
            context.Users.Add(aspnetInternalUser);
            context.LocalAreas.Add(localArea);
            await context.SaveChangesAsync();

            // Internal user is different UKCA from the notification - should cause the exception.
            var internalUser = new InternalUser(aspnetInternalUser.Id, "test", UKCompetentAuthority.Wales,
                                                localArea.Id);

            context.InternalUsers.Add(internalUser);
            await context.SaveChangesAsync();

            A.CallTo(() => userContext.UserId).Returns(Guid.Parse(internalUser.UserId));

            var authorization = new NotificationApplicationAuthorization(context, userContext);

            // Assert.
            await Assert.ThrowsAsync <SecurityException>(() => authorization.EnsureAccessAsync(notification.Id));

            // Clear data.
            context.DeleteOnCommit(internalUser);
            await context.SaveChangesAsync();

            context.Entry(aspnetInternalUser).State = EntityState.Deleted;
            context.Entry(localArea).State          = EntityState.Deleted;
            await context.SaveChangesAsync();

            context.DeleteOnCommit(notification);
            await context.SaveChangesAsync();
        }
Exemplo n.º 28
0
        public async Task GetNotificationApplicationOverviewByIdChecksAuthorization()
        {
            var notification = NotificationApplicationFactory.Create(userId, NotificationType.Recovery,
                                                                     UKCompetentAuthority.England, 20181);

            context.NotificationApplications.Add(notification);
            context.SaveChanges();

            var notificationId = notification.Id;

            var repository = new NotificationApplicationOverviewRepository(context,
                                                                           A.Fake <INotificationChargeCalculator>(),
                                                                           A.Fake <INotificationProgressService>(),
                                                                           notificationApplicationAuthorization);

            await repository.GetById(notificationId);

            A.CallTo(() => notificationApplicationAuthorization.EnsureAccessAsync(notificationId)).MustHaveHappened();

            context.DeleteOnCommit(notification);
            await context.SaveChangesAsync();
        }
        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.º 30
0
        public async Task GetNotificationNumberOfShipmentsHistoryChecksAuthorization()
        {
            var notification = NotificationApplicationFactory.Create(userId, NotificationType.Recovery,
                                                                     UKCompetentAuthority.England, 20181);

            context.NotificationApplications.Add(notification);
            context.SaveChanges();

            var notificationId = notification.Id;

            var shipmentsHistory = new NumberOfShipmentsHistory(notificationId, 10, DateTime.Now);
            var shipmentsInfo    = new ShipmentInfo(notificationId, new ShipmentPeriod(DateTime.Now, DateTime.Now.AddDays(10), true), 10, new ShipmentQuantity(1.0m, ShipmentQuantityUnits.Tonnes));

            context.NumberOfShipmentsHistories.Add(shipmentsHistory);
            context.ShipmentInfos.Add(shipmentsInfo);
            context.SaveChanges();

            var repository = new NumberOfShipmentsHistoryRepository(context,
                                                                    notificationApplicationAuthorization);

            await repository.GetOriginalNumberOfShipments(notificationId);

            await repository.GetCurrentNumberOfShipments(notificationId);

            await repository.GetLargestNumberOfShipments(notificationId);

            A.CallTo(() => notificationApplicationAuthorization.EnsureAccessAsync(notificationId))
            .MustHaveHappened(Repeated.Exactly.Times(4));

            context.DeleteOnCommit(shipmentsHistory);
            context.DeleteOnCommit(shipmentsInfo);
            await context.SaveChangesAsync();

            context.DeleteOnCommit(notification);
            await context.SaveChangesAsync();
        }