Ejemplo n.º 1
0
        public async Task WasteReceivedDateCanBeInThePast()
        {
            movement = new ImportMovement(notificationId, 52, PastDate);

            A.CallTo(() => movementRepository.Get(movementId)).Returns(movement);

            var result = await receiveFactory.Receive(movementId, new ShipmentQuantity(10, ShipmentQuantityUnits.Kilograms), PastDate);

            Assert.Equal(PastDate, result.Date);
        }
Ejemplo n.º 2
0
        public async Task WasteReceivedDateCanBeInThePast()
        {
            movement = new ImportMovement(notificationId, 52, PastDate);

            A.CallTo(() => movementRepository.Get(movementId)).Returns(movement);

            var result = await rejectFactory.Reject(movementId, PastDate, rejectionreason);

            Assert.Equal(PastDate, result.Date);
        }
Ejemplo n.º 3
0
        public async Task <ImportMovementPartialRejection> PartailReject(Guid movementId,
                                                                         DateTime date,
                                                                         string reason,
                                                                         decimal actualQuantity,
                                                                         ShipmentQuantityUnits actualUnit,
                                                                         decimal rejectedQuantity,
                                                                         ShipmentQuantityUnits rejectedUnit,
                                                                         DateTime?wasteDisposedDate)
        {
            var movement = await movementRepository.Get(movementId);

            if (date < movement.ActualShipmentDate)
            {
                throw new InvalidOperationException("The when the waste was received date cannot be before the actual date of shipment.");
            }
            if (date > SystemTime.UtcNow.Date)
            {
                throw new InvalidOperationException("The when the waste was received date cannot be in the future.");
            }

            var partialRejection = movement.PartialReject(movementId, date, reason, actualQuantity, actualUnit, rejectedQuantity, rejectedUnit, wasteDisposedDate);

            importMovementPartailRejectionRepository.Add(partialRejection);

            return(partialRejection);
        }
        public CancelImportMovementTests()
        {
            completedReceiptRepository = A.Fake<IImportMovementCompletedReceiptRepository>();
            movementRepository = A.Fake<IImportMovementRepository>();
            receiptRepository = A.Fake<IImportMovementReceiptRepository>();
            movement = new ImportMovement(notificationId, 1, new DateTime(2016, 1, 1));

            A.CallTo(() => movementRepository.Get(movementId)).Returns(movement);

            cancelMovement = new CancelImportMovement(movementRepository, receiptRepository, completedReceiptRepository);
        }
Ejemplo n.º 5
0
        public CancelImportMovementTests()
        {
            completedReceiptRepository = A.Fake <IImportMovementCompletedReceiptRepository>();
            movementRepository         = A.Fake <IImportMovementRepository>();
            receiptRepository          = A.Fake <IImportMovementReceiptRepository>();
            movement = new ImportMovement(notificationId, 1, new DateTime(2016, 1, 1));

            A.CallTo(() => movementRepository.Get(movementId)).Returns(movement);

            cancelMovement = new CancelImportMovement(movementRepository, receiptRepository, completedReceiptRepository);
        }
        public async Task WasteReceivedDateCanBeInThePast()
        {
            movement = new ImportMovement(notificationId, 52, PastDate);

            A.CallTo(() => movementRepository.Get(movementId)).Returns(movement);

            var result = await partialRejectFactory.PartailReject(movementId, PastDate, rejectionreason, 15, shipmentQuantityUnits, 5, shipmentQuantityUnits, PastDate);

            Assert.Equal(PastDate, result.WasteReceivedDate);
        }
        public async Task <ImportMovementData> HandleAsync(GetImportMovementDates message)
        {
            var movement = await movementRepository.Get(message.MovementId);

            return(new ImportMovementData
            {
                NotificationId = movement.NotificationId,
                ActualDate = movement.ActualShipmentDate,
                Number = movement.Number,
                PreNotificationDate = movement.PrenotificationDate,
                IsCancelled = movement.IsCancelled
            });
        }
        public async Task <RejectedMovementDetails> HandleAsync(GetRejectedImportMovementDetails message)
        {
            var movement = await movementRepository.Get(message.MovementId);

            var details = await rejectionRepository.GetByMovementIdOrDefault(message.MovementId);

            return(new RejectedMovementDetails
            {
                Number = movement.Number,
                Date = details.Date,
                Reason = details.Reason
            });
        }
Ejemplo n.º 9
0
        public async Task <bool> HandleAsync(SetImportMovementDates message)
        {
            var movement = await movementRepository.Get(message.MovementId);

            movement.SetActualShipmentDate(message.ActualShipmentDate);

            if (message.PrenotificationDate.HasValue)
            {
                movement.SetPrenotificationDate(message.PrenotificationDate.Value);
            }

            await context.SaveChangesAsync();

            return(true);
        }
Ejemplo n.º 10
0
        public async Task <Unit> HandleAsync(SetMovementComments message)
        {
            var movement = await repository.Get(message.MovementId);

            if (!string.IsNullOrWhiteSpace(message.Comments))
            {
                movement.SetComments(message.Comments);
            }
            if (!string.IsNullOrWhiteSpace(message.StatsMarking))
            {
                movement.SetStatsMarking(message.StatsMarking);
            }

            await context.SaveChangesAsync();

            return(Unit.Value);
        }
Ejemplo n.º 11
0
        public async Task <ImportMovementReceipt> Receive(Guid movementId, ShipmentQuantity quantity, DateTime date)
        {
            var movement = await movementRepository.Get(movementId);

            if (date < movement.ActualShipmentDate)
            {
                throw new InvalidOperationException("The when the waste was received date cannot be before the actual date of shipment.");
            }
            if (date > SystemTime.UtcNow.Date)
            {
                throw new InvalidOperationException("The when the waste was received date cannot be in the future.");
            }

            var receipt = movement.Receive(quantity, date);

            receiptRepository.Add(receipt);

            return(receipt);
        }
Ejemplo n.º 12
0
        public async Task <ImportMovementRejection> Reject(Guid importMovementId, DateTime date, string reason, decimal?quantity, ShipmentQuantityUnits?unit)
        {
            var movement = await movementRepository.Get(importMovementId);

            if (date < movement.ActualShipmentDate)
            {
                throw new InvalidOperationException("The when the waste was received date cannot be before the actual date of shipment.");
            }
            if (date > SystemTime.UtcNow.Date)
            {
                throw new InvalidOperationException("The when the waste was received date cannot be in the future.");
            }

            var rejection = movement.Reject(date, reason, quantity, unit);

            rejectionRepository.Add(rejection);

            return(rejection);
        }
Ejemplo n.º 13
0
        public async Task Cancel(Guid importMovementId)
        {
            var receipt = await receiptRepository.GetByMovementIdOrDefault(importMovementId);

            var completedReceipt = await completedReceiptRepository.GetByMovementIdOrDefault(importMovementId);

            if (receipt != null)
            {
                throw new InvalidOperationException(string.Format("Can't cancel movement {0} as it has been received", importMovementId));
            }

            if (completedReceipt != null)
            {
                throw new InvalidOperationException(string.Format("Can't cancel movement {0} as it has been recovered / disposed of", importMovementId));
            }

            var movement = await movementRepository.Get(importMovementId);

            movement.Cancel();
        }
Ejemplo n.º 14
0
        public async Task <ImportMovementCompletedReceipt> Complete(Guid movementId, DateTime date)
        {
            var movement = await movementRepository.Get(movementId);

            var movementReceipt = await movementReceiptRepository.GetByMovementIdOrDefault(movementId);

            if (date < movementReceipt.Date)
            {
                throw new InvalidOperationException("The when was the waste recovered date cannot be before the when was the waste received. ");
            }
            if (date > SystemTime.UtcNow.Date)
            {
                throw new InvalidOperationException("The when the waste was recovered date cannot be in the future.");
            }

            var completedReceipt = movement.Complete(date);

            completedReceiptRepository.Add(completedReceipt);

            return(completedReceipt);
        }
        public async Task <Guid> HandleAsync(GetNotificationIdByMovementId message)
        {
            var movement = await importMovementRepository.Get(message.MovementId);

            return(movement.NotificationId);
        }
Ejemplo n.º 16
0
 public async Task EnsureAccessAsync(Guid movementId)
 {
     var notificationId = (await repository.Get(movementId)).NotificationId;
     await authorization.EnsureAccessAsync(notificationId);
 }