public MovementsDetailsFactoryTests()
        {
            var movementRepository = A.Fake<IMovementRepository>();
            var shipmentRepository = A.Fake<IShipmentInfoRepository>();

            // Setup notification with 1000Kg intended quantity and 950Kg received

            movement = new TestableMovement
            {
                Id = new Guid("B3A80B02-52BF-4051-9BE8-7AA9F7758E0E"),
                NotificationId = notificationId,
                Receipt = new TestableMovementReceipt
                {
                    QuantityReceived = new ShipmentQuantity(950, ShipmentQuantityUnits.Kilograms)
                }
            };

            A.CallTo(() => movementRepository.GetMovementsByStatus(notificationId, MovementStatus.Received))
                .Returns(new[] { movement });

            var shipment = new TestableShipmentInfo
            {
                NotificationId = notificationId,
                Quantity = 1000,
                Units = ShipmentQuantityUnits.Kilograms
            };

            A.CallTo(() => shipmentRepository.GetByNotificationId(notificationId))
                .Returns(shipment);

            var movementQuantity = new NotificationMovementsQuantity(movementRepository, shipmentRepository);
            factory = new MovementDetailsFactory(movementQuantity);
        }
 private TestableMovement GetMovement(int number)
 {
     TestableMovement movement = new TestableMovement();
     movement.Id = Guid.NewGuid();
     movement.NotificationId = NotificationId;
     movement.Date = SystemTime.UtcNow.Date.AddDays(-number);
     movement.Number = number;
     return movement;
 }
        public GetMovementDateByMovementIdHandlerTests()
        {
            movement = new TestableMovement
            {
                Id = MovementId,
                Date = MovementDate
            };

            repository = A.Fake<IMovementRepository>();
            A.CallTo(() => repository.GetById(MovementId)).Returns(movement);

            handler = new GetMovementDateByMovementIdHandler(repository);
            request = new GetMovementDateByMovementId(MovementId);
        }
        public async Task NewMovementExceedsShipmentLimit_Throws()
        {
            CreateShipmentInfo(maxNumberOfShipments: 1);

            var existingMovement = new TestableMovement
            {
                Id = new Guid("1584B5F6-4E33-441D-A9C9-17C1C3B28BA2"),
                NotificationId = NotificationId,
            };

            A.CallTo(() => movementRepository.GetAllMovements(NotificationId)).Returns(new[] { existingMovement });

            await Assert.ThrowsAsync<InvalidOperationException>(() => factory.Create(NotificationId, Today));
        }
        public async Task QuantityReceived_CountsReceivedMovements()
        {
            var nonReceivedMovement = new TestableMovement
            {
                Status  = MovementStatus.Submitted,
                Receipt = new TestableMovementReceipt
                {
                    QuantityReceived = new ShipmentQuantity(5, ShipmentQuantityUnits.Tonnes)
                }
            };

            var movements = new[] { movement, nonReceivedMovement };

            SetUpRepositoryCalls(movements, shipmentInfo);

            var result = await movementQuantity.Received(NotificationId);

            Assert.Equal(new ShipmentQuantity(5, ShipmentQuantityUnits.Kilograms), result);
        }
Exemplo n.º 6
0
        public async Task QuantityRemaining_CountsCompletedMovements()
        {
            var completedMovement = new TestableMovement
            {
                Status  = MovementStatus.Completed,
                Receipt = new TestableMovementReceipt
                {
                    QuantityReceived = new ShipmentQuantity(5, ShipmentQuantityUnits.Kilograms)
                }
            };

            var movements = new[] { movement, completedMovement };

            SetUpRepositoryCalls(movements, shipmentInfo);

            var result = await movementQuantity.Remaining(NotificationId);

            Assert.Equal(new ShipmentQuantity(10, ShipmentQuantityUnits.Kilograms), result);
        }
 public MovementViewModelTests()
 {
     notification = new TestableNotificationApplication
     {
         Id = new Guid("07FF7B1D-A3A9-4FB1-B10B-F00EEF8FB9F8")
     };
     movement = new TestableMovement
     {
         Id = new Guid("B20B7BBE-EA7C-45F7-B6DB-04F645E7375B")
     };
     movementDetails = new TestableMovementDetails
     {
         Id = new Guid("E5DF0706-F17C-49CC-8DB2-B6A524A4C372")
     };
     shipmentInfo = new TestableShipmentInfo
     {
         Id = new Guid("B2B2ADE7-34EF-468D-BB88-72D8B5394AE6")
     };
 }
Exemplo n.º 8
0
 public MovementViewModelTests()
 {
     notification = new TestableNotificationApplication
     {
         Id = new Guid("07FF7B1D-A3A9-4FB1-B10B-F00EEF8FB9F8"),
         CompetentAuthority = UKCompetentAuthority.England
     };
     movement = new TestableMovement
     {
         Id = new Guid("B20B7BBE-EA7C-45F7-B6DB-04F645E7375B")
     };
     movementDetails = new TestableMovementDetails
     {
         Id = new Guid("E5DF0706-F17C-49CC-8DB2-B6A524A4C372")
     };
     shipmentInfo = new TestableShipmentInfo
     {
         Id = new Guid("B2B2ADE7-34EF-468D-BB88-72D8B5394AE6")
     };
 }
        public async Task QuantityReceived_IfMovementsUnitsDiffer_ConvertsAndSums()
        {
            var movementWithOtherUnits = new TestableMovement
            {
                Status  = MovementStatus.Received,
                Receipt = new TestableMovementReceipt
                {
                    Date             = new DateTime(2015, 9, 2),
                    Decision         = Core.MovementReceipt.Decision.Accepted,
                    QuantityReceived = new ShipmentQuantity(0.001m, ShipmentQuantityUnits.Tonnes)
                }
            };

            var movements = new[] { movement, movementWithOtherUnits };

            SetUpRepositoryCalls(movements, shipmentInfo);

            var result = await movementQuantity.Received(NotificationId);

            Assert.Equal(new ShipmentQuantity(6, ShipmentQuantityUnits.Kilograms), result);
        }
        public MovementQuantityTests()
        {
            movement = new TestableMovement
            {
                Status = MovementStatus.Received,
                Receipt = new TestableMovementReceipt
                {
                    Date = new DateTime(2015, 9, 1),
                    Decision = Core.MovementReceipt.Decision.Accepted,
                    QuantityReceived = new ShipmentQuantity(5, ShipmentQuantityUnits.Kilograms)
                }
            };

            shipmentInfo = new TestableShipmentInfo
            {
                Quantity = 20,
                Units = ShipmentQuantityUnits.Kilograms
            };

            movementRepository = A.Fake<IMovementRepository>();
            shipmentRepository = A.Fake<IShipmentInfoRepository>();

            movementQuantity = new NotificationMovementsQuantity(movementRepository, shipmentRepository);
        }
Exemplo n.º 11
0
        public MovementsDetailsFactoryTests()
        {
            var movementRepository = A.Fake <IMovementRepository>();
            var shipmentRepository = A.Fake <IShipmentInfoRepository>();

            movementPartialRejectionRepository = A.Fake <IMovementPartialRejectionRepository>();

            // Setup notification with 1000Kg intended quantity and 950Kg received

            movement = new TestableMovement
            {
                Id             = new Guid("B3A80B02-52BF-4051-9BE8-7AA9F7758E0E"),
                NotificationId = notificationId,
                Receipt        = new TestableMovementReceipt
                {
                    QuantityReceived = new ShipmentQuantity(950, ShipmentQuantityUnits.Kilograms)
                }
            };

            A.CallTo(() => movementRepository.GetMovementsByStatus(notificationId, MovementStatus.Received))
            .Returns(new[] { movement });

            var shipment = new TestableShipmentInfo
            {
                NotificationId = notificationId,
                Quantity       = 1000,
                Units          = ShipmentQuantityUnits.Kilograms
            };

            A.CallTo(() => shipmentRepository.GetByNotificationId(notificationId))
            .Returns(shipment);

            var movementQuantity = new NotificationMovementsQuantity(movementRepository, shipmentRepository, movementPartialRejectionRepository);

            factory = new MovementDetailsFactory(movementQuantity);
        }
        public MovementQuantityTests()
        {
            movement = new TestableMovement
            {
                Status  = MovementStatus.Received,
                Receipt = new TestableMovementReceipt
                {
                    Date             = new DateTime(2015, 9, 1),
                    Decision         = Core.MovementReceipt.Decision.Accepted,
                    QuantityReceived = new ShipmentQuantity(5, ShipmentQuantityUnits.Kilograms)
                }
            };

            shipmentInfo = new TestableShipmentInfo
            {
                Quantity = 20,
                Units    = ShipmentQuantityUnits.Kilograms
            };

            movementRepository = A.Fake <IMovementRepository>();
            shipmentRepository = A.Fake <IShipmentInfoRepository>();

            movementQuantity = new NotificationMovementsQuantity(movementRepository, shipmentRepository);
        }
Exemplo n.º 13
0
        protected TestBase()
        {
            UserContext = new TestUserContext(UserId);
            Context     = new TestIwsContext(UserContext);

            NotificationApplication = new TestableNotificationApplication
            {
                Id     = NotificationId,
                UserId = UserId
            };

            Context.Countries.AddRange(new[]
            {
                TestableCountry.France,
                TestableCountry.Switzerland,
                TestableCountry.UnitedKingdom
            });

            Movement = new TestableMovement
            {
                Id             = MovementId,
                NotificationId = NotificationId
            };
        }
        public async Task QuantityReceived_IfMovementsUnitsDiffer_ConvertsAndSums()
        {
            var movementWithOtherUnits = new TestableMovement
            {
                Status = MovementStatus.Received,
                Receipt = new TestableMovementReceipt
                {
                    Date = new DateTime(2015, 9, 2),
                    Decision = Core.MovementReceipt.Decision.Accepted,
                    QuantityReceived = new ShipmentQuantity(0.001m, ShipmentQuantityUnits.Tonnes)
                }
            };

            var movements = new[] { movement, movementWithOtherUnits };

            SetUpRepositoryCalls(movements, shipmentInfo);

            var result = await movementQuantity.Received(NotificationId);

            Assert.Equal(new ShipmentQuantity(6, ShipmentQuantityUnits.Kilograms), result);
        }
        public async Task QuantityRemaining_Unchanged_WhenNoMovementsReceived()
        {
            var nonReceivedMovement = new TestableMovement
            {
                Status = MovementStatus.Submitted,
                Receipt = new TestableMovementReceipt
                {
                    QuantityReceived = new ShipmentQuantity(5, ShipmentQuantityUnits.Kilograms)
                }
            };

            var movements = new[] { nonReceivedMovement };

            SetUpRepositoryCalls(movements, shipmentInfo);

            var result = await movementQuantity.Remaining(NotificationId);

            Assert.Equal(new ShipmentQuantity(20, ShipmentQuantityUnits.Kilograms), result);
        }
        public async Task QuantityRemaining_CountsCompletedMovements()
        {
            var completedMovement = new TestableMovement
            {
                Status = MovementStatus.Completed,
                Receipt = new TestableMovementReceipt
                {
                    QuantityReceived = new ShipmentQuantity(5, ShipmentQuantityUnits.Kilograms)
                }
            };

            var movements = new[] { movement, completedMovement };

            SetUpRepositoryCalls(movements, shipmentInfo);

            var result = await movementQuantity.Remaining(NotificationId);

            Assert.Equal(new ShipmentQuantity(10, ShipmentQuantityUnits.Kilograms), result);
        }
Exemplo n.º 17
0
        private CancelMovements GetRequestWithAddedMovements()
        {
            var cancelledMovements = new List <MovementData>()
            {
                new MovementData()
                {
                    Id = Guid.NewGuid(), Number = 1
                },
                new MovementData()
                {
                    Id = Guid.NewGuid(), Number = 2
                },
                new MovementData()
                {
                    Id = Guid.NewGuid(), Number = 3
                }
            };

            var addedMovements = new List <AddedCancellableMovement>()
            {
                new AddedCancellableMovement()
                {
                    NotificationId = notificationId,
                    Number         = 4,
                    ShipmentDate   = SystemTime.Now
                },
                new AddedCancellableMovement()
                {
                    NotificationId = notificationId,
                    Number         = 5,
                    ShipmentDate   = SystemTime.Now
                }
            };

            var firstAddedMovement = new TestableMovement()
            {
                Id             = Guid.NewGuid(),
                NotificationId = notificationId,
                Number         = 4,
                Status         = MovementStatus.Captured
            };

            var secondAddedMovement = new TestableMovement()
            {
                Id             = Guid.NewGuid(),
                NotificationId = notificationId,
                Number         = 5,
                Status         = MovementStatus.Captured
            };

            A.CallTo(
                () =>
                capturedMovementFactory.Create(notificationId,
                                               A <int> .That.Matches(number => number == firstAddedMovement.Number), null,
                                               A <DateTime> .Ignored, true)).Returns(firstAddedMovement);

            A.CallTo(
                () =>
                capturedMovementFactory.Create(notificationId,
                                               A <int> .That.Matches(number => number == secondAddedMovement.Number), null,
                                               A <DateTime> .Ignored, true)).Returns(secondAddedMovement);

            var movements = cancelledMovements.Select(cancelled => new TestableMovement
            {
                Id             = cancelled.Id,
                NotificationId = notificationId,
                Number         = cancelled.Number,
                Status         = MovementStatus.Submitted
            }).ToList();

            movements.Add(firstAddedMovement);
            movements.Add(secondAddedMovement);

            A.CallTo(
                () =>
                repository.GetMovementsByIds(notificationId,
                                             A <IEnumerable <Guid> > .Ignored)).Returns(movements);

            return(new CancelMovements(notificationId, cancelledMovements, addedMovements));
        }
        private void SetupMovements(int intendedQuantity, int quantityReceived)
        {
            var shipment = new TestableShipmentInfo
            {
                Id = new Guid("2DA8E281-A6A4-459A-A38A-B4B0643E0726"),
                NotificationId = NotificationId,
                NumberOfShipments = 10,
                Quantity = intendedQuantity,
                Units = ShipmentQuantityUnits.Tonnes
            };

            var existingMovement = new TestableMovement
            {
                Id = new Guid("1584B5F6-4E33-441D-A9C9-17C1C3B28BA2"),
                NotificationId = NotificationId,
                Status = MovementStatus.Received
            };

            var movementReceipt = new TestableMovementReceipt
            {
                Id = new Guid("28FFDD0B-1A1A-4CAC-B4E4-D232DA7B2AB8"),
                QuantityReceived = new ShipmentQuantity(quantityReceived, ShipmentQuantityUnits.Tonnes)
            };

            existingMovement.Receipt = movementReceipt;

            A.CallTo(() => shipmentRepository.GetByNotificationId(NotificationId)).Returns(shipment);
            A.CallTo(() => movementRepository.GetMovementsByStatus(NotificationId, MovementStatus.Received)).Returns(new[] { existingMovement });
            A.CallTo(() => assessmentRepository.GetByNotificationId(NotificationId)).Returns(new TestableNotificationAssessment { Status = NotificationStatus.Consented });
            A.CallTo(() => consentRepository.GetByNotificationId(NotificationId)).Returns(ValidConsent());
        }