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); }
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); }
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)); }
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); })); }
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); }
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 }); }
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); }
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))); }
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)); }
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())); }
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())); }
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); }
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)); }
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)); }
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); }
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>()); }
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)); }
public async Task <Guid> HandleAsync(AddDisposalCodes command) { var notification = await noticationRepository.GetById(command.NotificationId); notification.SetOperationCodes(command.DisposalCodes); await context.SaveChangesAsync(); return(command.NotificationId); }
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)); }
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)); }
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); }
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)); }
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); }
public async Task <bool> HandleAsync(SetOperationCodes message) { var notification = await notificationRepository.GetById(message.NotificationId); notification.SetOperationCodes(message.OperationCodes); await context.SaveChangesAsync(); return(true); }
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); }