public async Task EnsureDateValid(Movement movement, DateTime newDate)
        {
            if (movement.Status != MovementStatus.Submitted)
            {
                throw new MovementDateException(string.Format(
                                                    "Can't set new movement date {0} because the movement is not in the submitted state (state: {1})",
                                                    newDate,
                                                    movement.Status));
            }

            await movementDateValidator.EnsureDateValid(movement.NotificationId, newDate);

            var originalDate = await originalMovementDate.Get(movement);

            var notification = await notificationRepository.GetByMovementId(movement.Id);

            var includeStartDate = false;

            if (newDate > workingDayCalculator.AddWorkingDays(originalDate, 10, includeStartDate, notification.CompetentAuthority))
            {
                throw new MovementDateOutOfRangeOfOriginalDateException(string.Format(
                                                                            "Can't set new movement date {0} since it is more than 10 working days after the original shipment date {1}",
                                                                            newDate,
                                                                            originalDate));
            }
        }
        public async Task <IDocumentBlock> Create(Guid movementId, IList <MergeField> mergeFields)
        {
            var notification = await notificationApplicationRepository.GetByMovementId(movementId);

            var producer = await producerRepository.GetByMovementId(movementId);

            return(new MovementProducerBlock(mergeFields, notification, producer));
        }
        public async Task <IDocumentBlock> Create(Guid movementId, IList <MergeField> mergeFields)
        {
            var notification = await notificationApplicationRepository.GetByMovementId(movementId);

            var technologyEmployed = await technologyEmployedRepository.GetByNotificaitonId(notification.Id);

            return(new MovementOperationBlock(mergeFields, notification, technologyEmployed));
        }
        public async Task <OperationCompleteData> HandleAsync(GetOperationCompleteData message)
        {
            var notificationType = (await notificationApplicationRepository.GetByMovementId(message.MovementId)).NotificationType;
            var movement         = await movementRepository.GetById(message.MovementId);

            var data = new OperationCompleteData
            {
                NotificationType = notificationType,
                ReceiptDate      = movement.Receipt.Date
            };

            return(data);
        }
        public MovementDateValidatorTests()
        {
            consentRepository      = A.Fake <INotificationConsentRepository>();
            notificationRepository = A.Fake <INotificationApplicationRepository>();
            historyRepository      = A.Fake <IMovementDateHistoryRepository>();
            workingDayCalculator   = A.Fake <IWorkingDayCalculator>();

            dateValidator        = new MovementDateValidator(consentRepository);
            originalMovementDate = new OriginalMovementDate(historyRepository);
            updatedDateValidator = new UpdatedMovementDateValidator(dateValidator,
                                                                    originalMovementDate,
                                                                    workingDayCalculator,
                                                                    notificationRepository);

            SystemTime.Freeze(Today.AddHours(5));

            A.CallTo(() => consentRepository.GetByNotificationId(NotificationId))
            .Returns(new Consent(
                         NotificationId,
                         new DateRange(ConsentStart, ConsentEnd),
                         AnyString,
                         AnyGuid));

            A.CallTo(() => notificationRepository.GetByMovementId(A <Guid> .Ignored))
            .Returns(new NotificationApplication(
                         AnyGuid,
                         NotificationType.Recovery,
                         UKCompetentAuthority.England,
                         10));

            A.CallTo(() => historyRepository.GetByMovementId(A <Guid> .Ignored))
            .Returns(new MovementDateHistory[0]);

            A.CallTo(() => workingDayCalculator.AddWorkingDays(A <DateTime> .Ignored,
                                                               A <int> .Ignored,
                                                               A <bool> .Ignored,
                                                               A <UKCompetentAuthority> .Ignored))
            .ReturnsLazily((DateTime inputDate,
                            int inputDays,
                            bool includeStartDay,
                            UKCompetentAuthority ca) =>
                           //A very simple working day formula that ignores bank holidays taken from http://stackoverflow.com/a/279370
                           inputDate.AddDays(inputDays
                                             + ((inputDays / 5) * 2)
                                             + ((((int)inputDate.DayOfWeek + (inputDays % 5)) >= 5) ? 2 : 0)));
        }
        public MovementDateValidatorTests()
        {
            consentRepository = A.Fake<INotificationConsentRepository>();
            notificationRepository = A.Fake<INotificationApplicationRepository>();
            historyRepository = A.Fake<IMovementDateHistoryRepository>();
            workingDayCalculator = A.Fake<IWorkingDayCalculator>();

            dateValidator = new MovementDateValidator(consentRepository);
            originalMovementDate = new OriginalMovementDate(historyRepository);
            updatedDateValidator = new UpdatedMovementDateValidator(dateValidator,
                originalMovementDate,
                workingDayCalculator,
                notificationRepository);

            SystemTime.Freeze(Today.AddHours(5));

            A.CallTo(() => consentRepository.GetByNotificationId(NotificationId))
                .Returns(new Consent(
                    NotificationId,
                    new DateRange(ConsentStart, ConsentEnd),
                    AnyString,
                    AnyGuid));

            A.CallTo(() => notificationRepository.GetByMovementId(A<Guid>.Ignored))
                .Returns(new NotificationApplication(
                    AnyGuid,
                    NotificationType.Recovery,
                    UKCompetentAuthority.England,
                    10));

            A.CallTo(() => historyRepository.GetByMovementId(A<Guid>.Ignored))
                .Returns(new MovementDateHistory[0]);

            A.CallTo(() => workingDayCalculator.AddWorkingDays(A<DateTime>.Ignored,
                A<int>.Ignored,
                A<bool>.Ignored,
                A<UKCompetentAuthority>.Ignored))
                    .ReturnsLazily((DateTime inputDate,
                        int inputDays,
                        bool includeStartDay,
                        UKCompetentAuthority ca) =>
                            //A very simple working day formula that ignores bank holidays taken from http://stackoverflow.com/a/279370
                            inputDate.AddDays(inputDays
                                + ((inputDays / 5) * 2)
                                + ((((int)inputDate.DayOfWeek + (inputDays % 5)) >= 5) ? 2 : 0)));
        }
Example #7
0
        public async Task <string> HandleAsync(GetNotificationNumberByMovementId message)
        {
            var notification = await repository.GetByMovementId(message.MovementId);

            return(notification.NotificationNumber);
        }
        public async Task <IDocumentBlock> Create(Guid movementId, IList <MergeField> mergeFields)
        {
            var notification = await notificationApplicationRepository.GetByMovementId(movementId);

            return(new MovementWasteCodesBlock(mergeFields, notification));
        }