Exemplo 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);
        }
Exemplo 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);
        }
Exemplo 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);
        }
Exemplo 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
            });
        }
Exemplo 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);
        }
Exemplo 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);
        }
Exemplo 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);
        }
Exemplo 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);
        }
Exemplo 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();
        }
Exemplo 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);
        }
Exemplo n.º 16
0
 public async Task EnsureAccessAsync(Guid movementId)
 {
     var notificationId = (await repository.Get(movementId)).NotificationId;
     await authorization.EnsureAccessAsync(notificationId);
 }