示例#1
0
        public GetWasteCodeLookupAndNotificationDataByTypesHandlerTests()
        {
            wasteCodeRepository = A.Fake <IWasteCodeRepository>();
            notificationApplicationRepository = A.Fake <INotificationApplicationRepository>();
            //var context = new TestIwsContext();

            handler = new GetWasteCodeLookupAndNotificationDataByTypesHandler(notificationApplicationRepository, wasteCodeRepository, new WasteCodeMap(), new WasteCodeMap());

            A.CallTo(() => wasteCodeRepository.GetAllWasteCodes()).Returns(wasteCodes);

            var notificationWithWasteCodes = new TestableNotificationApplication
            {
                Id         = NotificationWithWasteCodesId,
                WasteCodes = new WasteCodeInfo[]
                {
                    new TestableWasteCodeInfo(FirstBaselCode)
                }
            };

            A.CallTo(() => notificationApplicationRepository.GetById(NotificationWithWasteCodesId)).Returns(notificationWithWasteCodes);

            var notificationWithoutWasteCodes = new TestableNotificationApplication
            {
                Id = NotificationWithoutWasteCodesId
            };

            A.CallTo(() => notificationApplicationRepository.GetById(NotificationWithoutWasteCodesId)).Returns(notificationWithoutWasteCodes);
        }
示例#2
0
        public async Task <Guid> HandleAsync(SetMultipleMovementFileId message)
        {
            var movements = new List <Movement>();

            foreach (var movementId in message.MovementIds)
            {
                var movement = await movementRepository.GetById(movementId);

                movements.Add(movement);
            }

            var notification = await notificationRepository.GetById(message.NotificationId);

            var fileName = GetFileName(notification.NotificationNumber, movements.Select(m => m.Number));

            var file   = new File(fileName, message.FileType, message.MovementBytes);
            var fileId = await fileRepository.Store(file);

            foreach (var movement in movements)
            {
                movement.Submit(fileId);
            }

            await context.SaveChangesAsync();

            foreach (var movement in movements)
            {
                await movementAuditRepository.Add(new MovementAudit(movement.NotificationId, movement.Number,
                                                                    userContext.UserId.ToString(), (int)MovementAuditType.Prenotified, SystemTime.Now));
            }

            await context.SaveChangesAsync();

            return(fileId);
        }
示例#3
0
        private async Task <int> GetWorkingDaysToExpiry(Guid notificationId)
        {
            var ca             = (await notificationApplicationRepository.GetById(notificationId)).CompetentAuthority;
            var consentEndDate = (await consentRepository.GetByNotificationId(notificationId)).ConsentRange.To;

            return(workingDayCalculator.GetWorkingDays(SystemTime.UtcNow, consentEndDate, true, ca));
        }
示例#4
0
        public SetMultipleMovementFileIdHandlerTests()
        {
            var context = new TestIwsContext();

            context.Users.Add(UserFactory.Create(TestIwsContext.UserId, AnyString, AnyString, AnyString, AnyString));

            notificationId = Guid.NewGuid();
            fileId         = Guid.NewGuid();
            var userId = TestIwsContext.UserId;

            movementRepository      = A.Fake <IMovementRepository>();
            notificationRepository  = A.Fake <INotificationApplicationRepository>();
            fileRepository          = A.Fake <IFileRepository>();
            movementAuditRepository = A.Fake <IMovementAuditRepository>();
            var userContext = A.Fake <IUserContext>();

            A.CallTo(() => notificationRepository.GetById(notificationId))
            .Returns(new TestableNotificationApplication()
            {
                NotificationNumber = NotificatioNumber
            });

            A.CallTo(() => fileRepository.Store(A <File> .Ignored)).Returns(fileId);

            A.CallTo(() => userContext.UserId).Returns(userId);

            handler = new SetMultipleMovementFileIdHandler(context, movementRepository, notificationRepository,
                                                           fileRepository, movementAuditRepository, userContext);
        }
        public async Task <PrenotificationContentRuleResult <PrenotificationContentRules> > GetResult(List <PrenotificationMovement> movements,
                                                                                                      Guid notificationId)
        {
            var ca                = (await notificationApplicationRepository.GetById(notificationId)).CompetentAuthority;
            var consentEndDate    = (await consentRepository.GetByNotificationId(notificationId)).ConsentRange.To;
            var consentHasExpired = consentEndDate < SystemTime.UtcNow;

            return(await Task.Run(() =>
            {
                var shipments =
                    movements.Where(
                        m =>
                        m.ShipmentNumber.HasValue && m.ActualDateOfShipment.HasValue &&
                        m.ActualDateOfShipment.Value.Date >= SystemTime.UtcNow.Date && !consentHasExpired &&
                        workingDayCalculator.GetWorkingDays(SystemTime.UtcNow, m.ActualDateOfShipment.Value,
                                                            true, ca) < 4)
                    .GroupBy(m => m.ShipmentNumber)
                    .OrderBy(x => x.Key)
                    .Select(x => x.Key)
                    .ToList();

                var result = shipments.Any() ? MessageLevel.Error : MessageLevel.Success;
                var minShipment = shipments.FirstOrDefault() ?? 0;

                var shipmentNumbers = string.Join(", ", shipments);
                var errorMessage = string.Format(Prsd.Core.Helpers.EnumHelper.GetDisplayName(PrenotificationContentRules.ThreeWorkingDaysToShipment), shipmentNumbers);

                return new PrenotificationContentRuleResult <PrenotificationContentRules>(PrenotificationContentRules.ThreeWorkingDaysToShipment, result, errorMessage, minShipment);
            }));
        }
示例#6
0
        private async Task <TransportRoute> CloneTransportRoute(Guid sourceNotificationId, Guid destinationNotificationId, UKCompetentAuthority destinationCompetentAuthority)
        {
            var transportRoute = await context.TransportRoutes.SingleOrDefaultAsync(p => p.NotificationId == sourceNotificationId);

            var destinationTransportRoute = new TransportRoute(destinationNotificationId);

            if (transportRoute != null)
            {
                var sourceCompetentAuthority   = (await notificationApplicationRepository.GetById(sourceNotificationId)).CompetentAuthority;
                var intraCountryExportAlloweds = await intraCountryExportAllowedRepository.GetAllAsync();

                if (destinationCompetentAuthority == sourceCompetentAuthority)
                {
                    transportRouteCopier.CopyTransportRoute(transportRoute, destinationTransportRoute, intraCountryExportAlloweds);
                }
                else
                {
                    transportRouteCopier.CopyTransportRouteWithoutExport(transportRoute, destinationTransportRoute, intraCountryExportAlloweds);
                }
            }

            context.TransportRoutes.Add(destinationTransportRoute);

            await context.SaveChangesAsync();

            return(destinationTransportRoute);
        }
示例#7
0
        public async Task <WasteCodeDataAndNotificationData> HandleAsync(GetWasteCodeLookupAndNotificationDataByTypes message)
        {
            var notification = await notificationApplicationRepository.GetById(message.Id);

            //var notification = await context.NotificationApplications.SingleAsync(na => na.Id == message.Id);

            IList <WasteCode> lookupCodes = await GetLookupCodes(message);

            IList <WasteCodeInfo> notificationCodes = GetNotificationCodes(message, notification);

            var lookupCodesDictionary = lookupCodes.GroupBy(wc => wc.CodeType).ToDictionary(x => x.Key, x => wasteCodeMapper.Map(x));

            var notificationCodesDictionary = message.NotificationWasteCodeTypes.GroupBy(wc => wc)
                                              .ToDictionary(x => x.Key, x => wasteCodeInfoMapper.Map(notificationCodes.Where(nc => nc.CodeType == x.Key)));

            var notApplicable =
                notification.WasteCodes.Where(wc => wc.IsNotApplicable).Select(wc => wc.CodeType).ToList();

            return(new WasteCodeDataAndNotificationData
            {
                LookupWasteCodeData = lookupCodesDictionary,
                NotificationWasteCodeData = notificationCodesDictionary,
                NotApplicableCodes = notApplicable
            });
        }
示例#8
0
        public async Task <Guid> HandleAsync(SaveMovementCompletedReceipt message)
        {
            var movement = await movementRepository.GetById(message.MovementId);

            var receipt = await certificateFactory.CreateForMovement(nameGenerator, movement, message.CertificateBytes, message.FileType);

            var fileId = await fileRepository.Store(receipt);

            movement.Complete(message.CompletedDate, fileId, userContext.UserId);

            await context.SaveChangesAsync();

            var notificationType  = (await notificationRepository.GetById(movement.NotificationId)).NotificationType;
            var movementAuditType = notificationType == NotificationType.Recovery
                ? MovementAuditType.Recovered
                : MovementAuditType.Disposed;

            await
            movementAuditRepository.Add(new MovementAudit(movement.NotificationId, movement.Number,
                                                          userContext.UserId.ToString(), (int)movementAuditType, message.AuditDate));

            await context.SaveChangesAsync();

            return(fileId);
        }
示例#9
0
        private async Task <IEnumerable <PackagingInfo> > GetPackagingInfos(Guid notificationId, IList <PackagingType> packagingTypes)
        {
            var notification = await notificationRepository.GetById(notificationId);

            return(notification.PackagingInfos
                   .Where(p => packagingTypes.Contains(p.PackagingType)));
        }
示例#10
0
        public async Task <NotificationDatesSummary> GetById(Guid notificationId)
        {
            await authorization.EnsureAccessAsync(notificationId);

            var assessment = await notificationAssessmentRepository.GetByNotificationId(notificationId);

            var notification = await notificationApplicationRepository.GetById(notificationId);

            var paymentReceived = await transactionCalculator.PaymentReceivedDate(notificationId) ??
                                  await transactionCalculator.LatestPayment(notificationId);

            DateTime?paymentReceivedDate = null;

            if (paymentReceived != null)
            {
                paymentReceivedDate = paymentReceived.Date;
            }

            return(NotificationDatesSummary.Load(
                       assessment.Status,
                       assessment.Dates.NotificationReceivedDate,
                       notificationId,
                       paymentReceivedDate,
                       await transactionCalculator.IsPaymentComplete(notificationId),
                       assessment.Dates.CommencementDate,
                       assessment.Dates.NameOfOfficer,
                       assessment.Dates.CompleteDate,
                       assessment.Dates.TransmittedDate,
                       assessment.Dates.AcknowledgedDate,
                       await decisionRequiredBy.GetDecisionRequiredByDate(notification, assessment),
                       assessment.Dates.FileClosedDate,
                       assessment.Dates.ArchiveReference));
        }
示例#11
0
        public async Task <ReceiptRecoveryContentRuleResult <ReceiptRecoveryContentRules> > GetResult(List <ReceiptRecoveryMovement> movements, Guid notificationId)
        {
            var actualMovements = (await movementRepo.GetAllMovements(notificationId)).ToList();
            var notification    = await notificationRepo.GetById(notificationId);

            var shipments = new List <int>();

            var validMovements =
                movements.Where(p => !p.MissingRecoveredDisposedDate && p.RecoveredDisposedDate.HasValue)
                .OrderBy(p => p.ShipmentNumber)
                .ToList();

            foreach (var movement in validMovements)
            {
                var actualMovement = actualMovements.FirstOrDefault(p => p.Number == movement.ShipmentNumber);

                if (actualMovement != null && actualMovement.Status == MovementStatus.Completed)
                {
                    shipments.Add(movement.ShipmentNumber.GetValueOrDefault());
                }
            }

            var result          = shipments.Any() ? MessageLevel.Error : MessageLevel.Success;
            var shipmentNumbers = string.Join(", ", shipments.Distinct());

            var type         = notification.NotificationType == NotificationType.Disposal ? "disposed" : "recovered";
            var errorMessage = string.Format(Prsd.Core.Helpers.EnumHelper.GetDisplayName(ReceiptRecoveryContentRules.AlreadyRecievedRecoveredDisposed), shipmentNumbers, type);

            return(new ReceiptRecoveryContentRuleResult <ReceiptRecoveryContentRules>(ReceiptRecoveryContentRules.AlreadyRecievedRecoveredDisposed, result, errorMessage, shipments.DefaultIfEmpty(0).Min()));
        }
示例#12
0
        public async Task <PrenotificationContentRuleResult <PrenotificationContentRules> > GetResult(List <PrenotificationMovement> movements, Guid notificationId)
        {
            var notificationApplication = await notificationApplicationRepository.GetById(notificationId);

            return(await Task.Run(() =>
            {
                var shipments =
                    movements.Where(
                        m =>
                        m.ShipmentNumber.HasValue &&
                        (!m.PackagingTypes.Any() ||
                         !m.PackagingTypes.All(
                             p => notificationApplication.PackagingInfos.Any(t => t.PackagingType == p))))
                    .GroupBy(x => x.ShipmentNumber)
                    .OrderBy(x => x.Key)
                    .Select(x => x.Key)
                    .ToList();

                var result = shipments.Any() ? MessageLevel.Error : MessageLevel.Success;
                var minShipment = shipments.FirstOrDefault() ?? 0;

                var shipmentNumbers = string.Join(", ", shipments);
                var errorMessage = string.Format(Prsd.Core.Helpers.EnumHelper.GetDisplayName(PrenotificationContentRules.InvalidPackagingType), shipmentNumbers);

                return new PrenotificationContentRuleResult <PrenotificationContentRules>(PrenotificationContentRules.InvalidPackagingType, result, errorMessage, minShipment);
            }));
        }
 public ReceiptRecoveryRecoveryDateFormatRuleTests()
 {
     notificationRepo = A.Fake <INotificationApplicationRepository>();
     rule             = new ReceiptRecoveryRecoveryDateFormatRule(notificationRepo);
     notificationId   = Guid.NewGuid();
     A.CallTo(() => notificationRepo.GetById(notificationId)).Returns(A.Fake <NotificationApplication>());
 }
        public async Task <ReceiptRecoveryContentRuleResult <ReceiptRecoveryContentRules> > GetResult(List <ReceiptRecoveryMovement> movements, Guid notificationId)
        {
            var actualMovements = (await movementRepo.GetAllMovements(notificationId)).ToList();
            var notification    = await notificationRepo.GetById(notificationId);

            var shipments = new List <int>();

            var validMovements =
                movements.Where(
                    p =>
                    !p.MissingReceivedDate && !p.MissingRecoveredDisposedDate &&
                    p.ReceivedDate.HasValue && p.RecoveredDisposedDate.HasValue)
                .OrderBy(p => p.ShipmentNumber)
                .ToList();

            foreach (var movement in validMovements)
            {
                var actualMovement = actualMovements.FirstOrDefault(p => p.Number == movement.ShipmentNumber);

                if (actualMovement == null)
                {
                    shipments.Add(movement.ShipmentNumber.GetValueOrDefault());
                    continue;
                }

                //Exclude these statuses as these will be picked up by Already Received and Already Recovered rules.
                if (actualMovement.Status != MovementStatus.Received &&
                    actualMovement.Status != MovementStatus.Completed)
                {
                    if (actualMovement.Status == MovementStatus.Captured)
                    {
                        if (actualMovement.Date.Date < SystemTime.UtcNow.Date)
                        {
                            shipments.Add(movement.ShipmentNumber.GetValueOrDefault());
                        }
                    }
                    else if (actualMovement.Status == MovementStatus.Submitted)
                    {
                        if (actualMovement.Date.Date > SystemTime.UtcNow.Date)
                        {
                            shipments.Add(movement.ShipmentNumber.GetValueOrDefault());
                        }
                    }
                    else
                    {
                        shipments.Add(movement.ShipmentNumber.GetValueOrDefault());
                    }
                }
            }

            var result          = shipments.Any() ? MessageLevel.Error : MessageLevel.Success;
            var shipmentNumbers = string.Join(", ", shipments.Distinct());

            var errorMessage =
                string.Format(
                    Prsd.Core.Helpers.EnumHelper.GetDisplayName(ReceiptRecoveryContentRules.ReceivedRecoveredValidation),
                    shipmentNumbers, Prsd.Core.Helpers.EnumHelper.GetDisplayName(notification.NotificationType));

            return(new ReceiptRecoveryContentRuleResult <ReceiptRecoveryContentRules>(ReceiptRecoveryContentRules.ReceivedRecoveredValidation, result, errorMessage, shipments.DefaultIfEmpty(0).Min()));
        }
示例#15
0
        public SaveMovementCompletedReceiptHandlerTests()
        {
            var context = new TestIwsContext();

            context.Users.Add(UserFactory.Create(TestIwsContext.UserId, AnyString, AnyString, AnyString, AnyString));

            notificationId = Guid.NewGuid();
            movementId     = Guid.NewGuid();
            fileId         = Guid.NewGuid();

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

            movementRepository      = A.Fake <IMovementRepository>();
            fileRepository          = A.Fake <IFileRepository>();
            notificationRepository  = A.Fake <INotificationApplicationRepository>();
            movementAuditRepository = A.Fake <IMovementAuditRepository>();

            A.CallTo(() => notificationRepository.GetById(notificationId))
            .Returns(new TestableNotificationApplication()
            {
                NotificationNumber = NotificationNumber
            });

            A.CallTo(() => fileRepository.Store(A <File> .Ignored)).Returns(fileId);

            var nameGenerator      = new CertificateOfRecoveryNameGenerator(notificationRepository);
            var certificateFactory = new CertificateFactory();

            handler = new SaveMovementCompletedReceiptHandler(context, fileRepository, movementRepository,
                                                              certificateFactory, nameGenerator, userContext, notificationRepository, movementAuditRepository);
        }
示例#16
0
        public async Task <IDocumentBlock> Create(Guid notificationId, IList <MergeField> mergeFields)
        {
            var notification = await notificationApplicationRepository.GetById(notificationId);

            var technologyEmployed = await technologyEmployedRepository.GetByNotificaitonId(notificationId);

            return(new OperationBlock(mergeFields, notification, technologyEmployed));
        }
示例#17
0
        public async Task <IDocumentBlock> Create(Guid notificationId, IList <MergeField> mergeFields)
        {
            var notification = await notificationApplicationRepository.GetById(notificationId);

            var producer = await producerRepository.GetByNotificationId(notificationId);

            return(new ProducerBlock(mergeFields, notification, producer));
        }
示例#18
0
        public async Task <string> GetValue(Movement movement)
        {
            var notification = await notificationApplicationRepository.GetById(movement.NotificationId);

            var notificationNumber = notification.NotificationNumber.Replace(" ", string.Empty);

            return(string.Format(nameFormat, notificationNumber, movement.Number));
        }
        public GetWasteRecoveryProviderHandlerTests()
        {
            notification = new TestableNotificationApplication { Id = NotificationId };
            repository = A.Fake<INotificationApplicationRepository>();
            A.CallTo(() => repository.GetById(NotificationId)).Returns(notification);

            handler = new GetWasteRecoveryProviderHandler(repository);
        }
示例#20
0
        public ReceiptRecoveryShipmentMustBePrenotifiedRuleTests()
        {
            movementRepo     = A.Fake <IMovementRepository>();
            notificationRepo = A.Fake <INotificationApplicationRepository>();
            rule             = new ReceiptRecoveryShipmentMustBePrenotifiedRule(movementRepo, notificationRepo);
            notificationId   = Guid.NewGuid();

            A.CallTo(() => notificationRepo.GetById(notificationId)).Returns(A.Fake <NotificationApplication>());
        }
示例#21
0
        public async Task <string> GetValue(Movement movement)
        {
            var notification = await notificationRepository.GetById(movement.NotificationId);

            var notificationNumber = notification.NotificationNumber.Replace(" ", string.Empty);
            var notificationType   = notification.NotificationType.ToString().ToLowerInvariant();

            return(string.Format(nameFormat, notificationNumber, movement.Number, notificationType));
        }
示例#22
0
        public async Task <Guid> HandleAsync(AddDisposalCodes command)
        {
            var notification = await noticationRepository.GetById(command.NotificationId);

            notification.SetOperationCodes(command.DisposalCodes);

            await context.SaveChangesAsync();

            return(command.NotificationId);
        }
示例#23
0
        public async Task <IDocumentBlock> Create(Guid notificationId, IList <MergeField> mergeFields)
        {
            var notification = await notificationApplicationRepository.GetById(notificationId);

            var shipment = await shipmentInfoRepository.GetByNotificationId(notificationId);

            var facilityCollection = await facilityRepository.GetByNotificationId(notificationId);

            return(new GeneralBlock(mergeFields, notification, shipment, facilityCollection));
        }
示例#24
0
        public async Task <FinancialGuaranteeData> HandleAsync(GetFinancialGuaranteeDataByNotificationApplicationId message)
        {
            var financialGuaranteeCollection = await financialGuaranteeRepository.GetByNotificationId(message.NotificationId);

            var financialGuarantee = financialGuaranteeCollection.GetFinancialGuarantee(message.FinancialGuaranteeId);

            var authority = (await notificationApplicationRepository.GetById(message.NotificationId)).CompetentAuthority;

            return(financialGuaranteeMap.Map(financialGuarantee, authority));
        }
示例#25
0
        public async Task SaveMovementCompletedReceiptHandler_RecoveryNotification_LogsAuditAsRecovered()
        {
            var request = GetRequest();

            A.CallTo(() => notificationRepository.GetById(notificationId))
            .Returns(new TestableNotificationApplication()
            {
                NotificationNumber = NotificationNumber, NotificationType = NotificationType.Recovery
            });

            await handler.HandleAsync(request);

            A.CallTo(
                () =>
                movementAuditRepository.Add(
                    A <MovementAudit> .That.Matches(
                        m => m.NotificationId == notificationId && m.Type == (int)MovementAuditType.Recovered)))
            .MustHaveHappened(Repeated.Exactly.Once);
        }
        public SetOperationCodesHandlerTests()
        {
            this.context = new TestIwsContext();
            this.notificationRepository = A.Fake <INotificationApplicationRepository>();

            A.CallTo(() => notificationRepository.GetById(A <Guid> .Ignored)).Returns(GetFakeApplication());

            this.message = A.Fake <SetOperationCodes>();
            this.handler = new SetOperationCodesHandler(this.context, this.notificationRepository);
        }
示例#27
0
        public async Task <IDocumentBlock> Create(Guid notificationId, IList <MergeField> mergeFields)
        {
            var notification = await notificationApplicationRepository.GetById(notificationId);

            var wasteRecovery = await wasteRecoveryRepository.GetByNotificationId(notificationId);

            var wasteDisposal = await wasteDisposalRepository.GetByNotificationId(notificationId);

            return(new WasteRecoveryBlock(mergeFields, notification, wasteRecovery, wasteDisposal));
        }
示例#28
0
        public GetWasteRecoveryProviderHandlerTests()
        {
            notification = new TestableNotificationApplication {
                Id = NotificationId
            };
            repository = A.Fake <INotificationApplicationRepository>();
            A.CallTo(() => repository.GetById(NotificationId)).Returns(notification);

            handler = new GetWasteRecoveryProviderHandler(repository);
        }
        public async Task <bool> HandleAsync(SetWasteRecoveryProvider message)
        {
            var notification = await repository.GetById(message.NotificationId);

            notification.SetWasteRecoveryInformationProvider(message.ProvidedBy);

            await context.SaveChangesAsync();

            return(true);
        }
示例#30
0
        public async Task <bool> HandleAsync(SetOperationCodes message)
        {
            var notification = await notificationRepository.GetById(message.NotificationId);

            notification.SetOperationCodes(message.OperationCodes);

            await context.SaveChangesAsync();

            return(true);
        }
示例#31
0
        public async Task <string> HandleAsync(SetPreconsentedRecoveryFacility query)
        {
            var notification = await notificationApplicationRepository.GetById(query.NotificationId);

            await setAllFacilitiesPreconsented.SetForNotification(notification, query.IsPreconsentedRecoveryFacility);

            await context.SaveChangesAsync();

            return(notification.NotificationNumber);
        }
        public SetWasteRecoveryProviderHandlerTests()
        {
            context = new TestIwsContext();
            repository = A.Fake<INotificationApplicationRepository>();

            var notification = new TestableNotificationApplication
            {
                Id = NotificationId
            };

            context.NotificationApplications.Add(notification);
            A.CallTo(() => repository.GetById(NotificationId)).Returns(notification);

            handler = new SetWasteRecoveryProviderHandler(repository, context);
        }