public async Task CanCancelPrenotifiedMovement() { A.CallTo(() => completedReceiptRepository.GetByMovementIdOrDefault(movementId)) .Returns <ImportMovementCompletedReceipt>(null); A.CallTo(() => receiptRepository.GetByMovementIdOrDefault(movementId)) .Returns <ImportMovementReceipt>(null); await cancelMovement.Cancel(movementId); Assert.True(movement.IsCancelled); }
public async Task WasteReceivedDateCanBeInThePast() { movement = new ImportMovement(notificationId, 52, PastDate); movementReceipt = new ImportMovementReceipt(movementId, new ShipmentQuantity(10, ShipmentQuantityUnits.Kilograms), PastDate); A.CallTo(() => movementRepository.Get(movementId)).Returns(movement); A.CallTo(() => receiptRepository.GetByMovementIdOrDefault(movementId)).Returns(movementReceipt); var result = await completeFactory.Complete(movementId, PastDate); Assert.Equal(PastDate, result.Date); }
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(); }
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); }